Commit a7a6c756 authored by Tt's avatar Tt

录音逻辑添加

parent 87d4d7e5
......@@ -4,6 +4,8 @@ import pg from "./pg_hy01_danci";
const { ccclass, property } = cc._decorator;
let win: any = window;
let courseware = win.courseware;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
......@@ -51,6 +53,85 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
private letter: string;
private targetTime: number;
private recordAudio: string;
//按钮触发,使用的方法
async onTouchRecord() {
this.recordAudio = '';
// let AniNode = pg.view.find(this.layout_record, 'AniNode');
// AniNode.active = true;
this.showTimeStart();
cc.audioEngine.stopAllEffects();
courseware && courseware.startTest(this.letter); //开始录音
}
async onTouchRecordEnd() {
// let AniNode = pg.view.find(this.layout_record, 'AniNode');
// AniNode.active = false;
this.showTimeEnd();
let testData = {
"dtLastResponse": "2021-09-17 13:36:26:109",
"refText": "I haven't found anything out about him yet.",
"recordId": "6144295213f0a2200000ed93",
"eof": 1,
audioUrl: 'http://staging-teach.cdn.ireadabc.com/43839adb578c7e01456748b8a176a0c3_l.mp3',
"result": {
"pronunciation": 25,
"resource_version": "3.1.0",
"fluency": 60,
"rhythm": 90,
"kernel_version": "5.2.4",
"overall": 8,//75
"integrity": 100,
"duration": "6.779",
"rear_tone": "fall",
"speed": 96,
},
"tokenId": "6144295408558b08dd000001",
"applicationId": "154838659000009e"
}
if (!courseware) {
return this.recrodEnd(testData)
}
courseware && courseware.stopTest((res) => {
res = JSON.parse(res);
this.recrodEnd(res);
}); //结束录音
}
async recrodEnd(data) {
this.recordAudio = data.audioUrl;
let score = data.result.overall;
pg.event.emit('layer_record_score', score);
}
private startTime: number;
showTimeStart() {
if (!this.targetTime) return;
let nowTime = new Date().getTime();
this.startTime = nowTime;
}
showTimeUpdate() {
if (!this.startTime) return;
let nowTime = new Date().getTime();
let subTime = (nowTime - this.startTime) / 1000;
let percent = 1 - (subTime / this.targetTime);
percent = Math.max(percent, 0)
// let record_time = pg.view.find(this.layout_record, 'record_time');
// record_time.getComponent(cc.Sprite).fillRange = percent;
// if (percent == 0) {
// this.showTimeEnd();
// }
}
showTimeEnd() {
this.startTime = null;
// let record_time = pg.view.find(this.layout_record, 'record_time');
// record_time.getComponent(cc.Sprite).fillRange = 0;
}
playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment