2014-01-07 40 views
0

这个我控制器(MyCltr.js)它得到了前两个功能,让接取令牌和第二张贴音频文件,语音API,但是当第二函数被调用json形式的响应是充分利用AT&T的语音API输出为“无法识别语音”

{“Recognition”:{“Info”:{“Metrics”:{“AudioBytes”:0,“AudioTime”:0}},“ResponseId”:“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> 

用于路由app.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> 

回答