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

96 lines
3.4 KiB
Dart

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;
2 years ago
final FlutterTts flutterTts;
3 years ago
2 years ago
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;
3 years ago
2 years ago
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()}");
2 years ago
// 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];
}
3 years ago
// Create Pre Voice Players
2 years ago
if (postVoice != null && postVoice.isNotEmpty) {
flutterTts.setSpeechRate(0.45);
if (lang != "ar") {
await flutterTts.setLanguage(lang);
2 years ago
flutterTts.setPitch(0.9);
flutterTts.setVolume(1.0);
isVoiceActualCompletedGlobally = true;
await flutterTts.speak(preVoice + " .. " + clinicName + " .. " + patientAlpha + " .. " + patientNumeric + " .. " + postVoice);
return;
2 years ago
}
flutterTts.setPitch(1.1);
2 years ago
flutterTts.setVolume(1.0);
await flutterTts.setLanguage(lang);
isVoiceActualCompletedGlobally = false;
await flutterTts.awaitSpeakCompletion(true); // TODO : BUG HERE
2 years ago
// 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;
2 years ago
await flutterTts.speak(postVoice);
3 years ago
}
// // 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();
// }
// }
3 years ago
// 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();
// }
}