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.
86 lines
2.9 KiB
Dart
86 lines
2.9 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter_tts/flutter_tts.dart';
|
|
import 'package:queuing_system/home/app_provider.dart';
|
|
|
|
class CallByVoice {
|
|
final String lang;
|
|
final String preVoice;
|
|
final String ticketNo;
|
|
final String postVoice;
|
|
final FlutterTts flutterTts;
|
|
|
|
CallByVoice({this.lang = 'en', required this.ticketNo, required this.preVoice, required this.postVoice, required this.flutterTts});
|
|
|
|
double volume = 1.0;
|
|
double pitch = 0.6;
|
|
double rate = 0.2;
|
|
|
|
Future<void> startCalling(bool isClinicNameAdded) async {
|
|
log("lang: $lang");
|
|
log("preVoice: $preVoice");
|
|
log("postVoice: $postVoice");
|
|
log("ticketNo: $ticketNo");
|
|
log("isClinicNameAdded: $isClinicNameAdded");
|
|
|
|
// 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 = "";
|
|
|
|
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];
|
|
}
|
|
}
|
|
// Create Pre Voice Players
|
|
if (postVoice != null && postVoice.isNotEmpty) {
|
|
log('lang $lang');
|
|
flutterTts.setSpeechRate(0.45);
|
|
if (lang != "ar") {
|
|
await flutterTts.setLanguage(lang);
|
|
flutterTts.setPitch(0.9);
|
|
flutterTts.setVolume(1.0);
|
|
isVoiceActualCompletedGlobally = true;
|
|
await flutterTts.awaitSpeakCompletion(true);
|
|
await flutterTts.speak("$preVoice .. $clinicName .. $patientAlpha .. $patientNumeric .. $postVoice");
|
|
return;
|
|
}
|
|
|
|
flutterTts.setPitch(1.1);
|
|
flutterTts.setVolume(1.0);
|
|
await flutterTts.setLanguage(lang);
|
|
isVoiceActualCompletedGlobally = false;
|
|
await flutterTts.awaitSpeakCompletion(true);
|
|
|
|
// await flutterTts.speak(preVoice + " .. " + clinicName + " .. " + patientAlpha + " .. " + patientNumeric + " .. " + postVoice);
|
|
await flutterTts.speak("$preVoice .. ");
|
|
await flutterTts.setLanguage("en");
|
|
await flutterTts.speak("$clinicName .. $patientAlpha .. $patientNumeric .. ");
|
|
await flutterTts.setLanguage(lang);
|
|
isVoiceActualCompletedGlobally = true;
|
|
await flutterTts.speak(postVoice);
|
|
}
|
|
}
|
|
}
|