uniapp語音識別(訊飛語音)轉(zhuǎn)文字
常見應(yīng)用:游戲界面
文字語音、商城導(dǎo)航欄
的語音輸入搜索框、聊天界面
的語音文字輸入等.
引自官方 unicloud官方語音:
語音輸入接口可使得網(wǎng)頁開發(fā)人員能快速調(diào)用設(shè)備的麥克風(fēng)進(jìn)行語音輸入,而不需要安裝額外的瀏覽器插件。規(guī)范不定義底層語音識別引擎的技術(shù)架構(gòu),瀏覽器實(shí)現(xiàn)可基于語音識別服務(wù)器或本地內(nèi)置語音識別模塊。
配置SDK–識別訊飛語音(如果用不了訊飛語音,可換百度語音,自己去看接入文檔)
進(jìn)入項(xiàng)目根目錄下的 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ā)送驗(yàn)證碼', e); } }) }, // 調(diào)用訊飛語音識別 voiceBegain() { let _this = this; let options = {}; //#ifdef APP-PLUS || APP-PLUS-NVUE options.engine = 'iFly'; options.punctuation = false; // 是否需要標(biāo)點(diǎn)符號 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 // 關(guān)閉語音 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>
如圖:
運(yùn)行云打包
或自定義調(diào)試基座
生成 apk 文件,apk安裝到手機(jī)上;
點(diǎn)擊button
按鈕,觸發(fā)自定義回調(diào)函數(shù)
此時頁面輸出
注意:
普通瀏覽器里沒有 plus
環(huán)境,只有 HBuilder 真機(jī)運(yùn)行和打包后才能運(yùn)行plus api
。否則報錯:
以上就是uniapp語音識別(訊飛語音)轉(zhuǎn)文字的詳細(xì)內(nèi)容,更多關(guān)于uniapp語音識別(訊飛語音)轉(zhuǎn)文字的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
淺談架構(gòu)模式變遷之從分層架構(gòu)到微服務(wù)架構(gòu)
一般地,架構(gòu)模式大致可以分成兩類,單體架構(gòu)(monolithic architecture)和分布式架構(gòu)(distributed architecture)。2021-05-05300行代碼讓外婆實(shí)現(xiàn)語音搜索購物功能
這篇文章主要介紹了300行代碼讓外婆實(shí)現(xiàn)語音搜索購物功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03淺談服務(wù)發(fā)現(xiàn)和負(fù)載均衡的來龍去脈
單機(jī)時代,傳統(tǒng)軟件大多是單體/巨石架構(gòu)(Monolithic)。大家往一個代碼倉庫提交CODE,這會導(dǎo)致應(yīng)用膨脹,以及擴(kuò)展受限,無法按需伸縮等諸多問題。單體架構(gòu)怎么解決多人合作的問題?模塊化,按功能拆分,模塊之間定義編程接口(API)。本篇文章帶你詳細(xì)了解。2021-05-05DLL(Dynamic Linkable Library) 詳解說明
DLL文件(Dynamic Linkable Library 即動態(tài)鏈接庫文件),是一種不能單獨(dú)運(yùn)行的文件,它允許程序共享執(zhí)行特殊任務(wù)所必需的代碼和其他資源2008-12-12