|
@@ -26,7 +26,16 @@ Page({
|
|
|
pageNo: 1,
|
|
|
nextMargin: getApp().globalData.nextMargin,
|
|
|
lowerThresHold: 100,
|
|
|
- isVideoListShow: true
|
|
|
+ isVideoListShow: true,
|
|
|
+ overall: '', // 评测总分
|
|
|
+ integrity: '', //完成度
|
|
|
+ tone: '', //语调声调
|
|
|
+ fluency: '', //流利度
|
|
|
+ accuracy: '', // 正确分,发音分
|
|
|
+ star: [0, 0, 0, 0, 0],
|
|
|
+ ifTextShow: true,
|
|
|
+ ifScoreDialogShow: false,
|
|
|
+ ifScoreShow: false
|
|
|
},
|
|
|
onLoad: function (option) {
|
|
|
console.log(option);
|
|
@@ -56,97 +65,13 @@ Page({
|
|
|
|
|
|
})
|
|
|
})
|
|
|
- this.recorderManager = wx.getRecorderManager();
|
|
|
-
|
|
|
-
|
|
|
- // 监听录音部分
|
|
|
- // 录音开始
|
|
|
- this.recorderManager.onStart(() => {
|
|
|
- // this.saveVideo();
|
|
|
- this.setData({
|
|
|
- btnImgFlag: true,
|
|
|
- btnFlag: false
|
|
|
- })
|
|
|
- console.log('recorder start')
|
|
|
- })
|
|
|
- // this.recorderManager.onPause(() => {
|
|
|
- // wx.showToast({
|
|
|
- // title: '录音被暂停',
|
|
|
- // icon: 'fail',
|
|
|
- // duration: 500
|
|
|
- // })
|
|
|
- // })
|
|
|
- // this.recorderManager.onInterruptionBegin(() => {
|
|
|
- // wx.showToast({
|
|
|
- // title: '录音被应用中断开始',
|
|
|
- // icon: 'fail',
|
|
|
- // duration: 500
|
|
|
- // })
|
|
|
- // })
|
|
|
- // this.recorderManager.onInterruptionEnd(() => {
|
|
|
- // wx.showToast({
|
|
|
- // title: '录音中断结束',
|
|
|
- // icon: 'fail',
|
|
|
- // duration: 500
|
|
|
- // })
|
|
|
- // })
|
|
|
- let dialogFlag = true;
|
|
|
- this.recorderManager.onError(() => {
|
|
|
- wx.getSetting({
|
|
|
- success(res) {
|
|
|
- if (!res.authSetting['scope.record'] && dialogFlag) {
|
|
|
- wx.showModal({
|
|
|
- title: '录音前请打开麦克风权限',
|
|
|
- content: '点击右上角浮点...,选择:设置-麦克风,点击/打开。',
|
|
|
- confirmText: '我知道了',
|
|
|
- showCancel: false,
|
|
|
- success(res) {
|
|
|
- console.log('用户点击确定')
|
|
|
- // dialogFlag = false;
|
|
|
- }
|
|
|
- })
|
|
|
- dialogFlag = false;
|
|
|
- setTimeout(() => {
|
|
|
- dialogFlag = true;
|
|
|
- }, 1000)
|
|
|
- }
|
|
|
- // else {
|
|
|
- // wx.showToast({
|
|
|
- // title: 'onError',
|
|
|
- // icon: 'fail',
|
|
|
- // duration: 500
|
|
|
- // })
|
|
|
- // }
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- // 录音结束
|
|
|
- this.recorderManager.onStop((res) => {
|
|
|
- // wx.showToast({
|
|
|
- // title: 'onStop',
|
|
|
- // icon: 'fail',
|
|
|
- // duration: 500
|
|
|
- // })
|
|
|
- this.videoCtx.stop();
|
|
|
- console.log('recorder stop', res)
|
|
|
- const recordFile = res.tempFilePath;
|
|
|
- this.setData({
|
|
|
- recordFlag: 0,
|
|
|
- recordSource: recordFile,
|
|
|
- btnFlag: true,
|
|
|
- btnImgFlag: false
|
|
|
- })
|
|
|
- })
|
|
|
},
|
|
|
onHide: function () {
|
|
|
console.log('onhide')
|
|
|
if (this.data.btnImgFlag) {
|
|
|
- this.recorderManager.stop();
|
|
|
- }
|
|
|
-
|
|
|
- if (this.innerAudioContext) {
|
|
|
- this.innerAudioContext.stop();
|
|
|
+ this.ss.stopRecord();
|
|
|
}
|
|
|
+ this.ss.destroyEngine();
|
|
|
this.setData({
|
|
|
recordFlag: 0
|
|
|
})
|
|
@@ -154,12 +79,10 @@ Page({
|
|
|
},
|
|
|
onUnload: function () {
|
|
|
console.log('onUnload')
|
|
|
- if (this.recorderManager) {
|
|
|
- this.recorderManager.stop();
|
|
|
- }
|
|
|
- if (this.innerAudioContext) {
|
|
|
- this.innerAudioContext.stop();
|
|
|
+ if (this.data.btnImgFlag) {
|
|
|
+ this.ss.stopRecord();
|
|
|
}
|
|
|
+ this.ss.destroyEngine();
|
|
|
},
|
|
|
onShow: function () {
|
|
|
this.setData({
|
|
@@ -169,16 +92,45 @@ Page({
|
|
|
},
|
|
|
})
|
|
|
this.videoCtx = wx.createVideoContext('myVideo', this);
|
|
|
+ let data = requirePlugin("myPlugin");
|
|
|
+ const obj = {
|
|
|
+ appid: 'a415',
|
|
|
+ userid: wx.getStorageSync('uid'),
|
|
|
+ getEvalMessage: (res) => {
|
|
|
+ this.getRecordScore(res)
|
|
|
+ // console.log('评测结果',res)
|
|
|
+ },
|
|
|
+ recorderCallback: (type, data) => {
|
|
|
+ // 录音测评监控回调
|
|
|
+ this.ssRecorderCallback(type, data)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ this.ss = new data.ssEngine(obj);
|
|
|
|
|
|
},
|
|
|
- // 视频缓冲
|
|
|
- // videoWaiting: function () {
|
|
|
- // this.recorderManager.pause();
|
|
|
- // },
|
|
|
- // //视频播放
|
|
|
- // videoPlay: function () {
|
|
|
- // this.recorderManager.resume();
|
|
|
- // },
|
|
|
+ ssRecorderCallback: function (type, data) {
|
|
|
+ console.log('录音测评监控回调', type)
|
|
|
+ console.log('录音测评监控回调', data)
|
|
|
+ /* 录音开始 */
|
|
|
+ if (type === 'onStart') {
|
|
|
+ this.setData({
|
|
|
+ btnImgFlag: true,
|
|
|
+ btnFlag: false
|
|
|
+ })
|
|
|
+ console.log('recorder start')
|
|
|
+ }
|
|
|
+ if (type === 'onStop') {
|
|
|
+ this.videoCtx.stop();
|
|
|
+ this.setData({
|
|
|
+ recordFlag: 0,
|
|
|
+ recordSource: data.tempFilePath,
|
|
|
+ btnFlag: true,
|
|
|
+ btnImgFlag: false
|
|
|
+ })
|
|
|
+ console.log('recorder start')
|
|
|
+ }
|
|
|
+ },
|
|
|
// 录音中视频播放结束 (控制录音同时结束)
|
|
|
recordingVideoEnd: function () {
|
|
|
console.log(this.data.videoCtr)
|
|
@@ -198,7 +150,8 @@ Page({
|
|
|
// 播放中视频播放结束 (控制录音同时结束)
|
|
|
playingVideoEnd: function () {
|
|
|
console.log('playingVideoEnd')
|
|
|
- this.innerAudioContext.stop();
|
|
|
+
|
|
|
+ this.ss.stopPlay();;
|
|
|
},
|
|
|
/***
|
|
|
* recordFlag:
|
|
@@ -216,12 +169,12 @@ Page({
|
|
|
this.videoCtx.stop();
|
|
|
this.videoCtx.seek(0);
|
|
|
}
|
|
|
- if (this.recorderManager) {
|
|
|
- this.recorderManager.stop();
|
|
|
- }
|
|
|
- if (this.innerAudioContext) {
|
|
|
- this.innerAudioContext.stop();
|
|
|
- }
|
|
|
+ // if (this.recorderManager) {
|
|
|
+ // this.recorderManager.stop();
|
|
|
+ // }
|
|
|
+ // if (this.innerAudioContext) {
|
|
|
+ // this.innerAudioContext.stop();
|
|
|
+ // }
|
|
|
const that = this;
|
|
|
wx.getSetting({
|
|
|
success(res) {
|
|
@@ -267,30 +220,88 @@ Page({
|
|
|
format: 'mp3',
|
|
|
frameSize: 50
|
|
|
}
|
|
|
- this.recorderManager.start(options);
|
|
|
+ this.ss.startRecord({
|
|
|
+ coreType: 'cn.sent.score', //测评题型
|
|
|
+ evalTime: 240000, //测评的录音时间,时间到自动停止测评
|
|
|
+ refText: this.data.readingText, //测评文本
|
|
|
+ warrantId: 'c11163aa6c834a028da4a4b30955be96', //鉴权id
|
|
|
+ })
|
|
|
},
|
|
|
// 录音结束
|
|
|
recordStop: function () {
|
|
|
+ this.ss.stopRecord();
|
|
|
console.log('录音结束')
|
|
|
- this.recorderManager.stop();
|
|
|
wx.hideLoading()
|
|
|
},
|
|
|
+ // 获取测评结果
|
|
|
+ getRecordScore(res) {
|
|
|
+ console.log('测评结果', res)
|
|
|
+ const result = res.result;
|
|
|
+ const overall = result.overall; // 总分
|
|
|
+ const integrity = result.integrity; //完成度
|
|
|
+ const tone = result.tone; // 语调声调
|
|
|
+ const accuracy = result.accuracy; // 发音分
|
|
|
+ const fluency = result.fluency.overall; //流利度
|
|
|
+ let starArray = [];
|
|
|
+ let score = overall / 20;
|
|
|
+ if (score <= 0) {
|
|
|
+ starArray = [0, 0, 0, 0, 0]
|
|
|
+ } else {
|
|
|
+ for (let i = 1; i < 5; i += 0.9) {
|
|
|
+ if (i < score) {
|
|
|
+ starArray.push(1);
|
|
|
+ } else {
|
|
|
+ starArray.push(0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ overall,
|
|
|
+ integrity,
|
|
|
+ tone,
|
|
|
+ accuracy,
|
|
|
+ fluency,
|
|
|
+ ifScoreDialogShow: true,
|
|
|
+ star: starArray
|
|
|
+ })
|
|
|
+ },
|
|
|
+ closeScoreDialog() {
|
|
|
+ this.setData({
|
|
|
+ ifScoreDialogShow: false,
|
|
|
+ ifScoreShow: true,
|
|
|
+ ifTextShow: false
|
|
|
+ })
|
|
|
+ },
|
|
|
// 播放录音
|
|
|
audioPlay: function () {
|
|
|
+ /* 用了先声智能以后录音播放由先声只能接管 */
|
|
|
this.setData({
|
|
|
videoUrl: this.data.videoUrl
|
|
|
})
|
|
|
- console.log('音频播放');
|
|
|
- if (this.innerAudioContext) {
|
|
|
- this.innerAudioContext.stop();
|
|
|
- this.videoCtx.stop();
|
|
|
- }
|
|
|
+
|
|
|
this.videoCtx.seek(0)
|
|
|
- this.innerAudioContext = wx.createInnerAudioContext();
|
|
|
- this.innerAudioContext.src = this.data.recordSource; // 这里可以是录音的临时路径
|
|
|
- console.log(this.innerAudioContext.src);
|
|
|
- this.videoCtx.play();
|
|
|
- this.innerAudioContext.play();
|
|
|
+ const recordSource = this.data.recordSource
|
|
|
+ wx.uploadFile({
|
|
|
+ url: 'https://reader.lingjiao.cn/readerBase/file/upload',
|
|
|
+ filePath: recordSource,
|
|
|
+ name: '朗读录音',
|
|
|
+ header: {
|
|
|
+ uid: wx.getStorageSync('uid')
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ const formateRes = JSON.parse(res.data);
|
|
|
+
|
|
|
+ let audioPath = formateRes.data;
|
|
|
+ this.setData({
|
|
|
+ audioPath,
|
|
|
+ audioPlaying: true
|
|
|
+ })
|
|
|
+ this.ss.startPlay(audioPath);
|
|
|
+ this.videoCtx.play();
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
videoComplete: function () {
|
|
@@ -312,76 +323,91 @@ Page({
|
|
|
if (this.videoCtx) {
|
|
|
this.videoCtx.stop();
|
|
|
}
|
|
|
- if (this.recorderManager) {
|
|
|
- this.recorderManager.stop();
|
|
|
- }
|
|
|
- if (this.innerAudioContext) {
|
|
|
- this.innerAudioContext.stop();
|
|
|
+ if (this.data.audioPlaying) {
|
|
|
+ this.ss.stopPlay();
|
|
|
+ this.setData({
|
|
|
+ audioPlaying: false
|
|
|
+ })
|
|
|
}
|
|
|
wx.showLoading({
|
|
|
title: '作品分享中',
|
|
|
mask: true
|
|
|
})
|
|
|
- const recordSource = this.data.recordSource;
|
|
|
- wx.uploadFile({
|
|
|
- url: 'https://reader.lingjiao.cn/readerBase/file/upload',
|
|
|
- filePath: recordSource,
|
|
|
- name: '朗读录音',
|
|
|
- header: {
|
|
|
- uid: wx.getStorageSync('uid')
|
|
|
- },
|
|
|
- success: (res) => {
|
|
|
- const formateRes = JSON.parse(res.data);
|
|
|
- let audioPath = formateRes.data;
|
|
|
- let uid = wx.getStorageSync('uid');
|
|
|
- shareWorks(uid, audioPath);
|
|
|
- }
|
|
|
|
|
|
- })
|
|
|
- let shareWorks = (uid, audio) => {
|
|
|
- if (this.innerAudioContext) {
|
|
|
- this.innerAudioContext.stop();
|
|
|
- }
|
|
|
- const data = {
|
|
|
- "lessonId": this.data.id,
|
|
|
- "originVideo": this.data.videoUrl,
|
|
|
- "audioPath": audio,
|
|
|
- "title": this.data.title,
|
|
|
- "iconImg": this.data.img,
|
|
|
- "summary": this.data.summary,
|
|
|
- "productId": this.data.productId,
|
|
|
- "grade":this.data.grade,
|
|
|
- "exampleId": this.data.exampleId
|
|
|
- };
|
|
|
- httpRequestApi.postWork(uid, data).success(res => {
|
|
|
- wx.hideLoading({
|
|
|
- success: () => {
|
|
|
- wx.showToast({
|
|
|
- title: '上传成功',
|
|
|
- icon: 'success',
|
|
|
- duration: 1000,
|
|
|
- success: () => {
|
|
|
- console.log(res);
|
|
|
- wx.redirectTo({
|
|
|
- url: `../../social/works/works?id=${res.data.data.id}&flowerCount=${res.data.count}`
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- });
|
|
|
+ if (this.data.audioPath) {
|
|
|
+ this.shareWorks(uid, this.data.audioPath)
|
|
|
+ } else {
|
|
|
+ const recordSource = this.data.recordSource;
|
|
|
+ wx.uploadFile({
|
|
|
+ url: 'https://reader.lingjiao.cn/readerBase/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);
|
|
|
+ }
|
|
|
|
|
|
})
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ shareWorks: function (audio) {
|
|
|
+
|
|
|
+ const data = {
|
|
|
+ "lessonId": this.data.id,
|
|
|
+ "originVideo": this.data.videoUrl,
|
|
|
+ "audioPath": audio,
|
|
|
+ "title": this.data.title,
|
|
|
+ "iconImg": this.data.img,
|
|
|
+ "summary": this.data.summary,
|
|
|
+ "productId": this.data.productId,
|
|
|
+ "grade": this.data.grade,
|
|
|
+ "exampleId": this.data.exampleId
|
|
|
};
|
|
|
+ httpRequestApi.postWork(data).success(res => {
|
|
|
+ wx.hideLoading({
|
|
|
+ success: () => {
|
|
|
+ wx.showToast({
|
|
|
+ title: '上传成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1000,
|
|
|
+ success: () => {
|
|
|
+ console.log(res);
|
|
|
+ const _data = this.data;
|
|
|
+ const scoreData = {
|
|
|
+ "userReadId": res.data.data.id,
|
|
|
+ "complete": _data.integrity,
|
|
|
+ "accuracy": _data.accuracy,
|
|
|
+ "speed": _data.fluency,
|
|
|
+ "intonation": _data.tone,
|
|
|
+ "score": _data.overall
|
|
|
+ }
|
|
|
+ httpRequestApi.postWorksScore(scoreData).success(res => {
|
|
|
+ console.log(res)
|
|
|
+ })
|
|
|
+ wx.redirectTo({
|
|
|
+ url: `../../social/works/works?id=${res.data.data.id}&flowerCount=${res.data.count}`
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
},
|
|
|
|
|
|
// 获取本课朗读内容
|
|
|
- getReadInfo: function (id,pageNo, pageSize) {
|
|
|
+ getReadInfo: function (id, pageNo, pageSize) {
|
|
|
// const uid = wx.getStorageSync('uid');
|
|
|
const data = {
|
|
|
exampleId: this.data.id || id,
|
|
|
pageNo: this.data.pageNo,
|
|
|
pageSize: 3,
|
|
|
- type:'READ'
|
|
|
+ type: 'READ'
|
|
|
};
|
|
|
httpRequestApi.getClassRead(this.uid, data).success(res => {
|
|
|
const readInfo = res.data.data.list;
|