# 火山引擎语音服务插件 基于火山引擎语音SDK封装的Flutter插件,支持Android平台。 ## 功能 - 语音合成(TTS) - 支持在线/离线/混合合成模式 - 支持SSML格式文本 - 支持情感合成和情感预测 - 支持音量、语速、音高等多种参数调节 - 复刻音色支持 - 离线资源管理 - 语音识别(ASR) - 一次性识别 - 连续识别 - 长按识别 - 热词优化 - 多语言支持 ## 使用说明 ### TTS 语音合成 #### 基础用法 ```dart 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(); ``` #### 进阶用法 ```dart // 设置工作模式 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: '这是一段2023-10-01的语音合成' ); // 设置情感 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 语音识别 #### 一次性识别 ```dart 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(); ``` #### 连续识别 ```dart 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(); ``` #### 长按识别 ```dart 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(); }, ```