Skip to content

Commit

Permalink
task-2810229177954560:audio-record
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxue08 committed Feb 27, 2024
1 parent cb31af1 commit f07e373
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 47 deletions.
15 changes: 3 additions & 12 deletions packages/cw/cw_audio_library/components/cw-audio-record/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
- name: pauseRecord
title: 暂停录制
description: 暂停录制音频
- name: resumeRecord
title: 恢复录制
description: 恢复录制音频
- name: uploadRecord
title: 上传录制
description: 上传录制的音频
Expand All @@ -50,18 +53,6 @@
- name: type
type: string
description: 下载的文件格式(wav,mp3,pcm)
- name: deleteRecord
title: 删除录制
description: 删除录制的音频
- name: playRecord
title: 播放录制
description: 播放录制的音频
- name: pausePlayRecord
title: 暂停播放
description: 暂停播放录制的音频
- name: resumePlayRecord
title: 继续播放
description: 继续播放录制的音频
events:
- name: onUploadSuccess
description: 上传音频成功时
Expand Down
58 changes: 23 additions & 35 deletions packages/cw/cw_audio_library/components/cw-audio-record/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,55 +49,43 @@ export default {
};
},
methods: {
deleteRecord() {
async deleteRecord() {
if (this.recorder) {
this.recorder.destroy().then(() => {
console.log('删除录音');
recorder = null;
this.drawRecordId && cancelAnimationFrame(this.drawRecordId);
});
await this.recorder.destroy();
this.recorder = null;
this.drawRecordId && cancelAnimationFrame(this.drawRecordId);
}
},
playRecord() {
this.recorder && this.recorder.play();
this.drawRecordId && this.cancelAnimationFrame(drawRecordId);
this.drawRecordId = null;
console.log('播放录音');
},
pausePlayRecord() {
this.recorder && this.recorder.pausePlay();
console.log('暂停播放录音');
},
resumeRecord() {
this.recorder && this.recorder.resumePlay();
console.log('继续播放录音');
},
startRecord() {
async startRecord() {
const config = {
sampleRate: this.sampleRateOptions,
sampleBit: this.sampleBitOptions,
channelCount: this.channelOptions
};
if (!this.recorder) {
this.recorder = new Recorder(config);
this.recorder.start().then(() => {
this.isRecording = true;
}, (error) => {
console.log(`异常了,${error.name}:${error.message}`);
});
if (this.recorder) {
await this.deleteRecord()
}
this.recorder = new Recorder(config);
this.recorder.start().then(() => {
this.isRecording = true;
}, (error) => {
console.log(`异常了,${error.name}:${error.message}`);
});
this.recorder.onprogress = (params) => {
this.duration = params.duration.toFixed(2);
this.fileSize = params.fileSize;
if (this.fileSize >= this.maxFileSize * 1024 * 1024) {
this.stopRecord();
console.log('录音文件超过最大限制');
}
};
this.recorder.onprogress = (params) => {
this.duration = params.duration.toFixed(2);
this.fileSize = params.fileSize;
if (this.fileSize >= this.maxFileSize * 1024 * 1024) {
this.stopRecord();
console.log('录音文件超过最大限制');
}
};
this.drawRecord();
}
this.drawRecord();
},
async uploadRecord(type = 'wav') {
if (this.recorder && !this.isRecording && this.uploadUrl) {
Expand Down

0 comments on commit f07e373

Please sign in to comment.