鸿蒙(API 12 Beta2版)媒体开发【管理麦克风】

因为在录制过程中需要使用麦克风录制相关音频数据,所以建议开发者在调用录制接口前查询麦克风状态,并在录制过程中监听麦克风的状态变化,避免影响录制效果。

在音频录制过程中,用户可以将麦克风静音,此时录音过程正常进行,录制生成的数据文件的大小随录制时长递增,但写入文件的数据均为0,即无声数据(空白数据)。

开发步骤及注意事项

在AudioVolumeGroupManager中提供了管理麦克风状态的方法,接口的详细说明请参考[API文档]。

  1. 创建audioVolumeGroupManager对象。

    import { audio } from '@kit.AudioKit';

    let audioVolumeGroupManager: audio.AudioVolumeGroupManager;
    async function loadVolumeGroupManager() { //创建audioVolumeGroupManager对象
    const groupid = audio.DEFAULT_VOLUME_GROUP_ID;
    audioVolumeGroupManager = await audio.getAudioManager().getVolumeManager().getVolumeGroupManager(groupid);
    console.info('audioVolumeGroupManager create success.');
    }

  2. 调用isMicrophoneMute查询麦克风当前静音状态,返回true为静音,false为非静音。

    async function isMicrophoneMute() { //查询麦克风是否静音
    await audioVolumeGroupManager.isMicrophoneMute().then((value: boolean) => {
    console.info(isMicrophoneMute is: ${value}.);
    });
    }

相关推荐
Georgewu1 小时前
【HarmonyOS 6】 The target can not be empty. check the build.profile,json5 file of
harmonyos
Georgewu1 小时前
【HarmonyOS 6】Install Failed: error: failed to install bundle.code:9568322
harmonyos
hnxaoli2 小时前
win10(三)视频剪裁
音视频
爱笑的眼睛113 小时前
HarmonyOS 应用开发新范式:深入剖析 Stage 模型与 ArkTS 状态管理
华为·harmonyos
堆栈future3 小时前
我的个人网站上线了,AI再一次让我站起来了
程序员·llm·aigc
爱笑的眼睛114 小时前
深入浅出 HarmonyOS ArkUI 3.0:基于声明式开发范式与高级状态管理构建高性能应用
华为·harmonyos
大模型教程5 小时前
AI Agent 发展趋势与架构演进
程序员·llm·agent
ai产品老杨5 小时前
驱动物流创新与协同,助力物流行业可持续发展的智慧物流开源了
人工智能·开源·音视频·能源
AI大模型6 小时前
无所不能的Embedding(01) - 词向量三巨头之Word2vec模型详解&代码实现
程序员·llm·agent