更新记录

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.json5requestPermissions 中添加:

{
  "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>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

ohos.permission.MICROPHONE

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。