首页 文章

在Cordova上设置语音识别插件上的语言

提问于
浏览
0

我想在离子1.7.16的移动应用程序版本中添加语音识别功能 . 我正在寻找一个可以在Android和Ios上运行的好插件 .

这里是我在互联网上找到的插件列表以及我不使用它们的原因:

  • XSpeechRecognizer:仅适用于Android

  • annyang:不适用于Ios

  • 谷歌演讲文字:仅适用于Android

  • SpeechRecognizer:仅适用于Android

特别是Annyang.js这是非常好的图书馆,真可惜 .

所以我找到了SpeechRecognitionPlugin . 但是,识别的默认语言是英语 . 我想用法语改变它 .

在github上:[https://github.com/macdonst/SpeechRecognitionPlugin][1]它's written that i can change the langage. However i didn't找到任何文档 .

你知道如何改变应用程序的语言,例如理解法语语言吗?

谢谢你的回答 .

1 回答

  • 0

    实际上我已经在我的Ionic应用程序中为这个平台添加了语音识别功能,这个解决方案在意大利语中运行得非常好,例如:

    首先:安装此插件 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>
    

    我的控制器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;
                    });
    
                }
    

    希望它对你有所帮助! ..

相关问题