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.
|
|
2 years ago | |
|---|---|---|
| .. | ||
| android | 2 years ago | |
| ios | 2 years ago | |
| lib | 2 years ago | |
| LICENSE | 2 years ago | |
| README.md | 2 years ago | |
| pubspec.yaml | 2 years ago | |
README.md
火山引擎语音服务插件
基于火山引擎语音SDK封装的Flutter插件,支持Android平台。
功能
- 语音合成(TTS)
- 支持在线/离线/混合合成模式
- 支持SSML格式文本
- 支持情感合成和情感预测
- 支持音量、语速、音高等多种参数调节
- 复刻音色支持
- 离线资源管理
- 语音识别(ASR)
- 一次性识别
- 连续识别
- 长按识别
- 热词优化
- 多语言支持
使用说明
TTS 语音合成
基础用法
import 'package:volcano_speech/volcano_speech.dart';
// 初始化
await VolcanoSpeech.initialize(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
// 设置音量、语速等参数
await VolcanoSpeech.setSpeechParams(
rate: 0, // 语速: -500到500,0为正常速度
volume: 100, // 音量: 0到100,默认100
pitch: 0, // 音高: -500到500,0为正常音高
silenceDuration: 500, // 静音段时长: 毫秒
);
// 设置音色
await VolcanoSpeech.setVoice(
voiceName: 'zh_female_qingxin',
voiceType: 'qingxin'
);
// 开始合成并播放
await VolcanoSpeech.speakText(text: '这是一段测试文本');
// 暂停播放
await VolcanoSpeech.pausePlayback();
// 继续播放
await VolcanoSpeech.resumePlayback();
// 停止播放
await VolcanoSpeech.stopSpeaking();
// 销毁引擎
await VolcanoSpeech.dispose();
进阶用法
// 设置工作模式
await VolcanoSpeech.setWorkMode(mode: TtsWorkMode.alternate); // 先在线,断网时切换离线
// 设置离线发音人
await VolcanoSpeech.setOfflineVoice(
voiceName: 'xifei',
voiceType: 'qingxin'
);
// 下载离线资源
await VolcanoSpeech.downloadOfflineResource(
voiceTypes: ['qingxin', 'zhenjiang'],
languages: ['zh-CN']
);
// 使用SSML格式文本
await VolcanoSpeech.setTextType(type: TtsTextType.ssml);
await VolcanoSpeech.speakText(
text: '<speak>这是一段<say-as interpret-as="date">2023-10-01</say-as>的语音合成</speak>'
);
// 设置情感
await VolcanoSpeech.setEmotion(emotion: 'happy');
// 启用情感预测
await VolcanoSpeech.setEnableEmotionPredict(enable: true);
// 启用服务端缓存
await VolcanoSpeech.setEnableCache(enable: true);
// 监听TTS进度事件
VolcanoSpeech.ttsProgressEvents.listen((event) {
print('播放进度: ${(event.progress * 100).toStringAsFixed(1)}%');
});
// 复刻音色支持
await VolcanoSpeech.setEnableVoiceClone(
enable: true,
backendCluster: 'your_cluster_name'
);
ASR 语音识别
一次性识别
import 'package:volcano_speech/volcano_speech.dart';
// 初始化
await VolcanoSpeech.initializeAsr(
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_API_KEY',
supportedLanguages: ['zh-CN'],
);
// 设置识别语言
await VolcanoSpeech.setAsrLanguage(language: 'zh-CN');
// 设置热词(可选)
await VolcanoSpeech.setAsrHotWords(
hotWords: '{"hotwords":[{"word":"火山引擎","scale":2.0}]}',
);
// 开始一次性识别
try {
final result = await VolcanoSpeech.recognizeOnce();
print('识别结果: ${result['text']}, 语言: ${result['language']}');
} catch (e) {
print('识别出错: $e');
}
// 销毁引擎
await VolcanoSpeech.disposeAsr();
连续识别
import 'package:volcano_speech/volcano_speech.dart';
// 初始化
await VolcanoSpeech.initializeAsr(
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_API_KEY',
);
// 监听识别事件
VolcanoSpeech.asrEvents.listen((event) {
switch (event.type) {
case AsrEventType.sessionStarted:
print('识别会话开始');
break;
case AsrEventType.sessionStopped:
print('识别会话结束');
break;
case AsrEventType.recognizing:
print('正在识别: ${event.text}');
break;
case AsrEventType.result:
print('识别结果: ${event.text}');
break;
case AsrEventType.volumeChanged:
print('音量: ${event.volume}');
break;
case AsrEventType.error:
print('识别错误: ${event.errorMessage}');
break;
}
});
// 开始连续识别
await VolcanoSpeech.startContinuousRecognition();
// 检查是否正在识别
final isActive = await VolcanoSpeech.isContinuousRecognitionActive();
print('是否正在识别: $isActive');
// 停止连续识别
await VolcanoSpeech.stopContinuousRecognition();
长按识别
import 'package:volcano_speech/volcano_speech.dart';
// 初始化
await VolcanoSpeech.initializeAsr(
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_API_KEY',
);
// 监听识别事件
VolcanoSpeech.asrEvents.listen((event) {
// 处理事件...
});
// 用户按下按钮时开始识别
onPressed: () async {
await VolcanoSpeech.startListening();
},
// 用户释放按钮时停止识别
onReleased: () async {
await VolcanoSpeech.stopListening();
},