|
|
|
|
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("langs1: ${(await flutterTts.getVoices).toString()}");
|
|
|
|
|
// log("langs2: ${(await flutterTts.areLanguagesInstalled(["en-AU", "ar-AR"])).toString()}");
|
|
|
|
|
// log("langs3: ${(await flutterTts.getDefaultVoice).toString()}");
|
|
|
|
|
// log("langs3: ${(await flutterTts.getLanguages).toString()}");
|
|
|
|
|
// log("langs4: ${(await flutterTts.setVoice({"name": "kn-in-x-knf-network", "locale": "kn-IN"})).toString()}");
|
|
|
|
|
// log("langs5: ${(await flutterTts.getEngines).toString()}");
|
|
|
|
|
|
|
|
|
|
// print("lang: $lang");
|
|
|
|
|
// print("preVoice: $preVoice");
|
|
|
|
|
// print("postVoice: $postVoice");
|
|
|
|
|
// print("ticketNo: $ticketNo");
|
|
|
|
|
|
|
|
|
|
String clinicName = "";
|
|
|
|
|
String patientAlpha = "";
|
|
|
|
|
String patientNumeric = "";
|
|
|
|
|
|
|
|
|
|
if (isClinicNameAdded) {
|
|
|
|
|
var clinic = ticketNo.split(" ");
|
|
|
|
|
clinicName = clinic[0];
|
|
|
|
|
patientAlpha = clinic[1].split("-")[0];
|
|
|
|
|
patientNumeric = clinic[1].split("-")[1];
|
|
|
|
|
} else {
|
|
|
|
|
patientAlpha = ticketNo.split("-")[0];
|
|
|
|
|
patientNumeric = ticketNo.split("-")[1];
|
|
|
|
|
}
|
|
|
|
|
// Create Pre Voice Players
|
|
|
|
|
if (postVoice != null && postVoice.isNotEmpty) {
|
|
|
|
|
flutterTts.setSpeechRate(0.45);
|
|
|
|
|
if (lang != "ar") {
|
|
|
|
|
await flutterTts.setLanguage(lang);
|
|
|
|
|
flutterTts.setPitch(0.9);
|
|
|
|
|
flutterTts.setVolume(1.0);
|
|
|
|
|
isVoiceActualCompletedGlobally = 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); // TODO : BUG HERE
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// // Create Ticket Number Voice Players
|
|
|
|
|
// final characters = ticketNo.characters.toList();
|
|
|
|
|
// for (int i = 0; i < characters.length; i++) {
|
|
|
|
|
// final no = characters[i];
|
|
|
|
|
// if (no.isNotEmpty && no != "-" && no != "_" && no != " ") {
|
|
|
|
|
//
|
|
|
|
|
// await _player.stop();
|
|
|
|
|
// await _player.setAsset('assets/voice_$lang/${no.toUpperCase()}.mp3');
|
|
|
|
|
// await _player.play();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Create Post Voice Players
|
|
|
|
|
// if (postVoice != null && postVoice.isNotEmpty) {
|
|
|
|
|
// await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
|
//
|
|
|
|
|
// await _player.stop();
|
|
|
|
|
// await _player.setAsset('assets/voice_$lang/$postVoice');
|
|
|
|
|
// await _player.play();
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stop() async {
|
|
|
|
|
// await _player.stop();
|
|
|
|
|
// }
|
|
|
|
|
}
|