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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
< template >
< view >
< tabbar :index ="0" > < / tabbar >
< view class = "info" >
{ { voiceText } }
< / view >
< view class = "footer" >
< all -speech @startRecord ="start" @endRecord ="end" @cancelRecord ="cancel" > < / all -speech >
< / view >
< / view >
< / template >
< script >
const innerAudioContext = uni . createInnerAudioContext ( ) ;
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 ( ) {
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--------------' ) ;
}
}
}
< / script >
< style lang = "scss" >
. app {
height : 100 vh ;
width : 100 vw ;
}
image {
width : 450 rpx ;
height : 800 rpx ;
}
. info {
margin - top : 3 vh ;
padding - left : 10 px ;
font - size : 32 rpx ;
}
. footer {
position : fixed ;
bottom : 13 vh ;
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 >