将att speech api的输出作为“语音未被识别”

时间:2014-01-07 10:50:49

标签: angularjs post speech-to-text

这是我的控制器(MyCltr.js)它首先获得了两个函数来获取一个令牌,第二个用于将音频文件发布到语音api,但是当第二个函数被调用时,json形式的响应是

{“识别”:{“信息”:{“指标”:{“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>

1 个答案:

答案 0 :(得分:0)

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

data - {string | Object} - 要作为请求消息数据发送的数据。查看这些链接以获取帮助:

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