未验证 提交 60515c3b 编写于 作者: O openharmony_ci 提交者: Gitee

!14656 文件获取方式修改

Merge pull request !14656 from jiao_yanlin_001/master
...@@ -86,7 +86,7 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以 ...@@ -86,7 +86,7 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
参考以下示例,将采集到的数据写入文件。 参考以下示例,将采集到的数据写入文件。
```js ```js
import fileio from '@ohos.fileio'; import fs from '@ohos.file.fs';
let state = audioCapturer.state; let state = audioCapturer.state;
// 只有状态为STATE_RUNNING的时候才可以read. // 只有状态为STATE_RUNNING的时候才可以read.
...@@ -96,32 +96,36 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以 ...@@ -96,32 +96,36 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
} }
const path = '/data/data/.pulse_dir/capture_js.wav'; // 采集到的音频文件存储路径 const path = '/data/data/.pulse_dir/capture_js.wav'; // 采集到的音频文件存储路径
let fd = fileio.openSync(path, 0o102, 0o777); let file = fs.openSync(filePath, 0o2);
if (fd !== null) { let fd = file.fd;
console.info('AudioRecLog: file fd created'); if (file !== null) {
} console.info('AudioRecLog: file created');
else{ } else {
console.info('AudioRecLog: file fd create : FAILED'); console.info('AudioRecLog: file create : FAILED');
return; return;
} }
fd = fileio.openSync(path, 0o2002, 0o666);
if (fd !== null) { if (fd !== null) {
console.info('AudioRecLog: file fd opened in append mode'); console.info('AudioRecLog: file fd opened in append mode');
} }
let numBuffersToCapture = 150; // 循环写入150次 let numBuffersToCapture = 150; // 循环写入150次
let count = 0;
while (numBuffersToCapture) { while (numBuffersToCapture) {
let bufferSize = await audioCapturer.getBuffersize(); let bufferSize = await audioCapturer.getBuffersize();
let buffer = await audioCapturer.read(bufferSize, true); let buffer = await audioCapturer.read(bufferSize, true);
let options = {
offset: count * this.bufferSize,
length: this.bufferSize
}
if (typeof(buffer) == undefined) { if (typeof(buffer) == undefined) {
console.info('AudioRecLog: read buffer failed'); console.info('AudioRecLog: read buffer failed');
} else { } else {
let number = fileio.writeSync(fd, buffer); let number = fs.writeSync(fd, buffer, options);
console.info(`AudioRecLog: data written: ${number}`); console.info(`AudioRecLog: data written: ${number}`);
} }
numBuffersToCapture--; numBuffersToCapture--;
count++;
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册