|
|
@ -1,5 +1,6 @@ |
|
|
import 'dart:async'; |
|
|
import 'dart:async'; |
|
|
import 'dart:io'; |
|
|
import 'dart:io'; |
|
|
|
|
|
import 'package:deep_voice/data/models/appconfig.dart'; |
|
|
import 'package:flutter/services.dart'; |
|
|
import 'package:flutter/services.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
@ -13,9 +14,10 @@ import '../tts_service.dart'; |
|
|
class AzureTtsService extends GetxService implements TtsService { |
|
|
class AzureTtsService extends GetxService implements TtsService { |
|
|
static final AzureTtsService to = Get.put(AzureTtsService()); |
|
|
static final AzureTtsService to = Get.put(AzureTtsService()); |
|
|
static const MethodChannel _channel = MethodChannel('azure_speech/tts'); |
|
|
static const MethodChannel _channel = MethodChannel('azure_speech/tts'); |
|
|
static const EventChannel _eventChannel = EventChannel('azure_speech/tts_events'); |
|
|
static const EventChannel _eventChannel = |
|
|
|
|
|
EventChannel('azure_speech/tts_events'); |
|
|
|
|
|
|
|
|
final GetStorage _storage = GetStorage(); |
|
|
// final GetStorage _storage = GetStorage(); |
|
|
bool _isInitialized = false; |
|
|
bool _isInitialized = false; |
|
|
late final String _subscriptionKey; |
|
|
late final String _subscriptionKey; |
|
|
late final String _serviceRegion; |
|
|
late final String _serviceRegion; |
|
|
@ -28,7 +30,8 @@ class AzureTtsService extends GetxService implements TtsService { |
|
|
bool _isProcessingQueue = false; |
|
|
bool _isProcessingQueue = false; |
|
|
|
|
|
|
|
|
// 事件流 |
|
|
// 事件流 |
|
|
final StreamController<TtsEvent> _eventStreamController = StreamController<TtsEvent>.broadcast(); |
|
|
final StreamController<TtsEvent> _eventStreamController = |
|
|
|
|
|
StreamController<TtsEvent>.broadcast(); |
|
|
StreamSubscription? _eventSubscription; |
|
|
StreamSubscription? _eventSubscription; |
|
|
|
|
|
|
|
|
// 可观察状态 |
|
|
// 可观察状态 |
|
|
@ -53,9 +56,9 @@ class AzureTtsService extends GetxService implements TtsService { |
|
|
|
|
|
|
|
|
/// 从环境变量加载配置 |
|
|
/// 从环境变量加载配置 |
|
|
void _loadConfig() { |
|
|
void _loadConfig() { |
|
|
final _env = _storage.read("ENV") as Map<String, String>; |
|
|
// final _env = _storage.read("ENV") as Map<String, String>; |
|
|
_subscriptionKey = _env['AZURE_SPEECH_KEY'] ?? ''; |
|
|
_subscriptionKey = AppConfig.env('AZURE_SPEECH_KEY') ?? ''; |
|
|
_serviceRegion = _env['AZURE_SPEECH_REGION'] ?? ''; |
|
|
_serviceRegion = AppConfig.env('AZURE_SPEECH_REGION') ?? ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 设置事件通道 |
|
|
/// 设置事件通道 |
|
|
@ -281,7 +284,10 @@ class AzureTtsService extends GetxService implements TtsService { |
|
|
// 监听事件流检查队列是否完成 |
|
|
// 监听事件流检查队列是否完成 |
|
|
final subscription = onEvent.listen((event) { |
|
|
final subscription = onEvent.listen((event) { |
|
|
// 当队列为空且不在处理中,且当前非说话状态,完成操作 |
|
|
// 当队列为空且不在处理中,且当前非说话状态,完成操作 |
|
|
if (_textQueue.isEmpty && !_isProcessingQueue && !_isSpeaking.value && !completer.isCompleted) { |
|
|
if (_textQueue.isEmpty && |
|
|
|
|
|
!_isProcessingQueue && |
|
|
|
|
|
!_isSpeaking.value && |
|
|
|
|
|
!completer.isCompleted) { |
|
|
completer.complete(true); |
|
|
completer.complete(true); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|