import 'package:flutter/cupertino.dart'; import 'package:flutter_tts/flutter_tts.dart'; class CallByVoice { final String lang; final String preVoice; final String ticketNo; final String postVoice; CallByVoice(this.ticketNo, {this.lang = 'en', @required this.preVoice, @required this.postVoice}); final FlutterTts textToSpeech = FlutterTts(); double volume = 1.0; double pitch = 0.9; double rate = 0.5; Future _getLanguages() async => await textToSpeech.getLanguages; startCalling(bool isClinicNameAdded) async { 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]; } textToSpeech.setLanguage("en-US"); // Create Pre Voice Players if (preVoice != null && preVoice.isNotEmpty) { textToSpeech.setSpeechRate(rate); textToSpeech.setPitch(pitch); textToSpeech.setVolume(volume); 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(); // } }