更新记录
1.0.0(2026-02-02) 下载此版本
- Init HarmonyOS speech recognition UTS plugin
平台兼容性
uni-app(4.84)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | 12 |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × | × | × | × |
uni-app x(4.84)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| × | × | × | × | 12 | × |
otto-harmony-speech-recognizer
HarmonyOS Core Speech Kit 语音识别(SpeechRecognizer)UTS 插件,基于系统级语音识别能力(离线中文)。
API
startSpeechRecognition(options)启动语音识别(默认使用麦克风录音模式)stopSpeechRecognition()停止识别并释放引擎getLastSpeechRecognitionResult()获取最近一次识别结果(可能为 null)
返回结果
text: 识别文本isFinal: 是否为最终结果isLast: 是否为最后一句raw: 原始 SpeechRecognitionResult
权限说明(必须)
需要麦克风权限:ohos.permission.MICROPHONE
HBuilderX 用户请在项目目录的 harmony-configs/entry/src/main/module.json5 的 requestPermissions 中添加:
{
"name": "ohos.permission.MICROPHONE"
}
示例(index.vue)
按住开始识别,松手停止监听。
<template>
<view class="page">
<button
class="hold-button"
@touchstart="startListen"
@touchend="stopListen"
@touchcancel="stopListen"
>
按住说话
</button>
<button @click="latestValue">查看最新结果</button>
</view>
</template>
<script setup lang="ts">
import {
startSpeechRecognition,
stopSpeechRecognition,
getLastSpeechRecognitionResult
} from '@/uni_modules/otto-harmony-speech-recognizer'
const startListen = () => {
startSpeechRecognition({
success(res) {
console.log('speech start:', res.sessionId)
},
onResult(res) {
console.log('speech result:', res.text, res.isFinal, res.isLast)
},
fail(err) {
console.error('speech error:', err.errCode, err.errMsg)
}
})
}
const stopListen = () => {
stopSpeechRecognition()
}
const latestValue = () => {
const last = getLastSpeechRecognitionResult()
console.log('last', last)
}
</script>

收藏人数:
下载插件并导入HBuilderX
赞赏(0)
下载 2
赞赏 0
下载 11240619
赞赏 1855
赞赏
京公网安备:11010802035340号