You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
queuing_system/lib/utils/call_by_voice.dart

91 lines
2.8 KiB
Dart

import 'dart:developer';
import 'package:flutter_tts/flutter_tts.dart';
import 'package:queuing_system/home/app_provider.dart';
3 years ago
class CallByVoice {
3 years ago
final String lang;
final String preVoice;
final String ticketNo;
final String postVoice;
7 months ago
final bool isMute;
2 years ago
final FlutterTts flutterTts;
3 years ago
7 months ago
CallByVoice({
this.lang = 'en',
required this.isMute,
required this.ticketNo,
required this.preVoice,
required this.postVoice,
required this.flutterTts,
});
double volume = 1.0;
double pitch = 0.6;
double rate = 0.2;
3 years ago
2 years ago
Future<void> startCalling(bool isClinicNameAdded) async {
7 months ago
// log("getEngines: ${await flutterTts.getEngines}");
// log("getDefaultEngine: ${await flutterTts.getDefaultEngine}");
// log("getVoices: ${await flutterTts.getVoices}");
// log("getDefaultVoice: ${await flutterTts.getDefaultVoice}");
String clinicName = "";
String patientAlpha = "";
String patientNumeric = "";
7 months ago
if (isMute) {
volume = 0.0;
}
if (isClinicNameAdded) {
var clinic = ticketNo.split(" ");
clinicName = clinic[0];
var queueNoArray = clinic[1].split("-");
if (queueNoArray.length > 2) {
patientAlpha = "${queueNoArray[0]} .. ${queueNoArray[1]}";
patientNumeric = queueNoArray[2];
} else {
patientAlpha = queueNoArray[0];
patientNumeric = queueNoArray[1];
}
} else {
var queueNoArray = ticketNo.split("-");
if (queueNoArray.length > 2) {
patientAlpha = "${queueNoArray[0]} .. ${queueNoArray[1]}";
patientNumeric = queueNoArray[2];
} else {
patientAlpha = queueNoArray[0];
patientNumeric = queueNoArray[1];
}
}
3 years ago
// Create Pre Voice Players
7 months ago
if (postVoice.isNotEmpty) {
log('lang $lang');
2 years ago
flutterTts.setSpeechRate(0.45);
if (lang != "ar") {
await flutterTts.setLanguage(lang);
2 years ago
flutterTts.setPitch(0.9);
7 months ago
flutterTts.setVolume(volume);
isVoiceActualCompletedGlobally = true;
await flutterTts.awaitSpeakCompletion(true);
await flutterTts.speak("$preVoice .. $clinicName .. $patientAlpha .. $patientNumeric .. $postVoice");
return;
2 years ago
}
flutterTts.setPitch(1.1);
7 months ago
flutterTts.setVolume(volume);
await flutterTts.setLanguage(lang);
isVoiceActualCompletedGlobally = false;
await flutterTts.awaitSpeakCompletion(true);
2 years ago
// await flutterTts.speak(preVoice + " .. " + clinicName + " .. " + patientAlpha + " .. " + patientNumeric + " .. " + postVoice);
await flutterTts.speak("$preVoice .. ");
2 years ago
await flutterTts.setLanguage("en");
7 months ago
await flutterTts.speak("${clinicName.isNotEmpty ? ".." : ""} $patientAlpha .. $patientNumeric .. ");
2 years ago
await flutterTts.setLanguage(lang);
isVoiceActualCompletedGlobally = true;
2 years ago
await flutterTts.speak(postVoice);
3 years ago
}
}
}