本文基于TUIKit Demo项目集成迅飞语音听写(流式版)功能:
主要代码:
// \src\TUIKit\components\TUIChat\message-input\index.vue
<template>
<!-- 录音按钮 -->
<div @touchstart.stop="touchstart" />
<!-- 输入框 -->
<MessageInputEditor ref="editor"/>
</template>
<script setup lang="ts">
// xf-voice代码请参考本文附件
import { IatRecorder } from './xf-voice'
let xfVoice = null
const getPermission = () => {
return navigator.mediaDevices.getUserMedia({ audio: true })
}
const initXFVoice = (webSocketUrl) => {
// 实例化迅飞语音听写(流式版)WebAPI
let times = null
xfVoice = new IatRecorder({
APPID: '填写自己的APPID',
webSocketUrl,
onWillS