H5語音輸入


首先:HTML如下:

<textarea id="speech" ng-model="speech.text" class="gwyj-textarea" maxlength="250" placeholder="請詳細描述你的崗位意見"></textarea>

上截圖:

再來:js中(我用的angularJS)

$scope.speech = {};
        $scope.speech.text = "";
        var text = "";
        $scope.startRecognize = function() {
            if(plus.os.name == 'Android' && navigator.userAgent.indexOf('StreamApp') > 0) {
                plus.nativeUI.toast('當前環境暫不支持語音識別插件');
                return;
            }
            var options = {};
            options.engine = 'iFly';
            plus.speech.startRecognize(options, function(s) {
                text = $("#speech").val() + s;
         // 控制250字之間···
if (text.length>250) { text = text.substr(0,250); } else{ $("#speech").val(text); } console.log($scope.speech.text); }, function(e) { // alert("語音識別失敗!"); plus.nativeUI.toast('語音識別失敗'); }); // setTimeout( stopRecognize, 10000 ); } function stopRecognize() { plus.speech.stopRecognize(); }

 

截圖如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM