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

时间:2016-07-08 14:54:30

标签: cordova ionic-framework speech-recognition

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

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

  • XSpeechRecognizer:仅适用于Android
  • annyang:对Ios不起作用
  • Google演讲文字:仅适用于Android
  • SpeechRecognizer:仅供参考 的Android

特别是对于Annyang.js而言,这是非常好的,这是非常好的图书馆。

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

在github上:[https://github.com/macdonst/SpeechRecognitionPlugin][1]它写的是我可以改变语言。但是我没有找到任何文件。

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

感谢您的回答。

1 个答案:

答案 0 :(得分: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;
                });

            }

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

相关问题