#鸿蒙通关秘籍# 如何在HarmonyOS NEXT中使用AudioCapturer正确配置音频采集参数并创建实例?

HarmonyOS
2024-12-10 11:42:19
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
一路向北545
 import { audio } from '@kit.AudioKit';
 
 let audioStreamInfo: audio.AudioStreamInfo = {
   samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, // 采样率
   channels: audio.AudioChannel.CHANNEL_2, // 通道
   sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, // 采样格式
   encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW // 编码格式
 };
 
 let audioCapturerInfo: audio.AudioCapturerInfo = {
   source: audio.SourceType.SOURCE_TYPE_MIC,
   capturerFlags: 0
 };
 
 let audioCapturerOptions: audio.AudioCapturerOptions = {
   streamInfo: audioStreamInfo,
   capturerInfo: audioCapturerInfo
 };
 
 audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
   if (err) {
     console.error(`Invoke createAudioCapturer failed, code is ${err.code}, message is ${err.message}`);
   } else {
     console.info('Invoke createAudioCapturer succeeded.');
     let audioCapturer = data;
   }
 });
分享
微博
QQ
微信
回复
2024-12-14 20:57:21
相关问题