Commit 5c29605e authored by liujiangnan's avatar liujiangnan

feat: 自动录音

parent fda22160
...@@ -1983,7 +1983,7 @@ ...@@ -1983,7 +1983,7 @@
"__id__": 40 "__id__": 40
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 47 "__id__": 47
......
...@@ -29,7 +29,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -29,7 +29,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
_status = { _status = {
currentTipAudioId: null,
canClick: true, canClick: true,
currentSelectedCard: null, currentSelectedCard: null,
tryAgainFlg: false, tryAgainFlg: false,
...@@ -177,9 +176,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -177,9 +176,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (cc.find('Canvas/mask').active) { if (cc.find('Canvas/mask').active) {
return; return;
} }
this.playLocalAudio('tips', (id) => {
this._status.currentTipAudioId = id;
});
await this.userSpeak(); await this.userSpeak();
await this.hideCards(card, this._status.currentSelectedCard); await this.hideCards(card, this._status.currentSelectedCard);
this.checkQuestionOver(); this.checkQuestionOver();
...@@ -326,7 +322,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -326,7 +322,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
mask.active = false; mask.active = false;
this._status = { this._status = {
canClick: true, canClick: true,
currentTipAudioId: null,
currentSelectedCard: null, currentSelectedCard: null,
tryAgainFlg: false, tryAgainFlg: false,
starLength: 0, starLength: 0,
...@@ -370,120 +365,39 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -370,120 +365,39 @@ export default class SceneComponent extends MyCocosSceneComponent {
}); });
} }
userSpeak() { async userSpeak() {
const word = this._status.currentSelectedCard['word']; const word = this._status.currentSelectedCard['word'];
return new Promise((resolve, reject) => { const baseSpeaker = cc.find('Canvas/bg/speaker');
console.log('userSpeak: ' + word); baseSpeaker.active = true;
const baseSpeaker = cc.find('Canvas/bg/speaker'); const bg = baseSpeaker.getChildByName('bg');
baseSpeaker.active = true; cc.tween(bg)
const bg = baseSpeaker.getChildByName('bg'); .set({ opacity: 0 })
cc.tween(bg) .to(0.5, { opacity: 100 })
.set({ opacity: 0 }) .start();
.to(0.5, { opacity: 100 }) const speaker = baseSpeaker.getChildByName('speaker');
.start(); asyncPlayDragonBoneAnimation(speaker, 'newAnimation', -1);
if (window['courseware']) {
const speaker = baseSpeaker.getChildByName('speaker'); window['courseware'].startTest(word);
this._status.isRecording = true;
const btnStart = baseSpeaker.getChildByName('btnStart'); } else {
const btnStop = baseSpeaker.getChildByName('btnStop'); console.log('word = ' + word);
}
btnStart.active = true; await asyncDelay(5);
const dragonDisplay = speaker.getComponent(dragonBones.ArmatureDisplay);
btnStart['canClick'] = true; dragonDisplay.playAnimation('newAnimation', -1);
btnStart.off('click'); dragonDisplay.timeScale = 0.00000001;
btnStart.on('click', () => { let score = await this.stopTest();
if (typeof (this._status.currentTipAudioId) == 'number') { this._status.isRecording = false;
cc.audioEngine.stop(this._status.currentTipAudioId);
} if (score >= 60) {
const word = this._status.currentSelectedCard['word']; await this.showGoodjob();
if (!btnStart['canClick']) { baseSpeaker.active = false;
return; this._status.tryAgainFlg = false;
} } else {
this.playLocalAudio('btn'); this.playLocalAudio('try_again');
btnStart['canClick'] = false; await this.showTryAgain();
asyncPlayDragonBoneAnimation(speaker, 'newAnimation', -1); }
cc.tween(btnStart)
.to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 })
.call(() => {
btnStart.active = false;
btnStop.active = true;
btnStart['canClick'] = true;
})
.start();
if (window['courseware']) {
window['courseware'].startTest(word);
this._status.isRecording = true;
} else {
console.log('word = ' + word);
}
});
btnStop['canClick'] = true;
btnStop.off('click');
btnStop.on('click', () => {
if (!btnStop['canClick']) {
return;
}
this.playLocalAudio('btn');
btnStop['canClick'] = false;
cc.tween(btnStop)
.to(0.1, { scale: 1.1 })
.to(0.1, { scale: 1.0 })
.call(async () => {
btnStop['canClick'] = true;
btnStop.active = false;
const dragonDisplay = speaker.getComponent(dragonBones.ArmatureDisplay);
dragonDisplay.playAnimation('newAnimation', -1);
dragonDisplay.timeScale = 0.00000001;
let score = await this.stopTest();
this._status.isRecording = false;
if (score >= 60) {
await this.showGoodjob();
baseSpeaker.active = false;
this._status.tryAgainFlg = false;
resolve(null);
} else {
this.playLocalAudio('try_again');
const tryAgain = cc.find('Canvas/bg/speaker/tryAgain');
await this.showTryAgain();
if (!this._status.tryAgainFlg) {
this._status.tryAgainFlg = true;
tryAgain.active = false;
btnStart.active = true;
} else {
const skip = baseSpeaker.getChildByName('skip');
const doItAgain = baseSpeaker.getChildByName('doItAgain');
skip.active = true;
doItAgain.active = true;
skip.once('click', () => {
this.playLocalAudio('btn');
baseSpeaker.active = false;
tryAgain.active = false;
skip.active = false;
doItAgain.active = false;
this._status.tryAgainFlg = false;
console.log('喵喵喵');
resolve(null);
});
doItAgain.once('click', () => {
this.playLocalAudio('btn');
tryAgain.active = false;
btnStart.active = true;
skip.active = false;
doItAgain.active = false;
});
}
btnStop.active = false;
}
})
.start();
});
});
} }
stopTest() { stopTest() {
...@@ -561,7 +475,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -561,7 +475,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
this._status = { this._status = {
canClick: true, canClick: true,
currentSelectedCard: null, currentSelectedCard: null,
currentTipAudioId: null,
tryAgainFlg: false, tryAgainFlg: false,
starLength: 0, starLength: 0,
getStarNumber: 0, getStarNumber: 0,
......
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