uniapp語音識別(訊飛語音)轉(zhuǎn)文字
常見應用:游戲界面
文字語音、商城導航欄
的語音輸入搜索框、聊天界面
的語音文字輸入等.
引自官方 unicloud官方語音:
語音輸入接口可使得網(wǎng)頁開發(fā)人員能快速調(diào)用設備的麥克風進行語音輸入,而不需要安裝額外的瀏覽器插件。規(guī)范不定義底層語音識別引擎的技術(shù)架構(gòu),瀏覽器實現(xiàn)可基于語音識別服務器或本地內(nèi)置語音識別模塊。
配置SDK–識別訊飛語音(如果用不了訊飛語音,可換百度語音,自己去看接入文檔)
進入項目根目錄下的 manifest.json
-> App模塊配置
->speech
勾選 訊飛語音識別,如下圖所示:
index.vue
文件寫入
<template> <view class="content"> <image class="logo" src="/static/logo.png"></image> <button @click="voiceBegain">訊飛語音識別</button> <view v-if="words1"> 這是searchValue:{{words1}} </view> <view v-if="words2"> 這是searchText:{{words2}} </view> </view> </template> <script> export default { data() { return { title: 'Hello', words1: '', words2: '' } }, onLoad() { }, methods: { send() { uniCloud.callFunction({ name: 'sendcode', success: (e) => { console.log('這是發(fā)送驗證碼', e); } }) }, // 調(diào)用訊飛語音識別 voiceBegain() { let _this = this; let options = {}; //#ifdef APP-PLUS || APP-PLUS-NVUE options.engine = 'iFly'; options.punctuation = false; // 是否需要標點符號 options.timeout = 10 * 1000; //語音錄入持續(xù)時長 plus.speech.startRecognize(options, function(s) { _this.searchText = _this.searchText + s; console.log(_this.searchText) //拿到語音識別的結(jié)果 //下面是邏輯 _this.searchValue = s; _this.searchText = "" // 打印輸出結(jié)果 _this.words1 = _this.searchValue _this.words2 = _this.searchText // 關閉語音 plus.speech.stopRecognize(); }); //#endif // #ifdef H5 alert("只有h5平臺才有alert方法") // #endif } } } </script> <style> .content { display: flex; flex-direction: column; align-items: center; justify-content: center; } .logo { height: 200rpx; width: 200rpx; margin-top: 200rpx; margin-left: auto; margin-right: auto; margin-bottom: 50rpx; } .text-area { display: flex; justify-content: center; } .title { font-size: 36rpx; color: #8f8f94; } </style>
如圖:
運行云打包
或自定義調(diào)試基座
生成 apk 文件,apk安裝到手機上;
點擊button
按鈕,觸發(fā)自定義回調(diào)函數(shù)
此時頁面輸出
注意:
普通瀏覽器里沒有 plus
環(huán)境,只有 HBuilder 真機運行和打包后才能運行plus api
。否則報錯:
以上就是uniapp語音識別(訊飛語音)轉(zhuǎn)文字的詳細內(nèi)容,更多關于uniapp語音識別(訊飛語音)轉(zhuǎn)文字的資料請關注腳本之家其它相關文章!
相關文章
淺談架構(gòu)模式變遷之從分層架構(gòu)到微服務架構(gòu)
一般地,架構(gòu)模式大致可以分成兩類,單體架構(gòu)(monolithic architecture)和分布式架構(gòu)(distributed architecture)。2021-05-05DLL(Dynamic Linkable Library) 詳解說明
DLL文件(Dynamic Linkable Library 即動態(tài)鏈接庫文件),是一種不能單獨運行的文件,它允許程序共享執(zhí)行特殊任務所必需的代碼和其他資源2008-12-12