From a416eea88b8a8fba4c083bbca2d01dce72a2ff4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E4=B8=89=E5=9B=9B=E5=9B=9B?= <1184956293@qq.com> Date: Tue, 23 Aug 2022 03:08:44 +0000 Subject: [PATCH] =?UTF-8?q?update=20zh-cn/application-dev/media/audio-capt?= =?UTF-8?q?urer.md.=20=E4=BF=AE=E6=94=B9=E7=BC=A9=E8=BF=9B=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 三三四四 <1184956293@qq.com> --- zh-cn/application-dev/media/audio-capturer.md | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/zh-cn/application-dev/media/audio-capturer.md b/zh-cn/application-dev/media/audio-capturer.md index 84a51ffd24..84702dd781 100644 --- a/zh-cn/application-dev/media/audio-capturer.md +++ b/zh-cn/application-dev/media/audio-capturer.md @@ -22,24 +22,24 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以 ```js var audioStreamInfo = { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, - channels: audio.AudioChannel.CHANNEL_1, - sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, - encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW - } + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, + channels: audio.AudioChannel.CHANNEL_1, + sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, + encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW + } - var audioCapturerInfo = { - source: audio.SourceType.SOURCE_TYPE_MIC, - capturerFlags: 1 - } + var audioCapturerInfo = { + source: audio.SourceType.SOURCE_TYPE_MIC, + capturerFlags: 1 + } - var audioCapturerOptions = { - streamInfo: audioStreamInfo, - capturerInfo: audioCapturerInfo - } + var audioCapturerOptions = { + streamInfo: audioStreamInfo, + capturerInfo: audioCapturerInfo + } - let audioCapturer = await audio.createAudioCapturer(audioCapturerOptions); - var state = audioRenderer.state; + let audioCapturer = await audio.createAudioCapturer(audioCapturerOptions); + var state = audioRenderer.state; ``` 2. (可选)使用on('stateChange')订阅音频采集器状态更改。 @@ -49,26 +49,26 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以 audioCapturer.on('stateChange',(state) => { console.info('AudioCapturerLog: Changed State to : ' + state) switch (state) { - case audio.AudioState.STATE_PREPARED: - console.info('--------CHANGE IN AUDIO STATE----------PREPARED--------------'); - console.info('Audio State is : Prepared'); - break; - case audio.AudioState.STATE_RUNNING: - console.info('--------CHANGE IN AUDIO STATE----------RUNNING--------------'); - console.info('Audio State is : Running'); - break; - case audio.AudioState.STATE_STOPPED: - console.info('--------CHANGE IN AUDIO STATE----------STOPPED--------------'); - console.info('Audio State is : stopped'); - break; - case audio.AudioState.STATE_RELEASED: - console.info('--------CHANGE IN AUDIO STATE----------RELEASED--------------'); - console.info('Audio State is : released'); - break; - default: - console.info('--------CHANGE IN AUDIO STATE----------INVALID--------------'); - console.info('Audio State is : invalid'); - break; + case audio.AudioState.STATE_PREPARED: + console.info('--------CHANGE IN AUDIO STATE----------PREPARED--------------'); + console.info('Audio State is : Prepared'); + break; + case audio.AudioState.STATE_RUNNING: + console.info('--------CHANGE IN AUDIO STATE----------RUNNING--------------'); + console.info('Audio State is : Running'); + break; + case audio.AudioState.STATE_STOPPED: + console.info('--------CHANGE IN AUDIO STATE----------STOPPED--------------'); + console.info('Audio State is : stopped'); + break; + case audio.AudioState.STATE_RELEASED: + console.info('--------CHANGE IN AUDIO STATE----------RELEASED--------------'); + console.info('Audio State is : released'); + break; + default: + console.info('--------CHANGE IN AUDIO STATE----------INVALID--------------'); + console.info('Audio State is : invalid'); + break; } }); ``` @@ -80,9 +80,9 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以 ```js await audioCapturer.start(); if (audioCapturer.state == audio.AudioState.STATE_RUNNING) { - console.info('AudioRecLog: Capturer started'); + console.info('AudioRecLog: Capturer started'); } else { - console.info('AudioRecLog: Capturer start failed'); + console.info('AudioRecLog: Capturer start failed'); } ``` @@ -103,29 +103,29 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以 const path = '/data/data/.pulse_dir/capture_js.wav'; let fd = fileio.openSync(path, 0o102, 0o777); if (fd !== null) { - console.info('AudioRecLog: file fd created'); + console.info('AudioRecLog: file fd created'); } else{ - console.info('AudioRecLog: file fd create : FAILED'); - return; + console.info('AudioRecLog: file fd create : FAILED'); + return; } fd = fileio.openSync(path, 0o2002, 0o666); if (fd !== null) { - console.info('AudioRecLog: file fd opened in append mode'); + console.info('AudioRecLog: file fd opened in append mode'); } var numBuffersToCapture = 150; while (numBuffersToCapture) { - var buffer = await audioCapturer.read(bufferSize, true); - if (typeof(buffer) == undefined) { - console.info('read buffer failed'); - } else { - var number = fileio.writeSync(fd, buffer); - console.info('AudioRecLog: data written: ' + number); - } + var buffer = await audioCapturer.read(bufferSize, true); + if (typeof(buffer) == undefined) { + console.info('read buffer failed'); + } else { + var number = fileio.writeSync(fd, buffer); + console.info('AudioRecLog: data written: ' + number); + } - numBuffersToCapture--; + numBuffersToCapture--; } ``` @@ -134,9 +134,9 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以 ``` await audioCapturer.stop(); if (audioCapturer.state == audio.AudioState.STATE_STOPPED) { - console.info('AudioRecLog: Capturer stopped'); + console.info('AudioRecLog: Capturer stopped'); } else { - console.info('AudioRecLog: Capturer stop failed'); + console.info('AudioRecLog: Capturer stop failed'); } ``` @@ -145,8 +145,8 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以 ```js await audioCapturer.release(); if (audioCapturer.state == audio.AudioState.STATE_RELEASED) { - console.info('AudioRecLog: Capturer released'); + console.info('AudioRecLog: Capturer released'); } else { - console.info('AudioRecLog: Capturer release failed'); + console.info('AudioRecLog: Capturer release failed'); } ``` \ No newline at end of file -- GitLab