@aizhushou/webspeech
v1.0.3
Published
browser web speech api wrapper
Readme
基于web speech api的响应式封装
Web Speech API是一个浏览器API,允许网页进行语音识别(ASR)和语音合成(TTS)。它分为两个部分:语音识别(Speech Recognition)和语音合成(Speech Synthesis)。本项目提供了对这两个功能的响应式封装,方便在Vue 3中使用。
1、TTS语音合成
const speechOutput = useSpeechSynthesis();
speechOutput.speek('Hello, world!'); // 语音合成
speechOutput.pause(); // 暂停
speechOutput.resume(); // 恢复
speechOutput.cancel(); // 取消
speechOutput.toggle(); // 切换暂停/恢复
console.log(speechOutput.isSupported); // 是否支持语音合成
console.log(speechOutput.isInactive); // 是否处于非活动状态
console.log(speechOutput.isSpeaking); // 是否正在说话
console.log(speechOutput.isPaused); // 是否暂停
console.log(speechOutput.status); // 语音合成状态
console.log(speechOutput.error); // 错误信息2. ASR语音识别
注意:Chrome浏览器需要科学上网才能使用语音识别功能。
const speechInput = useSpeechRecognition();
speechInput.start(); // 开始语音识别
speechInput.stop(); // 停止语音识别
speechInput.toggle(); // 切换开始/停止
console.log(speechInput.isSupported); // 是否支持语音识别
console.log(speechInput.isInactive); // 是否处于非活动状态
console.log(speechInput.isListening); // 是否正在监听
console.log(speechInput.content); // 识别的内容
console.log(speechInput.interimContent); // 临时识别的内容
console.log(speechInput.status); // 语音识别状态
console.log(speechInput.error); // 错误信息