未验证 提交 9dca56c2 编写于 作者: O openharmony_ci 提交者: Gitee

!15516 翻译完成:14847+14624 update js_apis_audio.md (cherry-pick)

Merge pull request !15516 from wusongqing/cherry-pick-1678091830
......@@ -75,7 +75,7 @@ Creates an **AudioRenderer** instance. This API uses an asynchronous callback to
```js
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
import fs from '@ohos.file.fs';
import audio from '@ohos.multimedia.audio';
let audioStreamInfo = {
......@@ -130,7 +130,7 @@ Creates an **AudioRenderer** instance. This API uses a promise to return the res
```js
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
import fs from '@ohos.file.fs';
import audio from '@ohos.multimedia.audio';
let audioStreamInfo = {
......@@ -457,7 +457,7 @@ Enumerates the audio sample formats.
| SAMPLE_FORMAT_S16LE | 1 | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE | 2 | Signed 24-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_S32LE | 3 | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_F32LE<sup>9+</sup> | 4 | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_F32LE<sup>9+</sup> | 4 | Signed 32-bit floating point number, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
## AudioErrors<sup>9+</sup>
......@@ -529,7 +529,7 @@ Enumerates the audio content types.
| CONTENT_TYPE_SPEECH | 1 | Speech. |
| CONTENT_TYPE_MUSIC | 2 | Music. |
| CONTENT_TYPE_MOVIE | 3 | Movie. |
| CONTENT_TYPE_SONIFICATION | 4 | Sonification content.|
| CONTENT_TYPE_SONIFICATION | 4 | Notification tone. |
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5 | Ringtone. |
## StreamUsage
......@@ -1757,7 +1757,7 @@ Sets a device to the active state. This API uses an asynchronous callback to ret
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Audio device type. |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Active audio device type. |
| active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
......@@ -1789,7 +1789,7 @@ Sets a device to the active state. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Audio device type.|
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Active audio device type. |
| active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
**Return value**
......@@ -1823,7 +1823,7 @@ Checks whether a device is active. This API uses an asynchronous callback to ret
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Audio device type. |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Active audio device type. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the active state of the device.|
**Example**
......@@ -1854,7 +1854,7 @@ Checks whether a device is active. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Audio device type.|
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Active audio device type. |
**Return value**
......@@ -3950,6 +3950,7 @@ Describes the audio renderer change event.
**Example**
```js
import audio from '@ohos.multimedia.audio';
const audioManager = audio.getAudioManager();
......@@ -4054,7 +4055,7 @@ Describes an audio device.
| ----------------------------- | ------------------------- | -------- | -------- | ------------------------------------------------------------ |
| deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role. |
| deviceType | [DeviceType](#devicetype) | Yes | No | Device type. |
| id<sup>9+</sup> | number | Yes | No | Device ID. |
| id<sup>9+</sup> | number | Yes | No | Device ID, which is unique. |
| name<sup>9+</sup> | string | Yes | No | Device name. |
| address<sup>9+</sup> | string | Yes | No | Device address. |
| sampleRates<sup>9+</sup> | Array&lt;number&gt; | Yes | No | Supported sampling rates. |
......@@ -4234,7 +4235,6 @@ audioRenderer.getStreamInfo().then((streamInfo) => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### getAudioStreamId<sup>9+</sup>
......@@ -4257,7 +4257,6 @@ Obtains the stream ID of this **AudioRenderer** instance. This API uses an async
audioRenderer.getAudioStreamId((err, streamid) => {
console.info(`Renderer GetStreamId: ${streamid}`);
});
```
### getAudioStreamId<sup>9+</sup>
......@@ -4282,7 +4281,6 @@ audioRenderer.getAudioStreamId().then((streamid) => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### start<sup>8+</sup>
......@@ -4309,7 +4307,6 @@ audioRenderer.start((err) => {
console.info('Renderer start success.');
}
});
```
### start<sup>8+</sup>
......@@ -4334,7 +4331,6 @@ audioRenderer.start().then(() => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### pause<sup>8+</sup>
......@@ -4361,7 +4357,6 @@ audioRenderer.pause((err) => {
console.info('Renderer paused.');
}
});
```
### pause<sup>8+</sup>
......@@ -4386,7 +4381,6 @@ audioRenderer.pause().then(() => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### drain<sup>8+</sup>
......@@ -4413,7 +4407,6 @@ audioRenderer.drain((err) => {
console.info('Renderer drained.');
}
});
```
### drain<sup>8+</sup>
......@@ -4438,7 +4431,6 @@ audioRenderer.drain().then(() => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### stop<sup>8+</sup>
......@@ -4465,7 +4457,6 @@ audioRenderer.stop((err) => {
console.info('Renderer stopped.');
}
});
```
### stop<sup>8+</sup>
......@@ -4490,7 +4481,6 @@ audioRenderer.stop().then(() => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### release<sup>8+</sup>
......@@ -4517,7 +4507,6 @@ audioRenderer.release((err) => {
console.info('Renderer released.');
}
});
```
### release<sup>8+</sup>
......@@ -4542,7 +4531,6 @@ audioRenderer.release().then(() => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### write<sup>8+</sup>
......@@ -4577,17 +4565,26 @@ async function getCacheDir(){
path = await context.getCacheDir();
}
let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
let ss = fileio.createStreamSync(filePath, 'r');
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
audioRenderer.write(buf, (err, writtenbytes) => {
if (writtenbytes < 0) {
console.error('write failed.');
} else {
console.info(`Actual written bytes: ${writtenbytes}`);
}
});
let len = stat.size % this.bufferSize == 0 ? Math.floor(stat.size / this.bufferSize) : Math.floor(stat.size / this.bufferSize + 1);
for (let i = 0;i < len; i++) {
let options = {
offset: i * this.bufferSize,
length: this.bufferSize
}
let readsize = await fs.read(file.fd, buf, options)
let writeSize = await new Promise((resolve,reject)=>{
this.audioRenderer.write(buf,(err,writeSize)=>{
if(err){
reject(err)
}else{
resolve(writeSize)
}
})
})
}
```
### write<sup>8+</sup>
......@@ -4621,19 +4618,22 @@ async function getCacheDir(){
path = await context.getCacheDir();
}
let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
let ss = fileio.createStreamSync(filePath, 'r');
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
audioRenderer.write(buf).then((writtenbytes) => {
if (writtenbytes < 0) {
console.error('write failed.');
} else {
console.info(`Actual written bytes: ${writtenbytes}`);
}
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
let len = stat.size % this.bufferSize == 0 ? Math.floor(stat.size / this.bufferSize) : Math.floor(stat.size / this.bufferSize + 1);
for (let i = 0;i < len; i++) {
let options = {
offset: i * this.bufferSize,
length: this.bufferSize
}
let readsize = await fs.read(file.fd, buf, options)
try{
let writeSize = await this.audioRenderer.write(buf);
} catch(err) {
console.error(`audioRenderer.write err: ${err}`);
}
}
```
### getAudioTime<sup>8+</sup>
......@@ -4656,7 +4656,6 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
audioRenderer.getAudioTime((err, timestamp) => {
console.info(`Current timestamp: ${timestamp}`);
});
```
### getAudioTime<sup>8+</sup>
......@@ -4681,7 +4680,6 @@ audioRenderer.getAudioTime().then((timestamp) => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### getBufferSize<sup>8+</sup>
......@@ -4706,7 +4704,6 @@ let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
console.error('getBufferSize error');
}
});
```
### getBufferSize<sup>8+</sup>
......@@ -4733,7 +4730,6 @@ audioRenderer.getBufferSize().then((data) => {
}).catch((err) => {
console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
});
```
### setRenderRate<sup>8+</sup>
......@@ -4761,7 +4757,6 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) =>
console.info('Callback invoked to indicate a successful render rate setting.');
}
});
```
### setRenderRate<sup>8+</sup>
......@@ -4792,7 +4787,6 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(()
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### getRenderRate<sup>8+</sup>
......@@ -4815,7 +4809,6 @@ Obtains the current render rate. This API uses an asynchronous callback to retur
audioRenderer.getRenderRate((err, renderrate) => {
console.info(`getRenderRate: ${renderrate}`);
});
```
### getRenderRate<sup>8+</sup>
......@@ -4840,9 +4833,7 @@ audioRenderer.getRenderRate().then((renderRate) => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### setInterruptMode<sup>9+</sup>
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
......@@ -4872,9 +4863,7 @@ audioRenderer.setInterruptMode(mode).then(data=>{
}).catch((err) => {
console.error(`setInterruptMode Fail: ${err}`);
});
```
### setInterruptMode<sup>9+</sup>
setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
......@@ -4900,7 +4889,6 @@ audioRenderer.setInterruptMode(mode, (err, data)=>{
}
console.info('setInterruptMode Success!');
});
```
### setVolume<sup>9+</sup>
......@@ -4931,9 +4919,7 @@ audioRenderer.setVolume(0.5).then(data=>{
}).catch((err) => {
console.error(`setVolume Fail: ${err}`);
});
```
### setVolume<sup>9+</sup>
setVolume(volume: number, callback: AsyncCallback\<void>): void
......@@ -4958,7 +4944,6 @@ audioRenderer.setVolume(0.5, (err, data)=>{
}
console.info('setVolume Success!');
});
```
### on('audioInterrupt')<sup>9+</sup>
......@@ -5038,7 +5023,6 @@ async function onAudioInterrupt(){
}
});
}
```
### on('markReach')<sup>8+</sup>
......@@ -5065,7 +5049,6 @@ audioRenderer.on('markReach', 1000, (position) => {
console.info('ON Triggered successfully');
}
});
```
......@@ -5087,7 +5070,6 @@ Unsubscribes from mark reached events.
```js
audioRenderer.off('markReach');
```
### on('periodReach') <sup>8+</sup>
......@@ -5114,7 +5096,6 @@ audioRenderer.on('periodReach', 1000, (position) => {
console.info('ON Triggered successfully');
}
});
```
### off('periodReach') <sup>8+</sup>
......@@ -5135,10 +5116,9 @@ Unsubscribes from period reached events.
```js
audioRenderer.off('periodReach')
```
### on('stateChange')<sup>8+</sup>
### on('stateChange') <sup>8+</sup>
on(type: 'stateChange', callback: Callback<AudioState\>): void
......@@ -5164,7 +5144,6 @@ audioRenderer.on('stateChange', (state) => {
console.info('audio renderer state is: STATE_RUNNING');
}
});
```
## AudioCapturer<sup>8+</sup>
......@@ -5183,7 +5162,6 @@ Provides APIs for audio capture. Before calling any API in **AudioCapturer**, yo
```js
let state = audioCapturer.state;
```
### getCapturerInfo<sup>8+</sup>
......@@ -5212,7 +5190,6 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => {
console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
}
});
```
......@@ -5245,7 +5222,6 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => {
}).catch((err) => {
console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`);
});
```
### getStreamInfo<sup>8+</sup>
......@@ -5276,7 +5252,6 @@ audioCapturer.getStreamInfo((err, streamInfo) => {
console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
}
});
```
### getStreamInfo<sup>8+</sup>
......@@ -5305,7 +5280,6 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => {
}).catch((err) => {
console.error(`getStreamInfo :ERROR: ${err}`);
});
```
### getAudioStreamId<sup>9+</sup>
......@@ -5328,7 +5302,6 @@ Obtains the stream ID of this **AudioCapturer** instance. This API uses an async
audioCapturer.getAudioStreamId((err, streamid) => {
console.info(`audioCapturer GetStreamId: ${streamid}`);
});
```
### getAudioStreamId<sup>9+</sup>
......@@ -5353,7 +5326,6 @@ audioCapturer.getAudioStreamId().then((streamid) => {
}).catch((err) => {
console.error(`ERROR: ${err}`);
});
```
### start<sup>8+</sup>
......@@ -5380,7 +5352,6 @@ audioCapturer.start((err) => {
console.info('Capturer start success.');
}
});
```
......@@ -5412,7 +5383,6 @@ audioCapturer.start().then(() => {
}).catch((err) => {
console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`);
});
```
### stop<sup>8+</sup>
......@@ -5439,7 +5409,6 @@ audioCapturer.stop((err) => {
console.info('Capturer stopped.');
}
});
```
......@@ -5469,7 +5438,6 @@ audioCapturer.stop().then(() => {
}).catch((err) => {
console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
});
```
### release<sup>8+</sup>
......@@ -5496,7 +5464,6 @@ audioCapturer.release((err) => {
console.info('capturer released.');
}
});
```
......@@ -5526,7 +5493,6 @@ audioCapturer.release().then(() => {
}).catch((err) => {
console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
});
```
### read<sup>8+</sup>
......@@ -5560,7 +5526,6 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => {
console.info('Success in reading the buffer data');
}
});
```
### read<sup>8+</sup>
......@@ -5600,7 +5565,6 @@ audioCapturer.read(bufferSize, true).then((buffer) => {
}).catch((err) => {
console.info(`ERROR : ${err}`);
});
```
### getAudioTime<sup>8+</sup>
......@@ -5623,7 +5587,6 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
audioCapturer.getAudioTime((err, timestamp) => {
console.info(`Current timestamp: ${timestamp}`);
});
```
### getAudioTime<sup>8+</sup>
......@@ -5648,7 +5611,6 @@ audioCapturer.getAudioTime().then((audioTime) => {
}).catch((err) => {
console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
});
```
### getBufferSize<sup>8+</sup>
......@@ -5678,7 +5640,6 @@ audioCapturer.getBufferSize((err, bufferSize) => {
});
}
});
```
### getBufferSize<sup>8+</sup>
......@@ -5705,7 +5666,6 @@ audioCapturer.getBufferSize().then((data) => {
}).catch((err) => {
console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
});
```
### on('markReach')<sup>8+</sup>
......@@ -5732,7 +5692,6 @@ audioCapturer.on('markReach', 1000, (position) => {
console.info('ON Triggered successfully');
}
});
```
### off('markReach')<sup>8+</sup>
......@@ -5753,7 +5712,6 @@ Unsubscribes from mark reached events.
```js
audioCapturer.off('markReach');
```
### on('periodReach')<sup>8+</sup>
......@@ -5780,7 +5738,6 @@ audioCapturer.on('periodReach', 1000, (position) => {
console.info('ON Triggered successfully');
}
});
```
### off('periodReach')<sup>8+</sup>
......@@ -5801,10 +5758,9 @@ Unsubscribes from period reached events.
```js
audioCapturer.off('periodReach')
```
### on('stateChange')<sup>8+</sup>
### on('stateChange') <sup>8+</sup>
on(type: 'stateChange', callback: Callback<AudioState\>): void
......@@ -5830,7 +5786,6 @@ audioCapturer.on('stateChange', (state) => {
console.info('audio capturer state is: STATE_RUNNING');
}
});
```
## ToneType<sup>9+</sup>
......@@ -5905,7 +5860,6 @@ tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
console.info('callback call load success');
}
});
```
### load<sup>9+</sup>
......@@ -5938,7 +5892,6 @@ tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
}).catch(() => {
console.error('promise call load fail');
});
```
### start<sup>9+</sup>
......@@ -5968,7 +5921,6 @@ tonePlayer.start((err) => {
console.info('callback call start success');
}
});
```
### start<sup>9+</sup>
......@@ -5995,7 +5947,6 @@ tonePlayer.start().then(() => {
}).catch(() => {
console.error('promise call start fail');
});
```
### stop<sup>9+</sup>
......@@ -6025,7 +5976,6 @@ tonePlayer.stop((err) => {
console.error('callback call stop success ');
}
});
```
### stop<sup>9+</sup>
......@@ -6052,7 +6002,6 @@ tonePlayer.stop().then(() => {
}).catch(() => {
console.error('promise call stop fail');
});
```
### release<sup>9+</sup>
......@@ -6082,7 +6031,6 @@ tonePlayer.release((err) => {
console.info('callback call release success ');
}
});
```
### release<sup>9+</sup>
......@@ -6109,7 +6057,6 @@ tonePlayer.release().then(() => {
}).catch(() => {
console.error('promise call release fail');
});
```
## ActiveDeviceType<sup>(deprecated)</sup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册