更新记录
0.1.2(2026-07-17) 下载此版本
- 删除冗余代码
0.1.1(2026-07-17) 下载此版本
- 首次发版
平台兼容性
uni-app(5.12)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | × | × | × | × | × | × | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | × | × | × | × | × | - | × | × | × | - | - |
LongPressRecord
LongPressRecord 是一个面向微信小程序的 uni_modules 长按语音识别组件,适合用于工单描述、问诊输入、客服备注、表单语音录入等场景。
组件已封装以下能力:
- 长按开始录音,松开结束录音
- 支持
v-model/modelValue双向绑定文本 - 支持录音回放
- 支持接入 WebSocket 流式语音识别服务并实时回填文本
- 未配置识别服务时自动降级为仅录音模式
- 支持
camelCase与kebab-case两套事件监听方式
平台兼容性
当前版本仅支持微信小程序。
| 平台 | 支持情况 |
|---|---|
| 微信小程序 | √ |
| H5 | x |
| App | x |
| 其他小程序平台 | x |
目录结构
uni_modules/long-recoder/
├─ components/
│ └─ long-press-record/
│ ├─ long-press-record.vue
│ └─ longPressRecordCore.js
├─ changelog.md
├─ package.json
└─ README.md
快速开始
组件遵循 easycom 规范,安装到 uni_modules 后可直接在页面中使用。
<template>
<view>
<long-press-record
v-model="form.content"
theme-color="#e56b2f"
:max-duration="60000"
:max-text-length="200"
:enable-volc-asr="enableVolcAsr"
:volc-config="volcConfig"
placeholder="请输入文字,或长按语音录入内容"
@record-complete="handleRecordComplete"
@voice-path-change="handleVoicePathChange"
/>
</view>
</template>
<script>
export default {
data() {
return {
enableVolcAsr: true,
form: {
content: ''
},
voicePath: '',
volcConfig: {
appKey: '你的 appKey',
accessKey: '你的 accessKey',
resourceId: 'volc.seedasr.sauc.duration',
url: 'wss://openspeech.bytedance.com/api/v3/sauc/bigmodel_async',
request: {
model_name: 'bigmodel',
enable_punc: true,
enable_itn: true,
enable_nonstream: true,
end_window_size: 800,
enable_ddc: true,
result_type: 'full'
}
}
}
},
methods: {
handleRecordComplete(result) {
this.form.content = result.text
this.voicePath = result.voicePath
},
handleVoicePathChange(voicePath) {
this.voicePath = voicePath
}
}
}
</script>
演示页
仓库内已提供演示页:pages/indexTwo/indexTwo.vue
演示页特性:
- 支持切换“仅录音 / 语音识别”两种模式
- 自动读取
uni.setStorageSync('huoshan_config', ...)保存过的识别配置 - 显示录音路径、识别结果和事件回显,便于联调
本地缓存配置示例:
Props
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
value |
String |
'' |
vue2 双向绑定值 |
modelValue |
String |
'' |
vue3 双向绑定值 |
placeholder |
String |
'请输入文字或长按语音输入内容' |
输入框占位文案 |
themeColor |
String |
'#1fa27c' |
组件主色,影响录音按钮、回放按钮和高亮边框 |
maxDuration |
Number |
60000 |
最大录音时长,单位 ms |
maxTextLength |
Number |
100 |
最大文本长度 |
enableVolcAsr |
Boolean |
true |
是否启用语音识别 |
volcConfig |
Object |
{} |
语音识别服务配置 |
enablePlayback |
Boolean |
true |
是否允许回放录音 |
volcConfig 结构
{
appKey: '',
accessKey: '',
resourceId: 'volc.seedasr.sauc.duration',
url: 'wss://openspeech.bytedance.com/api/v3/sauc/bigmodel_async',
headers: {},
request: {
model_name: 'bigmodel',
enable_punc: true,
enable_itn: true,
enable_nonstream: true,
end_window_size: 800,
enable_ddc: true,
result_type: 'full'
}
}
说明:
- 当
enableVolcAsr = true但appKey、accessKey、url不完整时,组件会自动退回为仅录音模式 themeColor当前支持十六进制颜色值,例如#1fa27c、#e56b2f
事件
推荐在模板中使用 kebab-case 监听;组件内部同时兼容 camelCase 与 kebab-case。
| 推荐监听名 | 兼容监听名 | 返回值 | 说明 |
|---|---|---|---|
input |
input |
string |
vue2 文本变更 |
update:modelValue |
update:modelValue |
string |
vue3 文本变更 |
change |
change |
string |
文本内容变化 |
record-start |
recordStart |
object |
开始录音 |
record-stop |
recordStop |
object |
停止录音 |
voice-path-change |
voicePathChange |
string |
录音文件路径变化 |
playback-change |
playbackChange |
boolean |
回放状态变化 |
playback-error |
playbackError |
any |
回放失败 |
record-complete |
recordComplete |
object |
录音和识别完成 |
record-start 返回结构:
{
usedVolcAsr: true,
maxDuration: 60000
}
record-stop 返回结构:
{
voicePath: '',
rawVoicePath: '',
usedVolcAsr: true,
duration: 3200
}
record-complete 返回结构:
{
voicePath: '',
rawVoicePath: '',
text: '',
logId: '',
usedVolcAsr: true
}
注意事项
- 组件内部会主动申请微信小程序录音权限,但业务项目仍需在微信开发者工具和小程序后台确认相关能力配置
- 当前识别链路默认以 WebSocket 流式接口为例,如果你的服务协议不同,可改造
longPressRecordCore.js中的connectSocket与数据收发逻辑 - 若只需要录音文件,不需要实时转文字,建议将
enableVolcAsr设为false
更新记录
详细更新请查看 changelog.md

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