更新记录

1.0.0(2026-04-16)

鸿蒙端录音实时帧回调


平台兼容性

uni-app(4.75)

Vue2 Vue3 Chrome Safari app-vue app-vue插件版本 app-nvue Android iOS 鸿蒙
- - × × 1.0.0 - × × 5.0
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
× × × × × × × × × - × ×

yao-hm-record

使用示例

<template>
    <view class="content">
        <button class="btn" @click="start">开始 </button>
        <button class="btn" @click="Pause">暂停</button>
        <button class="btn" @click="Resume">继续</button>
        <button class="btn" @click="stop">停止</button>
        <button class="btn" @click="play">播放</button>
        <view>帧大小:{{numberArray.length}}</view>
        实时回调:{{numberArray}}
    </view>
</template>

<script>
    var AudioContext = uni.createInnerAudioContext();
    import {
        recordStart,
        recordPause,
        recordResume,
        recordStop,
        onFrameRecorded
    } from '@/uni_modules/yao-hm-record';
    export default {
        data() {
            return {
                filePath: '',
                numberArray: ''
            }
        },
        onLoad() {
            onFrameRecorded((buffer) => {
                const uint8Array = new Uint8Array(buffer);
                const numberArray = Array.from(uint8Array);
                this.numberArray = numberArray;
            })
        },
        methods: {
            start() {
                var options = {
                    sampleRate: 16000, //采用率s
                    numberOfChannels: 1, //(1单声道 2双声道)
                    frameSize: 2560, //指定帧大小
                    audioSource: 6, //音频来源(1=手机麦克风)(6=默认麦克风)
                };
                //开启录音
                recordStart(options, (str) => {
                    console.log(str)
                });
            },
            Pause() {
                recordPause();
            },
            Resume() {
                recordResume();
            },
            stop() {
                recordStop((path) => {
                    console.log('音频地址', path);
                    this.filePath = path;
                });
            },

            play() {
                AudioContext.src = this.filePath;
                AudioContext.onPlay(() => {
                    console.log("播放成功")
                })

                AudioContext.onError((err) => {
                    console.log("播放错误+")
                })
                AudioContext.play();
            }
        }
    }
</script>

隐私、权限声明

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

需要麦克风权限

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

插件不采集任何数据

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

暂无用户评论。