uniapp語(yǔ)音識(shí)別(訊飛語(yǔ)音)轉(zhuǎn)文字
常見(jiàn)應(yīng)用:游戲界面 文字語(yǔ)音、商城導(dǎo)航欄的語(yǔ)音輸入搜索框、聊天界面的語(yǔ)音文字輸入等.
引自官方 unicloud官方語(yǔ)音:
語(yǔ)音輸入接口可使得網(wǎng)頁(yè)開(kāi)發(fā)人員能快速調(diào)用設(shè)備的麥克風(fēng)進(jìn)行語(yǔ)音輸入,而不需要安裝額外的瀏覽器插件。規(guī)范不定義底層語(yǔ)音識(shí)別引擎的技術(shù)架構(gòu),瀏覽器實(shí)現(xiàn)可基于語(yǔ)音識(shí)別服務(wù)器或本地內(nèi)置語(yǔ)音識(shí)別模塊。
配置SDK–識(shí)別訊飛語(yǔ)音(如果用不了訊飛語(yǔ)音,可換百度語(yǔ)音,自己去看接入文檔)
進(jìn)入項(xiàng)目根目錄下的 manifest.json -> App模塊配置->speech 勾選 訊飛語(yǔ)音識(shí)別,如下圖所示:

index.vue文件寫(xiě)入
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<button @click="voiceBegain">訊飛語(yǔ)音識(shí)別</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)用訊飛語(yǔ)音識(shí)別
voiceBegain() {
let _this = this;
let options = {};
//#ifdef APP-PLUS || APP-PLUS-NVUE
options.engine = 'iFly';
options.punctuation = false; // 是否需要標(biāo)點(diǎn)符號(hào)
options.timeout = 10 * 1000; //語(yǔ)音錄入持續(xù)時(shí)長(zhǎng)
plus.speech.startRecognize(options, function(s) {
_this.searchText = _this.searchText + s;
console.log(_this.searchText) //拿到語(yǔ)音識(shí)別的結(jié)果
//下面是邏輯
_this.searchValue = s;
_this.searchText = ""
// 打印輸出結(jié)果
_this.words1 = _this.searchValue
_this.words2 = _this.searchText
// 關(guān)閉語(yǔ)音
plus.speech.stopRecognize();
});
//#endif
// #ifdef H5
alert("只有h5平臺(tái)才有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ù)

此時(shí)頁(yè)面輸出

注意:
普通瀏覽器里沒(méi)有 plus 環(huán)境,只有 HBuilder 真機(jī)運(yùn)行和打包后才能運(yùn)行plus api。否則報(bào)錯(cuò):

以上就是uniapp語(yǔ)音識(shí)別(訊飛語(yǔ)音)轉(zhuǎn)文字的詳細(xì)內(nèi)容,更多關(guān)于uniapp語(yǔ)音識(shí)別(訊飛語(yǔ)音)轉(zhuǎn)文字的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
淺談架構(gòu)模式變遷之從分層架構(gòu)到微服務(wù)架構(gòu)
一般地,架構(gòu)模式大致可以分成兩類(lèi),單體架構(gòu)(monolithic architecture)和分布式架構(gòu)(distributed architecture)。2021-05-05
300行代碼讓外婆實(shí)現(xiàn)語(yǔ)音搜索購(gòu)物功能
這篇文章主要介紹了300行代碼讓外婆實(shí)現(xiàn)語(yǔ)音搜索購(gòu)物功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03
淺談服務(wù)發(fā)現(xiàn)和負(fù)載均衡的來(lái)龍去脈
單機(jī)時(shí)代,傳統(tǒng)軟件大多是單體/巨石架構(gòu)(Monolithic)。大家往一個(gè)代碼倉(cāng)庫(kù)提交CODE,這會(huì)導(dǎo)致應(yīng)用膨脹,以及擴(kuò)展受限,無(wú)法按需伸縮等諸多問(wèn)題。單體架構(gòu)怎么解決多人合作的問(wèn)題?模塊化,按功能拆分,模塊之間定義編程接口(API)。本篇文章帶你詳細(xì)了解。2021-05-05
DLL(Dynamic Linkable Library) 詳解說(shuō)明
DLL文件(Dynamic Linkable Library 即動(dòng)態(tài)鏈接庫(kù)文件),是一種不能單獨(dú)運(yùn)行的文件,它允許程序共享執(zhí)行特殊任務(wù)所必需的代碼和其他資源2008-12-12

