|
@@ -1,4 +1,7 @@
|
|
import httpRequestApi from '../../utils/APIClient';
|
|
import httpRequestApi from '../../utils/APIClient';
|
|
|
|
+const aiengine = require('../../utils/ChivoxAiEngine')
|
|
|
|
+const sha1 = require('../../utils/sha1');
|
|
|
|
+
|
|
import {
|
|
import {
|
|
formatDate
|
|
formatDate
|
|
} from '../../utils/util';
|
|
} from '../../utils/util';
|
|
@@ -64,7 +67,6 @@ Page({
|
|
exampleId: res.data.data.userRead.exampleId,
|
|
exampleId: res.data.data.userRead.exampleId,
|
|
summary: res.data.data.userRead.summary,
|
|
summary: res.data.data.userRead.summary,
|
|
coverImg: res.data.data.userRead.coverImg,
|
|
coverImg: res.data.data.userRead.coverImg,
|
|
- shareImg: res.data.data.userRead.shareImg,
|
|
|
|
})
|
|
})
|
|
this.getReadInfo(id)
|
|
this.getReadInfo(id)
|
|
httpRequestApi.userIntoPage('pages/reading/reading', '朗读页面').success((res) => {
|
|
httpRequestApi.userIntoPage('pages/reading/reading', '朗读页面').success((res) => {
|
|
@@ -74,14 +76,13 @@ Page({
|
|
},
|
|
},
|
|
onHide: function () {
|
|
onHide: function () {
|
|
console.log('onhide')
|
|
console.log('onhide')
|
|
- if (this.data.audioPlaying) {
|
|
|
|
- console.log('返回时状态', this.data.audioPlaying)
|
|
|
|
- this.ss.stopPlay();
|
|
|
|
- }
|
|
|
|
if (this.data.btnImgFlag) {
|
|
if (this.data.btnImgFlag) {
|
|
- this.ss.stopRecord();
|
|
|
|
|
|
+ this.recorderManager.stop();
|
|
}
|
|
}
|
|
- this.ss.destroyEngine();
|
|
|
|
|
|
+ if (this.innerAudioContext) {
|
|
|
|
+ this.innerAudioContext.stop();
|
|
|
|
+ }
|
|
|
|
+ // this.ss.destroyEngine();
|
|
this.setData({
|
|
this.setData({
|
|
recordFlag: 0
|
|
recordFlag: 0
|
|
})
|
|
})
|
|
@@ -89,14 +90,12 @@ Page({
|
|
},
|
|
},
|
|
onUnload: function () {
|
|
onUnload: function () {
|
|
console.log('onUnload')
|
|
console.log('onUnload')
|
|
- if (this.data.audioPlaying) {
|
|
|
|
- console.log('销毁时状态', this.data.audioPlaying)
|
|
|
|
- this.ss.stopPlay();
|
|
|
|
- }
|
|
|
|
if (this.data.btnImgFlag) {
|
|
if (this.data.btnImgFlag) {
|
|
- this.ss.stopRecord();
|
|
|
|
|
|
+ this.recorderManager.stop();
|
|
|
|
+ }
|
|
|
|
+ if (this.innerAudioContext) {
|
|
|
|
+ this.innerAudioContext.stop();
|
|
}
|
|
}
|
|
- this.ss.destroyEngine();
|
|
|
|
},
|
|
},
|
|
onShow: function () {
|
|
onShow: function () {
|
|
this.videoCtx = wx.createVideoContext('myVideo', this);
|
|
this.videoCtx = wx.createVideoContext('myVideo', this);
|
|
@@ -114,7 +113,75 @@ Page({
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
- this.ss = new data.ssEngine(obj);
|
|
|
|
|
|
+ // this.ss = new data.ssEngine(obj);
|
|
|
|
+ this.recorderManager = wx.getRecorderManager();
|
|
|
|
+ this.recorderManager.onStop((res) => {
|
|
|
|
+ // wx.showToast({
|
|
|
|
+ // title: 'onStop',
|
|
|
|
+ // icon: 'fail',
|
|
|
|
+ // duration: 500
|
|
|
|
+ // })
|
|
|
|
+ this.videoCtx.seek(0);
|
|
|
|
+ this.videoCtx.stop();
|
|
|
|
+ console.log('recorder stop', res)
|
|
|
|
+ const recordFile = res.tempFilePath;
|
|
|
|
+ this.setData({
|
|
|
|
+ recordFlag: 0,
|
|
|
|
+ recordSource: recordFile,
|
|
|
|
+ btnFlag: true,
|
|
|
|
+ btnImgFlag: false
|
|
|
|
+ })
|
|
|
|
+ this.wsEngine.stop({
|
|
|
|
+ success: () => {
|
|
|
|
+ console.log('====== wsEngine stop success ======');
|
|
|
|
+ wx.showLoading({
|
|
|
|
+ title: '作品评测中',
|
|
|
|
+ mask: true
|
|
|
|
+ })
|
|
|
|
+ // TODO: add your code here
|
|
|
|
+ },
|
|
|
|
+ fail: (res) => {
|
|
|
|
+ console.log("====== wsEngine stop fail ======");
|
|
|
|
+ console.log(JSON.stringify(res)); //请关注res.errId, res.error
|
|
|
|
+ // TODO: add your code here
|
|
|
|
+ },
|
|
|
|
+ complete: () => {
|
|
|
|
+ // TODO: add your code here
|
|
|
|
+ // clearInterval(recordTimeInterval);
|
|
|
|
+ console.log("====== wsEngine stop complete ======");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+ this.recorderManager.onStart(() => {
|
|
|
|
+ // this.saveVideo();
|
|
|
|
+ this.setData({
|
|
|
|
+ btnImgFlag: true,
|
|
|
|
+ btnFlag: false
|
|
|
|
+ })
|
|
|
|
+ console.log('recorder start')
|
|
|
|
+ });
|
|
|
|
+ //监听已录制完指定帧大小的文件事件。如果设置了 frameSize,则会回调此事件。
|
|
|
|
+ this.recorderManager.onFrameRecorded((res) => {
|
|
|
|
+ const {
|
|
|
|
+ frameBuffer
|
|
|
|
+ } = res
|
|
|
|
+ console.log('frameBuffer.byteLength', frameBuffer.byteLength)
|
|
|
|
+ //TODO 调用feed接口传递音频片给驰声评测引擎
|
|
|
|
+ this.wsEngine.feed({
|
|
|
|
+ data: frameBuffer, // frameBuffer为微信录音机回调的音频数据
|
|
|
|
+ success: () => {
|
|
|
|
+ // feed 成功
|
|
|
|
+ console.log('feed success.')
|
|
|
|
+ },
|
|
|
|
+ fail: (res) => {
|
|
|
|
+ // feed 失败, 请关注res.errId, res.error
|
|
|
|
+ console.log('feed fail:', JSON.stringify(res))
|
|
|
|
+ },
|
|
|
|
+ complete: () => {
|
|
|
|
+ // feed 完成
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
|
|
},
|
|
},
|
|
ssRecorderCallback: function (type, data) {
|
|
ssRecorderCallback: function (type, data) {
|
|
@@ -159,7 +226,7 @@ Page({
|
|
playingVideoEnd: function () {
|
|
playingVideoEnd: function () {
|
|
console.log('playingVideoEnd')
|
|
console.log('playingVideoEnd')
|
|
|
|
|
|
- this.ss.stopPlay();;
|
|
|
|
|
|
+ // this.ss.stopPlay();
|
|
},
|
|
},
|
|
/***
|
|
/***
|
|
* recordFlag:
|
|
* recordFlag:
|
|
@@ -168,27 +235,26 @@ Page({
|
|
* 2 录音结束
|
|
* 2 录音结束
|
|
***/
|
|
***/
|
|
audioRecord: function () {
|
|
audioRecord: function () {
|
|
|
|
+
|
|
console.log('111111111111111recordFlag', this.data.recordFlag)
|
|
console.log('111111111111111recordFlag', this.data.recordFlag)
|
|
|
|
+ if (this.recorderManager) {
|
|
|
|
+ this.recorderManager.stop();
|
|
|
|
+ }
|
|
|
|
+ if (this.innerAudioContext) {
|
|
|
|
+ this.innerAudioContext.stop();
|
|
|
|
+ }
|
|
if (this.data.recordFlag === 0) {
|
|
if (this.data.recordFlag === 0) {
|
|
- // this.recordStart();
|
|
|
|
- // this.saveVideo();
|
|
|
|
- console.log('2222222222是否有视频', this.videoCtx)
|
|
|
|
- if (this.videoCtx) {
|
|
|
|
- console.log('3333333333333停止视频停止视频停止视频')
|
|
|
|
- this.videoCtx.stop();
|
|
|
|
- // this.videoCtx.seek(0);
|
|
|
|
- }
|
|
|
|
- if (this.data.audioPlaying) {
|
|
|
|
- this.ss.stopPlay();
|
|
|
|
- }
|
|
|
|
- // if (this.recorderManager) {
|
|
|
|
- // this.recorderManager.stop();
|
|
|
|
- // }
|
|
|
|
- // if (this.innerAudioContext) {
|
|
|
|
- // this.innerAudioContext.stop();
|
|
|
|
- // }
|
|
|
|
- this.getMicAuth()
|
|
|
|
- // this.videoComplete();
|
|
|
|
|
|
+ this.wsEngine = aiengine.createWsEngine({});
|
|
|
|
+ this.wsEngine.onResult(res => {
|
|
|
|
+ wx.hideLoading();
|
|
|
|
+ this.getRecordScore(res)
|
|
|
|
+ })
|
|
|
|
+ this.wsEngine.onErrorResult(res => {
|
|
|
|
+ wx.hideLoading();
|
|
|
|
+ console.log('驰声createWsEngine失败', res);
|
|
|
|
+ })
|
|
|
|
+ this.videoComplete();
|
|
|
|
+ // this.getMicAuth()
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// 录音结束后
|
|
// 录音结束后
|
|
@@ -219,11 +285,56 @@ Page({
|
|
format: 'mp3',
|
|
format: 'mp3',
|
|
frameSize: 50
|
|
frameSize: 50
|
|
}
|
|
}
|
|
- this.ss.startRecord({
|
|
|
|
- coreType: 'cn.sent.score', //测评题型
|
|
|
|
- evalTime: 300000, //测评的录音时间,时间到自动停止测评
|
|
|
|
- refText: this.data.readingText, //测评文本
|
|
|
|
- warrantId: 'c11163aa6c834a028da4a4b30955be96', //鉴权id
|
|
|
|
|
|
+ this.recorderManager.start(options);
|
|
|
|
+ // this.ss.startRecord({
|
|
|
|
+ // coreType: 'cn.sent.score', //测评题型
|
|
|
|
+ // evalTime: 300000, //测评的录音时间,时间到自动停止测评
|
|
|
|
+ // refText: this.data.readingText, //测评文本
|
|
|
|
+ // warrantId: 'c11163aa6c834a028da4a4b30955be96', //鉴权id
|
|
|
|
+ // })
|
|
|
|
+ // 驰声测评
|
|
|
|
+ let timeStamp = new Date().getTime()
|
|
|
|
+ let sig = sha1(`16075689600000da${timeStamp}caa8e60da6042731c230fe431ac9c7fd`)
|
|
|
|
+ console.log('加密串', sig)
|
|
|
|
+ // return
|
|
|
|
+ let app = {
|
|
|
|
+ applicationId: '16075689600000da',
|
|
|
|
+ sig, //签名字符串 通过签名算法alg(appkey + timestamp + secretKey)生成
|
|
|
|
+ alg: 'sha1',
|
|
|
|
+ timestamp: timeStamp + '',
|
|
|
|
+ userId: wx.getStorageSync('uid')
|
|
|
|
+ }
|
|
|
|
+ console.log('app数据', app)
|
|
|
|
+ let lessonText = this.data.readingText;
|
|
|
|
+ console.log('课文课文课文', lessonText)
|
|
|
|
+ this.wsEngine.start({
|
|
|
|
+ app,
|
|
|
|
+ request: {
|
|
|
|
+ coreType: "cn.pred.raw",
|
|
|
|
+ refText: lessonText,
|
|
|
|
+ rank: 100,
|
|
|
|
+ attachAudioUrl: 1,
|
|
|
|
+ result: {
|
|
|
|
+ details: {
|
|
|
|
+ gop_adjust: 1
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ audio: {
|
|
|
|
+ audioType: "mp3",
|
|
|
|
+ channel: 1,
|
|
|
|
+ sampleBytes: 2,
|
|
|
|
+ sampleRate: 16000
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ // 调用成功
|
|
|
|
+ console.log('驰声start成功', res)
|
|
|
|
+ },
|
|
|
|
+ fail: (res) => {
|
|
|
|
+ // start失败,请关注res.errId, res.error
|
|
|
|
+ console.log('驰声start失败', res)
|
|
|
|
+
|
|
|
|
+ }
|
|
})
|
|
})
|
|
},
|
|
},
|
|
getMicAuth() {
|
|
getMicAuth() {
|
|
@@ -231,9 +342,7 @@ Page({
|
|
wx.getSetting({
|
|
wx.getSetting({
|
|
success(res) {
|
|
success(res) {
|
|
if (res.authSetting['scope.record']) {
|
|
if (res.authSetting['scope.record']) {
|
|
- // that.videoComplete();
|
|
|
|
_this.videoComplete();
|
|
_this.videoComplete();
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
_this.getMicSetAuth();
|
|
_this.getMicSetAuth();
|
|
return;
|
|
return;
|
|
@@ -276,18 +385,20 @@ Page({
|
|
this.setData({
|
|
this.setData({
|
|
muted: false
|
|
muted: false
|
|
})
|
|
})
|
|
- this.ss.stopRecord();
|
|
|
|
|
|
+ // this.ss.stopRecord();
|
|
console.log('录音结束')
|
|
console.log('录音结束')
|
|
|
|
+ this.recorderManager.stop();
|
|
wx.hideLoading()
|
|
wx.hideLoading()
|
|
},
|
|
},
|
|
// 获取测评结果
|
|
// 获取测评结果
|
|
getRecordScore(res) {
|
|
getRecordScore(res) {
|
|
- console.log('测评结果', res)
|
|
|
|
|
|
+ console.log('测评结果', JSON.stringify(res))
|
|
const result = res.result;
|
|
const result = res.result;
|
|
const overall = result.overall; // 总分
|
|
const overall = result.overall; // 总分
|
|
const integrity = result.integrity; //完成度
|
|
const integrity = result.integrity; //完成度
|
|
const tone = result.tone; // 语调声调
|
|
const tone = result.tone; // 语调声调
|
|
- const accuracy = result.accuracy; // 发音分
|
|
|
|
|
|
+ // const accuracy = result.accuracy; // 准确度 发音分
|
|
|
|
+ const accuracy = result.overall; // 准确度 发音分
|
|
const fluency = result.fluency.overall; //流利度
|
|
const fluency = result.fluency.overall; //流利度
|
|
let starArray = [];
|
|
let starArray = [];
|
|
let score = overall / 20;
|
|
let score = overall / 20;
|
|
@@ -323,14 +434,25 @@ Page({
|
|
// 播放录音
|
|
// 播放录音
|
|
audioPlay: function () {
|
|
audioPlay: function () {
|
|
/* 用了先声智能以后录音播放由先声只能接管 */
|
|
/* 用了先声智能以后录音播放由先声只能接管 */
|
|
|
|
+ if (this.innerAudioContext) {
|
|
|
|
+ this.innerAudioContext.stop();
|
|
|
|
+ this.videoCtx.stop();
|
|
|
|
+ }
|
|
|
|
+ this.innerAudioContext = wx.createInnerAudioContext();
|
|
|
|
+ this.innerAudioContext.src = this.data.recordSource; // 这里可以是录音的临时路径
|
|
this.setData({
|
|
this.setData({
|
|
- videoUrl: this.data.videoUrl
|
|
|
|
|
|
+ videoUrl: this.data.videoUrl,
|
|
|
|
+ muted: true
|
|
})
|
|
})
|
|
- if (this.data.audioPath) {
|
|
|
|
|
|
+ console.log(this.innerAudioContext.src);
|
|
|
|
+ this.videoCtx.play();
|
|
|
|
+ this.innerAudioContext.play();
|
|
|
|
+
|
|
|
|
+ /* if (this.data.audioPath) {
|
|
if (this.data.audioPlaying) {
|
|
if (this.data.audioPlaying) {
|
|
- this.ss.stopPlay();
|
|
|
|
|
|
+ // this.ss.stopPlay();
|
|
}
|
|
}
|
|
- this.ss.startPlay(this.data.audioPath);
|
|
|
|
|
|
+ // this.ss.startPlay(this.data.audioPath);
|
|
this.videoCtx.stop();
|
|
this.videoCtx.stop();
|
|
this.videoCtx.play();
|
|
this.videoCtx.play();
|
|
|
|
|
|
@@ -351,7 +473,7 @@ Page({
|
|
audioPath,
|
|
audioPath,
|
|
audioPlaying: true
|
|
audioPlaying: true
|
|
})
|
|
})
|
|
- this.ss.startPlay(audioPath);
|
|
|
|
|
|
+ // this.ss.startPlay(audioPath);
|
|
// this.videoCtx.seek(0);
|
|
// this.videoCtx.seek(0);
|
|
this.videoCtx.stop();
|
|
this.videoCtx.stop();
|
|
console.log('播放器归0')
|
|
console.log('播放器归0')
|
|
@@ -359,22 +481,22 @@ Page({
|
|
console.log('播放器播放')
|
|
console.log('播放器播放')
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- }
|
|
|
|
|
|
+ } */
|
|
},
|
|
},
|
|
|
|
|
|
videoComplete: function () {
|
|
videoComplete: function () {
|
|
- // let videoUrl = 'http://efunimgs.ai160.com/ott/test/002tPr2Xlx07oP7B4ro40104120022hP0k010.mp4';
|
|
|
|
this.setData({
|
|
this.setData({
|
|
recordFlag: 1,
|
|
recordFlag: 1,
|
|
videoUrl: this.data.originVideo,
|
|
videoUrl: this.data.originVideo,
|
|
centerBtn: false,
|
|
centerBtn: false,
|
|
playBtn: false,
|
|
playBtn: false,
|
|
isVideoListShow: false,
|
|
isVideoListShow: false,
|
|
- muted: true,
|
|
|
|
|
|
+ muted: false,
|
|
ifTextShow: true,
|
|
ifTextShow: true,
|
|
ifScoreShow: false
|
|
ifScoreShow: false
|
|
|
|
|
|
}, () => {
|
|
}, () => {
|
|
|
|
+ console.log('播放视频播放视频播放视频')
|
|
this.videoCtx.play();
|
|
this.videoCtx.play();
|
|
this.recordStart();
|
|
this.recordStart();
|
|
})
|
|
})
|
|
@@ -385,7 +507,7 @@ Page({
|
|
this.videoCtx.stop();
|
|
this.videoCtx.stop();
|
|
}
|
|
}
|
|
if (this.data.audioPlaying) {
|
|
if (this.data.audioPlaying) {
|
|
- this.ss.stopPlay();
|
|
|
|
|
|
+ // this.ss.stopPlay();
|
|
this.setData({
|
|
this.setData({
|
|
audioPlaying: false
|
|
audioPlaying: false
|
|
})
|
|
})
|
|
@@ -394,31 +516,24 @@ Page({
|
|
title: '作品上传中',
|
|
title: '作品上传中',
|
|
mask: true
|
|
mask: true
|
|
})
|
|
})
|
|
-
|
|
|
|
- if (this.data.audioPath) {
|
|
|
|
- this.shareWorks(this.data.audioPath)
|
|
|
|
- } else {
|
|
|
|
- const recordSource = this.data.recordSource;
|
|
|
|
- wx.uploadFile({
|
|
|
|
- url: 'https://reader-api.ai160.com/file/upload',
|
|
|
|
- filePath: recordSource,
|
|
|
|
- name: '朗读录音',
|
|
|
|
- header: {
|
|
|
|
- uid: wx.getStorageSync('uid')
|
|
|
|
- },
|
|
|
|
- success: (res) => {
|
|
|
|
- const formateRes = JSON.parse(res.data);
|
|
|
|
- let audioPath = formateRes.data;
|
|
|
|
- this.shareWorks(audioPath);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ const recordSource = this.data.recordSource;
|
|
|
|
+ wx.uploadFile({
|
|
|
|
+ url: 'https://reader-api.ai160.com/file/upload',
|
|
|
|
+ // url: 'https://reader-test.efunbox.cn/file/upload',
|
|
|
|
+ filePath: recordSource,
|
|
|
|
+ name: '朗读录音',
|
|
|
|
+ header: {
|
|
|
|
+ uid: wx.getStorageSync('uid')
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ const formateRes = JSON.parse(res.data);
|
|
|
|
+ let audioPath = formateRes.data;
|
|
|
|
+ console.log('音频上传成功')
|
|
|
|
+ this.shareWorks(audioPath);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
},
|
|
},
|
|
shareWorks: function (audio) {
|
|
shareWorks: function (audio) {
|
|
-
|
|
|
|
const data = {
|
|
const data = {
|
|
"lessonId": this.data.id,
|
|
"lessonId": this.data.id,
|
|
"originVideo": this.data.videoUrl,
|
|
"originVideo": this.data.videoUrl,
|
|
@@ -429,8 +544,7 @@ Page({
|
|
"productId": this.data.productId,
|
|
"productId": this.data.productId,
|
|
"grade": this.data.grade,
|
|
"grade": this.data.grade,
|
|
"exampleId": this.data.exampleId,
|
|
"exampleId": this.data.exampleId,
|
|
- "coverImg": this.data.coverImg,
|
|
|
|
- "shareImg": this.data.shareImg,
|
|
|
|
|
|
+ "coverImg": this.data.coverImg
|
|
};
|
|
};
|
|
httpRequestApi.postWork(data).success(res => {
|
|
httpRequestApi.postWork(data).success(res => {
|
|
wx.hideLoading({
|
|
wx.hideLoading({
|
|
@@ -513,7 +627,6 @@ Page({
|
|
temp.coverImg = item.userRead.coverImg;
|
|
temp.coverImg = item.userRead.coverImg;
|
|
temp.videoShow = false;
|
|
temp.videoShow = false;
|
|
temp.grade = item.userRead.grade;
|
|
temp.grade = item.userRead.grade;
|
|
- temp.shareImg = item.userRead.shareImg;
|
|
|
|
temp.type = item.userRead.type;
|
|
temp.type = item.userRead.type;
|
|
|
|
|
|
// recommendWorks.push(temp);
|
|
// recommendWorks.push(temp);
|
|
@@ -572,7 +685,7 @@ Page({
|
|
return {
|
|
return {
|
|
title: '请欣赏我的课文朗读作品,点赞+评论。',
|
|
title: '请欣赏我的课文朗读作品,点赞+评论。',
|
|
path: `/pages/index/index?readId=${this.data.shareId}`,
|
|
path: `/pages/index/index?readId=${this.data.shareId}`,
|
|
- imageUrl: this.data.shareImg
|
|
|
|
|
|
+ imageUrl: '../../static/index/share_icon.png'
|
|
|
|
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -591,7 +704,7 @@ Page({
|
|
this.setData({
|
|
this.setData({
|
|
shareTitle: e.detail.currentTarget.dataset.title,
|
|
shareTitle: e.detail.currentTarget.dataset.title,
|
|
shareId: e.detail.currentTarget.dataset.id,
|
|
shareId: e.detail.currentTarget.dataset.id,
|
|
- shareImg: e.detail.currentTarget.dataset.shareimg
|
|
|
|
|
|
+ shareImg: e.detail.currentTarget.dataset.img
|
|
})
|
|
})
|
|
},
|
|
},
|
|
onPlay: function (e) {
|
|
onPlay: function (e) {
|