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.
58 lines
1.7 KiB
Dart
58 lines
1.7 KiB
Dart
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<dynamic> _getLanguages() async => await textToSpeech.getLanguages;
|
|
|
|
startCalling() async {
|
|
textToSpeech.setLanguage("en-US");
|
|
var clinic = ticketNo.split(" ");
|
|
var splitText = clinic[1].split("-");
|
|
// Create Pre Voice Players
|
|
if (preVoice != null && preVoice.isNotEmpty) {
|
|
textToSpeech.setSpeechRate(rate);
|
|
textToSpeech.setPitch(pitch);
|
|
textToSpeech.setVolume(volume);
|
|
await textToSpeech.speak(preVoice + " .. " + clinic[0] + " .. " + splitText[0] + " .. " + splitText[1] + " .. " + 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();
|
|
// }
|
|
}
|