You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
2.4 KiB

5 months ago
<template>
<view>
5 months ago
<tabbar :index="0"></tabbar>
4 months ago
<view class="info">
{{voiceText}}
</view>
<view class="footer">
<all-speech @startRecord="start" @endRecord="end" @cancelRecord="cancel"></all-speech>
</view>
5 months ago
</view>
</template>
<script>
4 months ago
const innerAudioContext = uni.createInnerAudioContext();
5 months ago
4 months ago
const plugin = requirePlugin("WechatSI")
const manager = plugin.getRecordRecognitionManager()
import {
getAIReply
} from '@/config/api.js';
export default {
data() {
return {
voicePath: '',
voiceText: ''
}
},
onLoad() {
manager.onStop = (res) => {
this.voicePath = res.tempFilePath;
this.voiceText = res.result;
if (this.voiceText == '') {
this.voiceText = '周围太安静啦~再试试~';
}
console.log("===============")
console.log(this.voiceText)
console.log("===============")
getAIReply({
prompt: this.voiceText,
session_id: '1'
}).then((res) => {
console.log(res.data.url)
innerAudioContext.src = res.data.url;
innerAudioContext.play();
}).catch((err) => {
console.log(err)
})
console.log("2133123")
};
// 识别错误事件
manager.onError = (err) => {
uni.showToast({
title: '错误(' + err.retcode + ')' + err.msg,
icon: 'none',
duration: 2000, //持续时间为 2秒
})
};
},
methods: {
test() {
5 months ago
4 months ago
getAIReply({
prompt: "长春是哪个省的省会?"
}).then((res) => {
console.log(res)
}).catch((err) => {
console.log(err)
})
},
start() {
console.log('start--------------');
manager.start({
duration: 60000,
lang: "zh_CN"
})
},
end() {
console.log('end--------------');
manager.stop();
},
cancel() {
console.log('cancel--------------');
}
}
5 months ago
}
</script>
4 months ago
<style lang="scss">
.app {
height: 100vh;
width: 100vw;
}
image {
width: 450rpx;
height: 800rpx;
}
.info {
margin-top: 3vh;
padding-left: 10px;
font-size: 32rpx;
}
.footer {
position: fixed;
bottom: 13vh;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.flex {
display: flex;
width: 100%;
/* background-color: red; */
}
/* image{
width: 20vw;
height: 70vh;
margin-right: 3vw;
} */
</style>