|
@@ -4,16 +4,15 @@
|
|
|
<script>
|
|
|
const util = require('@/utils/util.js').default;
|
|
|
const config = require('@/services/urlConfig.js');
|
|
|
+ let webAudioSpeechRecognizer;
|
|
|
import router from "@/router";
|
|
|
import {
|
|
|
setStorage,
|
|
|
getStorage,
|
|
|
} from '@/utils/localStorage';
|
|
|
import {
|
|
|
- Toast
|
|
|
+ Toast,Indicator
|
|
|
} from 'mint-ui';
|
|
|
- // import houseList from "../../components/houseList/houseList.vue";
|
|
|
- // import houseList2 from "../../components/houseList/houseList2.vue";
|
|
|
import commonPageMethod from '@/mixins/commonPageMethod.js';
|
|
|
export default {
|
|
|
mixins: [commonPageMethod],
|
|
@@ -49,10 +48,10 @@
|
|
|
selectIndex: -1, //用户选择的户型序号
|
|
|
queryObj: null, //页面参数
|
|
|
|
|
|
- webAudioSpeechRecognizer: null, //语音识别的对象
|
|
|
speechText: '', //语音识别的结果-文字
|
|
|
recording: false, //语音识别是否开始
|
|
|
- isCanStop:false, //socket是否已经链接好了
|
|
|
+ touching:false,
|
|
|
+ messageList:[], //消息列表
|
|
|
}
|
|
|
},
|
|
|
// components: {
|
|
@@ -136,25 +135,32 @@
|
|
|
};
|
|
|
util.trackRequest(param);
|
|
|
},
|
|
|
+ //选中这个户型
|
|
|
changeHouse(index) {
|
|
|
- this.curHouseObj = this.houseList[index];
|
|
|
- this.selectIndex = index;
|
|
|
- console.log("changeHouse: ", this.curHouseObj, this.selectIndex);
|
|
|
+ let curHouseObj = this.houseList[index];
|
|
|
+ // this.selectIndex = index;
|
|
|
+ console.log("changeHouse: ", curHouseObj);
|
|
|
let param = {
|
|
|
type: 'CLK', //埋点类型
|
|
|
clkId: 'clk_2cmina_24012401', //点击ID
|
|
|
clkName: 'option_clk', //点击前往的页面名称
|
|
|
clkParams: {
|
|
|
- houseType: this.curHouseObj.houseType,
|
|
|
- name: this.curHouseObj.name,
|
|
|
- note: this.curHouseObj.note,
|
|
|
- area: this.curHouseObj.houseArea,
|
|
|
- id: this.curHouseObj.id,
|
|
|
- locusValue: this.curHouseObj.houseType,
|
|
|
+ houseType: curHouseObj.houseType,
|
|
|
+ name: curHouseObj.name,
|
|
|
+ note: curHouseObj.note,
|
|
|
+ area: curHouseObj.houseArea,
|
|
|
+ id: curHouseObj.id,
|
|
|
+ locusValue: curHouseObj.houseType,
|
|
|
locusName: "空间选择",
|
|
|
}
|
|
|
};
|
|
|
util.trackRequest(param);
|
|
|
+ let message = {
|
|
|
+ author: 'AI',
|
|
|
+ type: 2,
|
|
|
+ ...curHouseObj,
|
|
|
+ }
|
|
|
+ this.messageList.push(message);
|
|
|
},
|
|
|
//查询题目数据
|
|
|
// async queryTestcaseSingle() {
|
|
@@ -212,7 +218,9 @@
|
|
|
}
|
|
|
},
|
|
|
//进入下一步
|
|
|
- enterAction() {
|
|
|
+ enterAction(index) {
|
|
|
+ let message = this.messageList[index];
|
|
|
+ this.curHouseObj = this.houseList.find(it=>it.id==message.id);
|
|
|
if (!this.curHouseObj) {
|
|
|
Toast({
|
|
|
message: '请选择喜欢的空间',
|
|
@@ -277,10 +285,25 @@
|
|
|
text = text.replaceAll(/ |,|。/ig, "");
|
|
|
if (!text) {
|
|
|
Toast({
|
|
|
- message: '请再说一次',
|
|
|
+ message: '未识别到语音',
|
|
|
});
|
|
|
return false;
|
|
|
}
|
|
|
+ let message = {
|
|
|
+ author: this.userId,
|
|
|
+ type: 1,
|
|
|
+ text: text,
|
|
|
+ }
|
|
|
+ this.messageList.push(message);
|
|
|
+ let param = {
|
|
|
+ type: 'CLK', //埋点类型
|
|
|
+ clkId: 'clk_2cmina_24082901', //点击ID
|
|
|
+ clkName: 'user_talk_clk', //点击前往的页面名称
|
|
|
+ clkParams: {
|
|
|
+ locusValue: text,
|
|
|
+ }
|
|
|
+ };
|
|
|
+ util.trackRequest(param);
|
|
|
// let res = await requestConfig("chineseToPinyin", {
|
|
|
// chinese: text
|
|
|
// });
|
|
@@ -292,9 +315,15 @@
|
|
|
if(houseIndex){
|
|
|
houseIndex = this.houseList.length - houseIndex;
|
|
|
if(houseIndex < 0){//越界了
|
|
|
- Toast({
|
|
|
- message: '数据不合法,请再说一次',
|
|
|
- });
|
|
|
+ // Toast({
|
|
|
+ // message: '数据不合法,请再说一次',
|
|
|
+ // });
|
|
|
+ let message = {
|
|
|
+ author: 'AI',
|
|
|
+ type: 2,
|
|
|
+ text: "没有匹配到,请再说一次~",
|
|
|
+ }
|
|
|
+ this.messageList.push(message);
|
|
|
}else{
|
|
|
this.changeHouse(houseIndex);
|
|
|
}
|
|
@@ -321,7 +350,7 @@
|
|
|
}
|
|
|
})
|
|
|
console.warn("***mate-result-list***",list);
|
|
|
- //寻找5个字符串以上的
|
|
|
+ //寻找2个字符串以上的
|
|
|
let tmpList = list.filter(it => {
|
|
|
return it.comStr.length > 2;
|
|
|
})
|
|
@@ -333,33 +362,34 @@
|
|
|
}
|
|
|
//没有找到语音操作对象
|
|
|
if (houseIndex==null || houseIndex < 0) {
|
|
|
- Toast({
|
|
|
- message: '请再说一次',
|
|
|
- });
|
|
|
+ let message = {
|
|
|
+ author: 'AI',
|
|
|
+ type: 2,
|
|
|
+ text: "没有匹配到,请再说一次",
|
|
|
+ }
|
|
|
+ this.messageList.push(message);
|
|
|
return false;
|
|
|
}
|
|
|
if(houseIndex > this.houseList.length){
|
|
|
- Toast({
|
|
|
- message: '数据不合法,请再说一次',
|
|
|
- });
|
|
|
+ // Toast({
|
|
|
+ // message: '数据不合法,请再说一次',
|
|
|
+ // });
|
|
|
+ let message = {
|
|
|
+ author: 'AI',
|
|
|
+ type: 2,
|
|
|
+ text: "没有匹配到,请再说一次!",
|
|
|
+ }
|
|
|
+ this.messageList.push(message);
|
|
|
return false;
|
|
|
}
|
|
|
this.changeHouse(houseIndex);
|
|
|
console.log("textChange:", houseIndex);
|
|
|
- // this.$emit("curSpaceChange", data); //通知父组件-当前已经选中了户型大类
|
|
|
- },
|
|
|
- //用户语音为空
|
|
|
- showRecordEmptyTip() {
|
|
|
- this.recording = false; //录音结束
|
|
|
- Toast({
|
|
|
- message: '告诉我您的想法',
|
|
|
- });
|
|
|
},
|
|
|
//语音识别
|
|
|
speechRecognizer() {
|
|
|
- this.recording = true;
|
|
|
- console.warn('speechRecognizer', this.webAudioSpeechRecognizer,this.recording);
|
|
|
- if (!this.webAudioSpeechRecognizer) {
|
|
|
+ this.touching = true;//用户开始触摸语音按钮
|
|
|
+ console.warn('speechRecognizer',this.recording);
|
|
|
+ // if (!webAudioSpeechRecognizer) {
|
|
|
const params = {
|
|
|
// signCallback: signCallback, // 鉴权函数,若直接使用默认鉴权函数。可不传此参数
|
|
|
// 用户参数
|
|
@@ -380,62 +410,61 @@
|
|
|
// convert_num_mode : 1,
|
|
|
// word_info: 2
|
|
|
}
|
|
|
- const webAudioSpeechRecognizer = new WebAudioSpeechRecognizer(params);
|
|
|
- let resultText = '';
|
|
|
+ webAudioSpeechRecognizer = new WebAudioSpeechRecognizer(params);
|
|
|
+ Indicator.open({
|
|
|
+ text: '正在链接...',
|
|
|
+ spinnerType: 'fading-circle'
|
|
|
+ });
|
|
|
// 开始识别
|
|
|
webAudioSpeechRecognizer.OnRecognitionStart = (res) => {
|
|
|
- console.log('开始识别',this.recording, res);
|
|
|
+ console.log('开始识别',res);
|
|
|
};
|
|
|
// 一句话开始 socket链接成功了
|
|
|
webAudioSpeechRecognizer.OnSentenceBegin = (res) => {
|
|
|
- console.log('一句话开始',this.recording, res);
|
|
|
- this.speechText = "";
|
|
|
- this.isCanStop = true;
|
|
|
+ console.log('一句话开始',this.touching,res);
|
|
|
+ if(this.touching==false){//用户没有触摸
|
|
|
+ return false;
|
|
|
+ }else{//正常开始识别语句了
|
|
|
+ this.speechText = "";
|
|
|
+ Indicator.close();
|
|
|
+ this.recording = true;//显示正在录音视图
|
|
|
+ }
|
|
|
+
|
|
|
};
|
|
|
// 识别变化时
|
|
|
webAudioSpeechRecognizer.OnRecognitionResultChange = (res) => {
|
|
|
- console.log('识别变化时',this.recording, res);
|
|
|
- const currentText = `${resultText}${res.result.voice_text_str}`;
|
|
|
- this.speechText = currentText;
|
|
|
+ console.log('识别变化时', res);
|
|
|
};
|
|
|
// 一句话结束
|
|
|
webAudioSpeechRecognizer.OnSentenceEnd = (res) => {
|
|
|
console.log('一句话结束',this.recording, res);
|
|
|
- resultText += res.result.voice_text_str;
|
|
|
+ let resultText = res.result.voice_text_str;
|
|
|
this.speechText = resultText;
|
|
|
- let param = {
|
|
|
- type: 'CLK', //埋点类型
|
|
|
- clkId: 'clk_2cmina_23080407', //点击ID
|
|
|
- clkName: 'voice_clk', //点击前往的页面名称
|
|
|
- clkParams: {
|
|
|
- locusName: "语音调整",
|
|
|
- text: resultText
|
|
|
- }
|
|
|
- };
|
|
|
- util.trackRequest(param);
|
|
|
this.textChange(resultText);
|
|
|
};
|
|
|
// 识别结束
|
|
|
webAudioSpeechRecognizer.OnRecognitionComplete = (res) => {
|
|
|
console.log('识别结束', res);
|
|
|
+ this.recording = false; //录音结束
|
|
|
};
|
|
|
// 识别错误
|
|
|
webAudioSpeechRecognizer.OnError = (res) => {
|
|
|
console.log('识别失败', res)
|
|
|
+ this.recording = false; //录音结束
|
|
|
+ Indicator.close();
|
|
|
};
|
|
|
- this.webAudioSpeechRecognizer = webAudioSpeechRecognizer;
|
|
|
- }
|
|
|
- this.webAudioSpeechRecognizer.start();
|
|
|
+ // }
|
|
|
+ webAudioSpeechRecognizer.start();
|
|
|
},
|
|
|
//结束识别
|
|
|
streamRecordEnd() {
|
|
|
- this.recording = false; //录音结束
|
|
|
- console.log('主动结束识别', this.recording,this.isCanStop)
|
|
|
- if (this.isCanStop) {//链接成功才能关闭
|
|
|
- this.webAudioSpeechRecognizer.stop();//关闭
|
|
|
- this.isCanStop = false; //已经关闭了,不能在此打开
|
|
|
- this.webAudioSpeechRecognizer = null;
|
|
|
+ this.touching = false;//用户没有触摸了
|
|
|
+ console.log('主动结束识别', this.recording)
|
|
|
+ if(webAudioSpeechRecognizer){
|
|
|
+ webAudioSpeechRecognizer.stop();//关闭
|
|
|
}
|
|
|
+ // webAudioSpeechRecognizer = null;
|
|
|
+ Indicator.close();
|
|
|
},
|
|
|
},
|
|
|
}
|