diff --git a/lib/core/api.dart b/lib/core/api.dart index b4b61c5..e64c53d 100644 --- a/lib/core/api.dart +++ b/lib/core/api.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/cupertino.dart'; import 'package:queuing_system/core/base/base_app_client.dart'; import 'package:queuing_system/core/response_model/patient_call.dart'; @@ -6,25 +8,22 @@ const _getCallRequestInfoByClinicInfo = "/GetCallRequestInfoByClinincInfo"; const _call_UpdateNotIsQueueRecordByIDAsync = "/Call_UpdateNotIsQueueRecordByID"; class API { - static GetCallRequestInfoByClinincInfo(String deviceIp, {@required Function(List) onSuccess, @required Function(dynamic) onFailure}) async { + static getCallRequestInfoByClinicInfo(String deviceIp, {@required Function(List) onSuccess, @required Function(dynamic) onFailure}) async { final body = {"IPAdress": deviceIp}; BaseAppClient.post(_getCallRequestInfoByClinicInfo, body: body, onSuccess: (response, status) { if (status == 200) { var calledByNurse = (response["CalledByNurse"] as List).map((j) => Tickets.fromJson(j)).toList(); - print("calledByNurse Length: ${calledByNurse.length}"); + log("calledByNurse Length: ${calledByNurse.length}"); final patients = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList(); - print("patients Length: ${patients.length}"); + log("patients Length: ${patients.length}"); calledByNurse.addAll(patients); - - // calledByNurse.sort((a, b) => a.callNo.compareTo(b.callNo)); - // final clinicCurrentPatient = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList(); onSuccess(calledByNurse.reversed.toList()); } else { onFailure(response); @@ -33,7 +32,7 @@ class API { onFailure: (error, status) => onFailure(error)); } - static Call_UpdateNotIsQueueRecordByIDAsync(String deviceIp, {@required Tickets ticket, @required Function(List) onSuccess, @required Function(dynamic) onFailure}) async { + static callUpdateNotIsQueueRecordByIDAsync(String deviceIp, {@required Tickets ticket, @required Function(List) onSuccess, @required Function(dynamic) onFailure}) async { if (ticket.id == null) { return; } @@ -46,7 +45,7 @@ class API { body: body, onSuccess: (response, status) { if (status == 200) { - ticket.call_updated = true; + ticket.callUpdated = true; _ticketsUpdated.add(ticket); } }, diff --git a/lib/core/response_model/patient_call.dart b/lib/core/response_model/patient_call.dart index 435dcf6..dc1332b 100644 --- a/lib/core/response_model/patient_call.dart +++ b/lib/core/response_model/patient_call.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:queuing_system/utils/call_type.dart'; class Tickets { @@ -16,15 +18,11 @@ class Tickets { this.queueNo, }); - String getParsedDateTime(String date) { - print("gotDate: $date"); - DateTime dateTime = DateTime.parse(date); - - + int getRandomNum() { + return Random().nextInt(1); } Tickets.fromJson(dynamic json) { - print("here json: $json"); id = json['ID']; callNo = json['CallNo']; roomNo = json['RoomNo']; @@ -38,6 +36,7 @@ class Tickets { patientID = json['PatientID']; queueNo = json['QueueNo']; callNoStr = json['CallNoStr'] ?? json['CallNo'].toString(); + isAcknowledged = getRandomNum(); } int id; @@ -53,7 +52,8 @@ class Tickets { int patientID; String queueNo; String callNoStr; - bool call_updated = false; + bool callUpdated = false; + int isAcknowledged; Map toJson() { final map = {}; @@ -75,7 +75,7 @@ class Tickets { @override String toString() { - return (callNo).toString(); + return (callNoStr).toString(); } CallType getCallType() { diff --git a/lib/home/home_screen.dart b/lib/home/home_screen.dart index 04aa2e8..fc03b41 100644 --- a/lib/home/home_screen.dart +++ b/lib/home/home_screen.dart @@ -14,7 +14,6 @@ import 'package:queuing_system/utils/call_type.dart'; import 'package:queuing_system/utils/signalR_utils.dart'; import 'package:queuing_system/utils/utils.dart'; import 'package:queuing_system/widget/data_display/app_texts_widget.dart'; -import 'package:text_to_speech/text_to_speech.dart'; var DEVICE_IP = "10.10.15.11"; // Testing IP // var DEVICE_IP = "10.10.14.11"; // Testing IP @@ -55,7 +54,6 @@ class _MyHomePageState extends State { TextEditingController controller = TextEditingController(); - @override Widget build(BuildContext context) { return AppScaffold( @@ -148,26 +146,58 @@ class _MyHomePageState extends State { } } + String getCallTypeText(Tickets ticket) { + final callType = ticket.getCallType(); + switch (callType) { + case CallType.RECEPTION: + return "Please Visit Doctor"; + break; + case CallType.NURSE: + return "Please Visit Nurse"; + break; + case CallType.DOCTOR: + return "Please Visit Doctor"; + break; + case CallType.NONE: + return ""; + break; + default: + return ""; + } + } + CallByVoice voiceCaller; voiceCall() async { + var j = { + "ID": 4182, + "PatientID": 123123, + "MobileNo": "05***6794", + "DoctorName": "Shakiera", + "DoctorNameN": "Shakeria", + "PatientGender": 1, + "CallNo": 123, + "callType": 1, + "RoomNo": "10", + "CreatedOn": "/Date(1673771382130+0300)/", + "EditedOn": "/Date(1673771384500+0300)/", + "CallNoStr": "A-5", + "QueueNo": null + }; + waitings = [Tickets.fromJson(j)]; + if (waitings.isNotEmpty && voiceCaller == null) { - final postVoice = waitings.first.getCallType().audio('en'); - voiceCaller = CallByVoice(waitings.first.callNoStr.toString(), preVoice: 'ticket_number.mp3', postVoice: postVoice, lang: 'en'); - await voiceCaller.start(); + final postVoice = getCallTypeText(waitings.first); + voiceCaller = CallByVoice(waitings.first.callNoStr.toString(), preVoice: "Ticket Number", postVoice: postVoice, lang: 'en'); + await voiceCaller.startCalling(); voiceCaller = null; } } - printWaiting() { - for (var value in waitings) { - print("waiting: ${value.callNoStr}"); - } - } onUpdateAvailable(data) async { waitings.clear(); - API.GetCallRequestInfoByClinincInfo(DEVICE_IP, onSuccess: (waitingCalls) { + API.getCallRequestInfoByClinicInfo(DEVICE_IP, onSuccess: (waitingCalls) { setState(() { waitings = waitingCalls; // currents = currentInClinic; @@ -175,9 +205,7 @@ class _MyHomePageState extends State { log("\n\n"); log("--------------------"); - // log("Current: $currentInClinic"); - // log("Waiting: $waitingCalls"); - printWaiting(); + log("waiting: $waitings"); log("--------------------"); log("\n\n"); @@ -186,12 +214,14 @@ class _MyHomePageState extends State { } updateTickets() { - // List _ticketsToUpdate = waitings.where((t) => t.call_updated == false).toList(); - // API.Call_UpdateNotIsQueueRecordByIDAsync(DEVICE_IP, ticket: _ticketsToUpdate.first, onSuccess: (tickets_updated) { - // print("[${tickets_updated.length}] Tickets Updated: $tickets_updated"); - // }, onFailure: (e) { - // print("API UPDate Tickets Failed with : ${e.toString()}"); - // }); + if (waitings != null && waitings.isNotEmpty) { + List _ticketsToUpdate = waitings.where((t) => t.callUpdated == false).toList(); + API.callUpdateNotIsQueueRecordByIDAsync(DEVICE_IP, ticket: _ticketsToUpdate.first, onSuccess: (tickets_updated) { + log("[${tickets_updated.length}] Tickets Updated: $tickets_updated"); + }, onFailure: (e) { + log("API UPDate Tickets Failed with : ${e.toString()}"); + }); + } } onConnect() { diff --git a/lib/utils/call_by_voice.dart b/lib/utils/call_by_voice.dart index 557d3f6..910e82d 100644 --- a/lib/utils/call_by_voice.dart +++ b/lib/utils/call_by_voice.dart @@ -1,5 +1,7 @@ +import 'dart:developer'; + import 'package:flutter/cupertino.dart'; -import 'package:just_audio/just_audio.dart'; +import 'package:flutter_tts/flutter_tts.dart'; class CallByVoice { final String lang; @@ -9,42 +11,50 @@ class CallByVoice { CallByVoice(this.ticketNo, {this.lang = 'en', @required this.preVoice, @required this.postVoice}); - final _player = AudioPlayer(); + final FlutterTts textToSpeech = FlutterTts(); + + double volume = 1.0; + double pitch = 0.9; + double rate = 0.5; + + Future _getLanguages() async => await textToSpeech.getLanguages; - start() async { + startCalling() async { + log("languages: ${await _getLanguages()}"); + log("no: $ticketNo"); + textToSpeech.setLanguage("en-US"); + var splitText = ticketNo.split("-"); // Create Pre Voice Players if (preVoice != null && preVoice.isNotEmpty) { - await _player.setAsset('assets/voice_$lang/$preVoice'); - await _player.play(); + textToSpeech.setSpeechRate(rate); + textToSpeech.setPitch(pitch); + textToSpeech.setVolume(volume); + await textToSpeech.speak(preVoice + " .. " + 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 Future.delayed(const Duration(milliseconds: 200)); - - await _player.stop(); - await _player.setAsset('assets/voice_$lang/${no.toUpperCase()}.mp3'); - await _player.play(); - } - } + // // 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(); - } - - _player.dispose(); - } - - stop() async { - await _player.stop(); + // 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(); +// } } diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 1d5268d..addc988 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,14 +7,14 @@ import Foundation import audio_session import connectivity_macos +import flutter_tts import just_audio import path_provider_macos -import text_to_speech_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin")) ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) + FlutterTtsPlugin.register(with: registry.registrar(forPlugin: "FlutterTtsPlugin")) JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) - TextToSpeechMacOsPlugin.register(with: registry.registrar(forPlugin: "TextToSpeechMacOsPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index c94731a..35bf3c8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -151,6 +151,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_tts: + dependency: "direct main" + description: + name: flutter_tts + url: "https://pub.dartlang.org" + source: hosted + version: "3.6.3" flutter_web_plugins: dependency: transitive description: flutter @@ -427,34 +434,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.12" - text_to_speech: - dependency: "direct main" - description: - name: text_to_speech - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.3" - text_to_speech_macos: - dependency: transitive - description: - name: text_to_speech_macos - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.1" - text_to_speech_platform_interface: - dependency: transitive - description: - name: text_to_speech_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.3" - text_to_speech_web: - dependency: transitive - description: - name: text_to_speech_web - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.2" tuple: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 0e196ae..6f0a180 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,7 @@ dependencies: http: ^0.13.0 blinking_text: ^1.0.2 just_audio: ^0.9.31 - text_to_speech: ^0.2.3 + flutter_tts: ^3.6.3 #signalr core signalr_core: ^1.1.1 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..63d4407 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + FlutterTtsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FlutterTtsPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b93c4c3..26bfe68 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + flutter_tts ) list(APPEND FLUTTER_FFI_PLUGIN_LIST