Files
ai_chat_assistant/lib/services/platform_tts_service.dart

37 lines
912 B
Dart
Raw Permalink Normal View History

import 'package:ai_chat_core/ai_chat_core.dart';
import 'package:flutter/services.dart';
/// TtsService 的平台特定实现,通过 MethodChannel 调用原生代码
class PlatformTtsService implements TtsService {
@override
final String channelName;
final MethodChannel _channel;
PlatformTtsService(this.channelName): _channel = MethodChannel(channelName);
Future<T?> _execute<T>(String method, [Map<Object, Object>? arguments]) {
return _channel.invokeMethod(method, arguments);
}
@override
Future<bool> start(bool isChinese) async {
return await _execute('startTts', {'isChinese': isChinese}) ?? false;
}
@override
Future<void> send(String text) async {
await _execute('sendTts', {'text': text});
}
@override
Future<void> complete() async {
await _execute('completeTts');
}
@override
Future<void> stop() async {
await _execute('stopTts');
}
}