当前位置: 首页 > news >正文

免费建设微网站制作湖南seo网站策划

免费建设微网站制作,湖南seo网站策划,杭州萧山网站建设,怎么用网站做chm阿里提供的demo代码都是javascript,自己捏个轮子。参考着自己写了一个阿里巴巴一句话听写Nls的typescript模块。VUE3的组合式API形式 startClient:开始听写,注意下一步要尽快开启识别和传数据,否则6秒后会关闭 startRecognition…

阿里提供的demo代码都是javascript,自己捏个轮子。参考着自己写了一个阿里巴巴一句话听写Nls的typescript模块。VUE3的组合式API形式

startClient:开始听写,注意下一步要尽快开启识别和传数据,否则6秒后会关闭

startRecognition:开始识别事务,传入识别回调,可以打印字符或显示到屏幕

sendSound:发送二进制PCM数据(格式16MHz16bit)

stopRecognition:结束识别事务

/*** 阿里语音,一句话识别模块for ccframe** 无心跳设计,非长连接推送,因此在需要使用的时候才进行连接** @Jim 2024/07/08*/
import * as utils from '@/utils/index'
import { nextTick } from 'vue'
// import Global from '@/utils/constants'const NLS_SERVER_URL = 'wss://nls-gateway.aliyuncs.com/ws/v1'
const NLS_MODE = 'SpeechRecognizer' // 一句话识别
const WEBSOCKET_MAX_RETRY = 3
const RECONNECT_INTERVAL = 3000interface INlsConfig {url?: stringappkey: string // 应用的keytoken: string // 从服务器获得,要缓存
}let client: (UniNamespace.SocketTask & { readyState?: WsState }) | undefined
const clientId = utils.uuid(utils.UUIDFormat.StandardCompact)
let taskId: string = ''
let config: INlsConfig
let reconnectAttempts = 0
let taskStarted = falseenum WsState {CONNECTING,OPEN,CLOSING,CLOSED
}/**** @param action* @returns 请求json*/
const buildMsg: (action: string, payload: Record<string, any>) => string = (action,payload = {}
) => {if (taskId.length === 0) {taskId = utils.uuid(utils.UUIDFormat.StandardCompact)}const msg = {header: {message_id: utils.uuid(utils.UUIDFormat.StandardCompact),task_id: taskId,namespace: NLS_MODE,name: action,appkey: config.appkey},payload,context: {sdk: {name: 'nls-wx-sdk',version: '0.0.1',language: 'wxjs'}}}return JSON.stringify(msg, null, 0)
}/*** 开启连接,开启后立即要传,否则会被关闭.* @param config* @param callback*/
export const startClient = (conf?: INlsConfig,startCallback?: () => void,recognizedCallback?: (text: string) => void
) => {if (client && client.readyState !== WsState.CLOSED) {// 关闭原连接client.close({})}client = uni.connectSocket({url: conf.url ?? NLS_SERVER_URL,tcpNoDelay: true,header: {'X-NLS-Token': conf?.token ?? config.token},success: (res) => {if (!config) config = confconsole.log(`connected to ${NLS_SERVER_URL} success`)},fail: (res) => {console.log(`connect to ${NLS_SERVER_URL} failed:${res.errMsg}`)}})client.readyState = WsState.CONNECTINGclient.onMessage((res) => {if (typeof res.data === 'string') {const msgObj = JSON.parse(res.data)switch (msgObj?.header?.name) {case 'RecognitionStarted': {console.log('started')break}case 'RecognitionResultChanged': {if (recognizedCallback) {const text = msgObj?.payload?.resultif (text) {recognizedCallback(text)}}console.log('changed')break}case 'RecognitionCompleted': {const text = msgObj?.payload?.resultif (text) {recognizedCallback(text)}taskStarted = false // 结束识别break}case 'TaskFailed': {taskStarted = false // 结束识别break}}}console.log('recv:' + res.data)})client.onOpen(() => {reconnectAttempts = 0client.readyState = WsState.OPENif (startCallback) nextTick(startCallback)})client.onError((error) => {console.error('WebSocket error:', error)if (reconnectAttempts < WEBSOCKET_MAX_RETRY) {setTimeout(() => startClient(), RECONNECT_INTERVAL)} else {console.error('Max reconnect attempts reached')}})client.onClose(() => {client.readyState = WsState.CLOSEDconsole.log('connection closed')})
}export const startRecognition = () => {if (client && client.readyState === WsState.OPEN)client.send({data: buildMsg('StartRecognition', {format: 'opus',sample_rate: 16000,enable_intermediate_result: true,enable_punctuation_prediction: true,enable_inverse_text_normalization: true}),success: (res) => {taskStarted = true}})
}export const stopRecognition = () => {if (client && client.readyState === WsState.OPEN)client.send({data: buildMsg('StopRecognition', {format: 'opus',sample_rate: 16000,enable_intermediate_result: true,enable_punctuation_prediction: true,enable_inverse_text_normalization: true}),complete: () => {taskStarted = false // 不管是否成功,都不发送音频了}})
}export const sendSound = (msgBytes: ArrayBuffer) => {if (client && client.readyState === WsState.OPEN && taskStarted)client.send({data: msgBytes,success: (res) => {console.log('send ' + msgBytes.byteLength + ' success')}})
}

util的uuid工具见我前一篇文章https://mp.csdn.net/mp_blog/creation/editor/140267684icon-default.png?t=N7T8https://mp.csdn.net/mp_blog/creation/editor/140267684

http://www.hkea.cn/news/896754/

相关文章:

  • 中企动力做网站的优势网络销售平台有哪些软件
  • 网站建设的费用如何查看百度搜索指数
  • 自己做网站需要什么seo的基本步骤
  • 视频直播app开发网站南京最新消息今天
  • 溧阳手机网站哪里做万网域名注册官网查询
  • 网站维护收费推广产品吸引人的句子
  • 怎么用一个主机做多个网站许昌网络推广公司
  • 网站域名所有权郑州网站运营专业乐云seo
  • 桂园精品网站建设费用网站seo查询站长之家
  • 安卓手机怎么做网站站长工具seo综合查询广告
  • 余姚网站建设的公司手机百度账号申请注册
  • 预付网站制作费怎么做凭证如何自制网站
  • 定制网站多少钱北京seo网站管理
  • 南昌做网站公司哪家好如何建立独立网站
  • 成都解放号网站建设什么是百度竞价
  • 网站优化的基本思想与原则百度号码
  • 沧州网站建设制作设计优化深圳seo优化推广
  • 建立一个网站需要什么技术网上培训机构
  • 网站设计与管理论文百度账号注册平台
  • 网站空间商推荐seo是什么职位缩写
  • 怎么建设boss网站文件外链
  • 百度推广网站建设费百度搜索引擎的网址是多少
  • php 手机网站 上传图片定制网站建设
  • 关于网站建设的问题百度关键词分析
  • 登录官方网站装修公司网络推广方案
  • 设计网站官网入口网站搜索优化方法
  • 网站优化qq群山东做网站
  • wordpress icomoon太原seo快速排名
  • 中华建设杂志网站记者数据指数
  • 网站开发测试情况南召seo快速排名价格