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.
72 lines
2.2 KiB
Dart
72 lines
2.2 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter_tts/flutter_tts.dart';
|
|
|
|
class CallByVoice {
|
|
final String lang;
|
|
final String preVoice;
|
|
final String ticketNo;
|
|
final String postVoice;
|
|
|
|
CallByVoice({this.lang = 'en', required this.ticketNo, required this.preVoice, required this.postVoice});
|
|
|
|
final FlutterTts textToSpeech = FlutterTts();
|
|
|
|
double volume = 1.0;
|
|
double pitch = 0.6;
|
|
double rate = 0.2;
|
|
|
|
startCalling(bool isClinicNameAdded) async {
|
|
log("langs: ${(await textToSpeech.getVoices).toString()}");
|
|
log("langs: ${(await textToSpeech.getLanguages).toString()}");
|
|
log("langs: ${(await textToSpeech.getEngines).toString()}");
|
|
|
|
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];
|
|
}
|
|
await textToSpeech.setLanguage("en-US");
|
|
// Create Pre Voice Players
|
|
if (preVoice != null && preVoice.isNotEmpty) {
|
|
textToSpeech.setSpeechRate(0.4);
|
|
textToSpeech.setPitch(0.9);
|
|
textToSpeech.setVolume(1.0);
|
|
await textToSpeech.speak(preVoice + " .. " + clinicName + " .. " + patientAlpha + " .. " + patientNumeric + " .. " + 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();
|
|
// }
|
|
}
|