|
|
|
@ -61,6 +61,9 @@ export default { |
|
|
|
|
recorderManager: null, |
|
|
|
|
innerAudioContext: {}, |
|
|
|
|
isRecording: false, |
|
|
|
|
ws: null, |
|
|
|
|
webSocketUrl: "", |
|
|
|
|
VITE_APP_WS: "wss://u140106-8027-537a5c07.westx.seetacloud.com:8443/api/stt/service" |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
onLoad() { |
|
|
|
@ -74,8 +77,37 @@ export default { |
|
|
|
|
// console.log('recorder stop' + JSON.stringify(res)); |
|
|
|
|
// self.voicePath = res.tempFilePath; |
|
|
|
|
// }); |
|
|
|
|
this.initWebSocket(); |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
async initWebSocket() { |
|
|
|
|
let url = this.VITE_APP_WS; |
|
|
|
|
var audio_type = "mic_stream"; |
|
|
|
|
var hot_words = "碳丝路 元梦空间"; |
|
|
|
|
var hot_words2 = "碳丝路元梦空间"; |
|
|
|
|
var language = "zh"; |
|
|
|
|
var sample_rate = "16000"; |
|
|
|
|
var timestamp = Math.floor(Date.now() / 1000); |
|
|
|
|
var api_key = "AT_syAHhLp3vqOA!@+T9Cocxc0^6z@^9"; |
|
|
|
|
var auth = `api_key=${api_key}&audio_type=${audio_type}&hot_words=${hot_words2}&language=${language}&sample_rate=${sample_rate}&stream=True×tamp=${timestamp}`; |
|
|
|
|
const sign = await this.sha256(auth); |
|
|
|
|
url = `${url}?audio_type=${audio_type}&hot_words=${encodeURIComponent(hot_words)}&language=${language}&sample_rate=${sample_rate}×tamp=${timestamp}&api_key=${encodeURIComponent(api_key)}&auth=${sign}`; |
|
|
|
|
createdWebSocket(url); |
|
|
|
|
}, |
|
|
|
|
async sha256(str) { |
|
|
|
|
// 将输入字符串转换为二进制数据 |
|
|
|
|
const encoder = new TextEncoder(); |
|
|
|
|
const data = encoder.encode(str); |
|
|
|
|
// 调用原生的SubtleCrypto API计算SHA-256哈希 |
|
|
|
|
return crypto.subtle.digest("SHA-256", data).then(buffer => { |
|
|
|
|
// 将哈希结果转换为十六进制字符串 |
|
|
|
|
const hexArray = Array.from(new Uint8Array(buffer)); |
|
|
|
|
const hexString = hexArray |
|
|
|
|
.map(byte => byte.toString(16).padStart(2, "0")) |
|
|
|
|
.join(""); |
|
|
|
|
return hexString; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
confirm() { |
|
|
|
|
this.popConfig.show = false; |
|
|
|
|
}, |
|
|
|
|