Commit 94759aba authored by Tt's avatar Tt

fix(语音功能): 修复语音按钮点击和录音关闭逻辑问题

parent d6b97261
......@@ -1353,9 +1353,7 @@
"__id__": 25
},
"_enabled": true,
"_clip": {
"__uuid__": "8bbf063f-fd82-4e2c-b54d-0997b6004b2c"
},
"_clip": null,
"_volume": 1,
"_mute": false,
"_loop": false,
......@@ -1434,9 +1432,7 @@
"__id__": 27
},
"_enabled": true,
"_clip": {
"__uuid__": "36ab29df-0eff-40ad-bd25-daa3d15f55cd"
},
"_clip": null,
"_volume": 1,
"_mute": false,
"_loop": false,
......@@ -3758,7 +3754,7 @@
"__id__": 111
}
],
"_active": false,
"_active": true,
"_components": [
{
"__id__": 113
......@@ -4485,8 +4481,10 @@
"_fontSize": 130,
"_lineHeight": 130,
"_enableWrapText": false,
"_N$file": null,
"_isSystemFontUsed": true,
"_N$file": {
"__uuid__": "23f9661e-5c67-41a5-abdf-65a4b99ef31b"
},
"_isSystemFontUsed": false,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
......
......@@ -692,6 +692,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.renderProgressLabel(label_progress);
}
onTouchVoice() {
// 使用pg.ts的API播放音频
const currentData = this.currentTouchNode.data;
pg.audio.playAudioByUrl(currentData.audioUrl);
}
/**
* 处理语音按钮的显示和事件绑定
* @param btn_voice 语音按钮节点
......@@ -702,10 +707,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 如果数据中有audio,显示语音按钮
pg.view.visible(btn_voice, true);
// 绑定点击事件播放音频
pg.view.touchOn(btn_voice, () => {
// 使用pg.ts的API播放音频
pg.audio.playAudioByUrl(currentData.audioUrl);
}, this);
pg.view.touchOn(btn_voice, this.onTouchVoice, this);
} else {
// 没有音频则隐藏按钮
pg.view.visible(btn_voice, false);
......@@ -809,11 +811,26 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.stopVoiceAni();
}
}
onTouchSpeakClose() {
private onTouchSpeakCloseClosing: boolean;
async onTouchSpeakClose() {
if (this.onTouchSpeakCloseClosing) return;
this.onTouchSpeakCloseClosing = true;
// 检查是否在录音状态
const btn_stop = pg.view.find(this.layout_speak, 'btn_stop');
if (btn_stop && btn_stop.active) {
// 如果在录音状态,先执行停止录音操作
await this.onTouchRecordEnd()
}
this.onTouchSpeakCloseClosing = false;
this.showCard(false);
// 获取最后一次录音数据
const lastVoice = Game.getIns().player.getLastVoice();
if (lastVoice.questionId != this.touchData.id) {
this.onRecordFail();
return;
}
// 如果有录音数据,则使用其分数
if (lastVoice && lastVoice.result && lastVoice.questionId == this.touchData.id) {
const score = lastVoice.result.overall;
......@@ -935,90 +952,97 @@ export default class SceneComponent extends MyCocosSceneComponent {
* 停止倒计时,显示播放和重新录制按钮,结束录音
*/
private onTouchRecordEnd() {
// 使用更新后的showCard方法,传入'recorded'状态
this.showCard(true, 'recorded');
// 隐藏倒计时并设置一个很大的值防止倒计时继续
this.countDown = 999999;
// 重置录音开始时间
this.recordStartTime = 0;
let testData = {
"audioUrl": "https://staging-teach.cdn.ireadabc.com/a8ea7bb153a46941e6f28b7d0dda49f4.mp3",
"eof": 1,
"file": "/storage/emulated/0/Android/data/com.example.oxford/cache/shengtong/gradeVoice.mp3",
"result": {
"duration": "2.630",
"fluency": 84,
"integrity": 100,
"kernel_version": "3.7.1",
"overall": 68,
"pronunciation": 88,
"resource_version": "2.3.11",
"rhythm": 46,
"sentences": [
{
"beginIndex": 0,
"details": [
{
"charType": 0,
"end": 0,
"overall": 69,
"prominence": 0,
"start": 0,
"word": "day"
},
{
"charType": 0,
"end": 0,
"overall": 100,
"prominence": 0,
"start": 0,
"word": "day"
},
{
"charType": 0,
"end": 0,
"overall": 100,
"prominence": 0,
"start": 0,
"word": "up"
},
{
"charType": 0,
"end": 0,
"overall": 100,
"prominence": 0,
"start": 0,
"word": "day"
},
{
"charType": 0,
"end": 0,
"overall": 100,
"prominence": 0,
"start": 0,
"word": "up"
}
],
"end": 0,
"endIndex": 0,
"overall": 88,
"sentence": "day day up day up",
"start": 0
}
],
"speed": 170
},
"tokenId": "632be7a73327935c2b000005"
}
if (!courseware) return this.recrodEnd(testData)
// await pg.time.delay(5);
courseware && courseware.stopTest((data) => {
data = JSON.parse(data);
this.recrodEnd(data);
}); //结束录音
return new Promise(async (resolve, reject) => {
// 使用更新后的showCard方法,传入'recorded'状态
this.showCard(true, 'recorded');
// 隐藏倒计时并设置一个很大的值防止倒计时继续
this.countDown = 999999;
// 重置录音开始时间
this.recordStartTime = 0;
let testData = {
"audioUrl": "https://staging-teach.cdn.ireadabc.com/a8ea7bb153a46941e6f28b7d0dda49f4.mp3",
"eof": 1,
"file": "/storage/emulated/0/Android/data/com.example.oxford/cache/shengtong/gradeVoice.mp3",
"result": {
"duration": "2.630",
"fluency": 84,
"integrity": 100,
"kernel_version": "3.7.1",
"overall": 68,
"pronunciation": 88,
"resource_version": "2.3.11",
"rhythm": 46,
"sentences": [
{
"beginIndex": 0,
"details": [
{
"charType": 0,
"end": 0,
"overall": 69,
"prominence": 0,
"start": 0,
"word": "day"
},
{
"charType": 0,
"end": 0,
"overall": 100,
"prominence": 0,
"start": 0,
"word": "day"
},
{
"charType": 0,
"end": 0,
"overall": 100,
"prominence": 0,
"start": 0,
"word": "up"
},
{
"charType": 0,
"end": 0,
"overall": 100,
"prominence": 0,
"start": 0,
"word": "day"
},
{
"charType": 0,
"end": 0,
"overall": 100,
"prominence": 0,
"start": 0,
"word": "up"
}
],
"end": 0,
"endIndex": 0,
"overall": 88,
"sentence": "day day up day up",
"start": 0
}
],
"speed": 170
},
"tokenId": "632be7a73327935c2b000005"
}
if (!courseware) {
await this.recrodEnd(testData)
resolve(testData);
return;
}
// await pg.time.delay(5);
courseware && courseware.stopTest(async (data) => {
data = JSON.parse(data);
await this.recrodEnd(data);
resolve(data);
}); //结束录音
})
}
onTouchPlayRecord() {
const voice = Game.getIns().player.getLastVoice();
......@@ -1092,38 +1116,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.updateTips(null);
return;
} else {
// 单词不正确
if (this.tryData.some(td => td.id == this.touchData.id)) {
// 已经尝试过的题目,显示加油提示
this.updateTips(TIPS_STATE.COMEON);
if (this.tryAgain) {
// 第二次尝试后,无论结果如何都进入下一题
this.tryAgain = false;
// 如果有父节点(火苗节点),隐藏它
if (this.touchData && this.touchData.parent) {
this.touchData.parent.active = false;
}
await pg.time.delay(3);
this.showCard(false);
this.updateTips(null);
this.recordTouching = false;
this.onRecordFail();
return;
}
} else {
// 首次尝试失败,显示再试一次提示
this.updateTips(TIPS_STATE.TRYAGAIN);
this.tryData.push(this.touchData);
this.tryAgain = true;
// 将火苗节点重新添加到活跃列表中,以便再次尝试
if (this.touchData && this.touchData.parent && !this.activeNodes.includes(this.touchData.parent)) {
this.activeNodes.push(this.touchData.parent);
}
// 首次尝试失败,显示再试一次提示
this.updateTips(TIPS_STATE.TRYAGAIN);
this.tryData.push(this.touchData);
this.tryAgain = true;
// 将火苗节点重新添加到活跃列表中,以便再次尝试
if (this.touchData && this.touchData.parent && !this.activeNodes.includes(this.touchData.parent)) {
this.activeNodes.push(this.touchData.parent);
}
Game.getIns().player.addVoice(data);
}
// 延迟后隐藏提示
......
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