AudioToWord.js
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-02-27 18:00:28
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-02-27 18:00:50
* @FilePath: \salesgpt-project\src\mixins\AudioToWord.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
export default {
data() {
return {
word: '',
isListening: false // 判断是否在语音监听中
}
},
methods: {
audioCHangeWord() {
var that = this
that.word = ''
// 创建SpeechRecognition对象
// eslint-disable-next-line no-undef
var recognition = new webkitSpeechRecognition()
console.log('recognition1', recognition)
if (!recognition) {
// eslint-disable-next-line no-undef
recognition = new SpeechRecognition()
}
console.log('recognition2', recognition)
console.log(11)
// 设置语言
recognition.lang = 'zh-CN'
console.log(22)
// 开始语音识别
recognition.start()
that.isListening = true
console.log(33)
// 监听识别结果
recognition.onresult = function (event) {
var result = event.results[0][0].transcript
console.log('监听结果:', result)
that.send(result)
}
// 监听错误事件
recognition.onerror = function (event) {
that.isListening = false
that.$message('监听语音失败:' + event.error)
console.error(event.error)
}
// 监听结束事件(包括识别成功、识别错误和用户停止)
recognition.onend = function () {
that.isListening = false
console.log('语音识别停止')
}
},
goBack() {
this.$router.push({ path: '/entry' })
}
}
}