Commit b1dd2c8f authored by Tt's avatar Tt

待声音接口确认后再进行api添加

parent 885ee0df
This diff is collapsed.
...@@ -4,6 +4,8 @@ import pg from "./pg_hy06_danxuan"; ...@@ -4,6 +4,8 @@ import pg from "./pg_hy06_danxuan";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
let win: any = window;
let courseware = win.courseware;
@ccclass @ccclass
export default class SceneComponent extends MyCocosSceneComponent { export default class SceneComponent extends MyCocosSceneComponent {
...@@ -51,16 +53,110 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -51,16 +53,110 @@ export default class SceneComponent extends MyCocosSceneComponent {
private right: number private right: number
//进度条成都 //进度条成都
private lengthProgress: number private lengthProgress: number
private layer_game: cc.Node;
private layout_begin: cc.Node;
initView() { initView() {
// 取对象 // 取对象
/* this.topQuestion = pg.view.find(this, 'topQuestion'); */ /* this.topQuestion = pg.view.find(this, 'topQuestion'); */
this.layer_game = pg.view.find(this, 'layer_game');
this.layout_begin = pg.view.find(this.layer_game, 'layout_begin');
} }
initListener() { initListener() {
//增加图片答案对象点击事件 //增加图片答案对象点击事件
}
async initGame() {
await this.showBegin()
this.hideBegin();
this.nextQuestion();
} }
initGame() { showCamera() {
// cw.openRecognitionCamera({
// x: 0,
// y: 0,
// width: 1,
// height: 1,
// })
}
startRecord() {
courseware && courseware.startTest(''); //开始录音
}
endRecord() {
let testData = {
"dtLastResponse": "2021-09-17 13:36:26:109",
"refText": "I haven't found anything out about him yet.",
"recordId": "6144295213f0a2200000ed93",
"eof": 1,
"result": {
"pronunciation": 25,
"resource_version": "3.1.0",
"fluency": 60,
"rhythm": 90,
"kernel_version": "5.2.4",
"overall": 25,//75
"integrity": 100,
"duration": "6.779",
"rear_tone": "fall",
"speed": 96,
},
"tokenId": "6144295408558b08dd000001",
"applicationId": "154838659000009e"
}
if (!courseware) return this.recrodEnd(testData)
courseware && courseware.stopTest((data) => {
data = JSON.parse(data);
this.recrodEnd(data);
}); //结束录音
}
recrodEnd(data) {
let score = data.result.overall;
}
//----------------------Ready Go------------------------------------
showBegin() {
return new Promise((resolve, reject) => {
this.layout_begin.active = true;
let bottom = pg.view.find(this.layout_begin, 'layout_bottom/bottom');
let ready = pg.view.find(this.layout_begin, 'layout_middle/ready');
let go = pg.view.find(this.layout_begin, 'layout_middle/go');
// ready go
ready.y = 2000;
go.y = 2000;
this.aniBottomEnter().then(() => {
pg.hw.playAudio('readyGo', false, () => {
});
cc.tween(ready).to(1, { y: -20 }).to(0.2, { y: 0 }).delay(1).call(() => {
ready.active = false;
}).start();
cc.tween(go).delay(1).to(1, { y: -20 }).to(0.2, { y: 0 }).delay(0.5).call(() => {
go.active = false;
resolve('');
}).start();
})
});
}
hideBegin() {
this.layout_begin.active = false;
}
aniBottomEnter() {
return new Promise((resolve, reject) => {
let bottom = pg.view.find(this.layout_begin, 'layout_bottom/bottom');
const bottomOrgPos = cc.v2(0, -736);
bottom.active = true;
bottom.y = bottomOrgPos.y - bottom.height;
cc.tween(bottom).to(1, { y: bottomOrgPos.y }).start();
pg.hw.playAudio('please5speak', false, () => {
resolve('');
});
});
}
//----------------------Question------------------------------------
nextQuestion() {
// 游戏所需的初始化数据
this.currentId = 0 this.currentId = 0
this.time = this.data.options.length * 5 this.time = this.data.options.length * 5
console.log(this.time, '456') console.log(this.time, '456')
...@@ -68,12 +164,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -68,12 +164,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.countdownTime = "60.00" this.countdownTime = "60.00"
this.lengthProgress = 0 this.lengthProgress = 0
this.right = 0 this.right = 0
this.question()
}
question() {
//预加载第一题 //预加载第一题
this.firstOptions() this.firstOptions()
//题目数分配 //题目数分配
this.questionNuber() this.questionNuber()
} }
......
...@@ -674,7 +674,18 @@ let pg = { ...@@ -674,7 +674,18 @@ let pg = {
const id = cc.audioEngine.playEffect(audio.clip, loop); const id = cc.audioEngine.playEffect(audio.clip, loop);
resolve(id); resolve(id);
}) })
} },
playAudio(audioName, loop = false, cb) {
console.log("play audio->" + audioName);
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
const audioId = cc.audioEngine.playEffect(audio.clip, loop);
cc.audioEngine.setFinishCallback(audioId, () => {
cb && cb();
});
resolve(audioId);
})
},
}, },
signal: { signal: {
createSignal(): Signal { createSignal(): Signal {
......
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