从 ATT 语音 API 获取输出作为"Speech Not Recognized"



这是我的控制器(MyCltr.js)它有两个函数,第一个用于获取 acess 令牌,第二个用于将音频文件发布到语音 API,但是当第二个函数被称为 JSON 形式的响应时是

{"识别":{"信息":{"指标":{"音频字节":0,"

音频时间":0}},"响应ID":"c2f8054051177fb5086a9006637d8fdb","状态":"语音无法识别"}}

音频文件有一些录音,但显示状态为"无法识别语音"。请帮助我从音频文件中获取文本。

var MyCtrl=angular.module('MyApp.controller',[]);

MyCtrl.controller('FirstCtrl', ['$scope','$rootScope','$location','$log','$http','$window',
 function($scope,$rootScope,$location,$log,$http){
      $scope.files = '$audio.wav';

    $scope.getToken = function () { $http({method:'POST',
                url:'https://api.att.com/oauth/token',
                headers:{'Content-Type':'application/x-www-form-urlencoded',
                    'Accept':'application/json'
                    },
              /* data:'client_id=d3m1zlqukeyjctt5jj69jicwx4hxlpz9&client_secret=kzzwjdrvf3cugiiaycxbujqkwjfze782&grant_type=client_credentials&scope=SPEECH'*/
                    params: {
                        'client_id':'5b1cb9a9c097e1100eeeebaf66117265',
                        'client_secret':'01b8417ac6872450',
                        'grant_type':'client_credentials',
                        'scope':'SPEECH'
                    }
                }  
    ).success(function(response){
                    $scope.response = response;
                    $scope.access_token=$scope.response.access_token;
                    alert($scope.access_token);
                   var result=angular.toJson($scope.response,[true]);
                    alert(result);
                   // $scope.getText();
                })
     .error(function(error){
                    $scope.error = error;
                    $log.log('Its Error');
                });      
};  

$scope.getText = function () {
    $http({method:'POST',
    url:'https://api.att.com/rest/2/SpeechToText',
         data:$scope.files,
    headers:{
        'Accept':'application/json',
        'Authorization':'Bearer '+$scope.access_token ,
        'X-SpeechContext': 'Generic',
        'Content-Type':'audio/wav'
        }

    }
).success(function(response){
$scope.response = response;
          var result1=angular.toJson($scope.response,[true]);
                    alert(result1);
    }).error(function(error){
        $scope.error = error; 
        $log.error('Its error from second functionssssssssss');
        });

/*$scope.getToken=function(){   
    $resource('https://api.att.com/oauth/token',{
        'client_id':'d3m1zlqukeyjctt5jj69jicwx4hxlpz9',
        'client_secret':'kzzwjdrvf3cugiiaycxbujqkwjfze782',
        'grant_type':'client_credentials','scope':'SPEECH'},
        {getOuth: {method: 'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'}}}).success(function(response){
            $scope.response = response;
            alert($scope.response);
        }).error(function(error){
            $scope.error = error;
            alert('error');
        }); 
};*/

    };              
}]);

这是用于调用这两个函数的两个按钮,首先单击第一个,然后单击第二个。

<div>
<button ng-click="getToken()"> click me for Access_token</button>
<br>
<button ng-click="getText()"> click me</button>
</div>

对于路由应用.js 使用

var MyApp=angular.module("MyApp",["MyApp.controller"]);
MyApp.config([ '$routeProvider', function ($routeProvider) {

    $routeProvider.when("/First",
            {
            templateUrl: 'partials/First.html',
            controller: 'FirstCtrl'
     });
    $routeProvider.otherwise({
        redirectTo: '/First'
    });
}]);

我的索引.html就像

<!DOCTYPE html>
<html  ng-app="MyApp">
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div ng-view></div>


    <script src="lib/angular/angular.js"></script>
    <script src="js/controller/MyCtrl.js"></script>
    <script src="js/routing/MyApp.js"></script>
</body>
</html>

angular http 数据不采用文件名并从中读取。 它需要一个字符串或可序列化的对象:

数据 – {字符串|对象} – 要作为请求消息数据发送的数据。查看以下链接以获取帮助:

http://uncorkedstudios.com/blog/multipartformdata-file-upload-with-angularjshttp://www.bennadel.com/blog/2615-posting-form-data-with-http-in-angularjs.htm

最新更新