You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
3 months ago | |
|---|---|---|
| .. | ||
| android | 3 months ago | |
| ios/azure_speech | 3 months ago | |
| lib | 6 months ago | |
| .gitignore | 1 year ago | |
| .metadata | 6 months ago | |
| LICENSE | 2 years ago | |
| README.md | 2 years ago | |
| analysis_options.yaml | 1 year ago | |
| pubspec.yaml | 1 year ago | |
README.md
Azure Speech 插件
本插件为Flutter提供了Azure语音服务的集成,包括:
- 语音合成(TTS)
- 语音识别(ASR)
功能
语音合成(TTS)
- 支持多种语音(如中文、英文等)
- 语音参数调整(语速、音调、音量)
- 音频输出设备选择(扬声器、听筒、自动)
- SSML支持
语音识别(ASR)
- 一次性语音识别
- 连续语音识别
- 自动语言检测
- 音频处理优化(回音消除、噪声抑制等)
平台支持
- Android
- iOS
如何使用
初始化
import 'package:azure_speech/azure_speech.dart';
// 初始化TTS
await AzureSpeech.initializeTts(
'your_subscription_key',
'your_service_region',
language: 'zh-CN',
);
// 初始化ASR
await AzureSpeech.initializeAsr(
'your_subscription_key',
'your_service_region',
['zh-CN', 'en-US'],
);
语音合成
// 设置语音
await AzureSpeech.setTtsVoice('zh-CN-XiaoxiaoNeural');
// 设置语音参数
await AzureSpeech.setTtsSpeechParams(
rate: 0, // 语速 -100~100
pitch: 0, // 音调 -100~100
volume: 100, // 音量 0~100
);
// 设置音频输出设备
await AzureSpeech.setTtsAudioOutputType('AUTO'); // 'SPEAKER', 'EARPIECE', 'AUTO'
// 播放文本
await AzureSpeech.speakText('你好,世界!');
// 停止播放
await AzureSpeech.stopSpeaking();
// 检查是否正在播放
bool isSpeaking = await AzureSpeech.isSpeaking();
语音识别
// 一次性识别
final result = await AzureSpeech.recognizeOnce();
if (result['success']) {
print('识别文本: ${result['text']}');
print('识别语言: ${result['language']}');
} else {
print('识别失败: ${result['error']}');
}
// 连续识别
// 监听识别结果
AzureSpeech.asrResultStream.listen((event) {
switch (event['eventType']) {
case 'recognizing':
// 实时识别中的结果
print('识别中: ${event['text']}');
break;
case 'finalResult':
// 最终识别结果
print('最终结果: ${event['text']}');
break;
case 'error':
// 错误
print('错误: ${event['error']}');
break;
}
});
// 开始连续识别
await AzureSpeech.startContinuousRecognition();
// 停止连续识别
await AzureSpeech.stopContinuousRecognition();
// 检查连续识别是否活跃
bool isActive = await AzureSpeech.isContinuousRecognitionActive();
释放资源
// 释放所有资源
await AzureSpeech.dispose();
依赖项
本插件依赖于:
- Microsoft Cognitive Services Speech SDK
- Flutter
注意事项
- 使用前需要在Azure门户中创建语音服务资源,并获取订阅密钥和区域
- Android需要相关权限:RECORD_AUDIO, INTERNET等
- iOS需要在Info.plist中添加麦克风使用权限描述