Reputation: 3386
I want to add a speech recognition on my mobile app builds with ionic 1.7.16. I'm looking for a good plugin which can work on Android and Ios.
Here the list of plugin that I found on internet and the reason why i don't use them :
It's pity especially for Annyang.js which is really good library.
So I found SpeechRecognitionPlugin. However, the default langage recognized is English. I would like to change it by French.
On github : [https://github.com/macdonst/SpeechRecognitionPlugin][1] it's written that i can change the langage. However i didn't find any documentation.
Do you know how to change langage in for the app understand French langage for example ?
Thank's for your answers.
Upvotes: 0
Views: 1013
Reputation: 3778
Actually I've added Speech Recognition in my Ionic app for both platform with this solution and it works quite well in Italian for example:
FIRST: install this plug-in https://github.com/pbakondy/cordova-plugin-speechrecognition
HTML:
<div class="row bar-search-container">
<div class="item-input-inset bar-search col-80">
<label class="item-input-wrapper">
<input type="search" placeholder="Cerca" data-ng-model="brand.text" data-ng-change="brand.checkSearch()">
</label>
<span data-ng-click="brand.search()"><i class="icon ion-ios-search placeholder-icon icon-search-products"></i></span>
</div>
<div class="col microphone">
<button class="mic-button {{micstate}}" data-ng-click="recordBrand()">
<i class="icon ion-mic-a placeholder-icon mic"></i>
</button>
</div>
</div>
My Controller JS:
var vm = this;
vm.micstate = "pause";
vm.recordBrand = _record;
/*
* Function to Translate Voice in Text
*/
function _record() {
//var recognition = new webkitSpeechRecognition(); //To Computer
var recognition = new SpeechRecognition(); // To Device
if (!recognition) return;
recognition.lang = 'it-IT'; //<-- HERE YOU SET YOUR PREFERRED LANGUAGE!!!
recognition.onaudiostart = function () {
vm.micstate = "listening";
$scope.$apply();
};
recognition.onaudioend = function () {
vm.micstate = "pause";
$scope.$apply();
};
recognition.onresult = function (event) {
if (event && event.results && event.results.length > 0) {
vm.text = event.results[0][0].transcript;
// search for products
_search();
$scope.$apply();
}
};
recognition.start();
}
//If text search length=0 set searchFilter.words=[]
function _checkSearch() {
if (vm.text.length === 0) {
vm.reset = true;
_search();
}
}
/**
* Function to search Brand on input on BACK END API (with pagination)
* @param {string} input
* @returns {}
*/
function _search() {
if (!vm.text && vm.reset === false) return;
//here I'm doing a call to back end API with text getted from speech recognition and plus pagination
Brand.Get(vm.text, 0, take).$promise.then(function (resp) {
vm.brands = resp;
});
}
Hope it help you !!! ..
Upvotes: 0