문제

AT & T 음성을 텍스트 API로 사용하려고합니다.지금까지 나는 액세스 토큰을 얻을 수 있습니다

def get_access_token(client_id, client_secret):
headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json'}

data = {'client_id': client_id, 'client_secret': client_secret, 'scope': 'SPEECH',
        'grant_type': 'client_credentials'}

response = requests.post(oauth_url, data=data, headers=headers)
return response.text
.

지금까지는 JSON 응답을 얻기 위해 오디오 파일을 보내는 것입니다.

def get_text_from_file(file, access_token):
headers = {'Authorization': 'Bearer ' + access_token, 'Accept': 'application/json', 'Content-Type': 'audio/wav',
           'X-SpeechContext': 'Generic', 'Connection': 'Keep-Alive'}
.

그러나 파일을 보내는 방법을 모르겠습니다.누구도 도움이 될 수 있습니까?

도움이 되었습니까?

해결책

방금 작업하는 것, 요청 라이브러리를 사용하는 것과 몇 가지 다른 리소스를 사용하여

아래 링크 할 수 있습니다.
import json
import requests

class ATTSpeech:
    CLIENT_ID = "SOME"
    CLIENT_SECRET = "ID"
    TOKEN = None

    def __init__(self, *args, **kwargs):
        self.get_token()


    def get_token(self):
        # Get Access Token via OAuth.
        # https://matrix.bf.sl.attcompute.com/apps/constellation-sandbox
        response = requests.post("https://api.att.com/oauth/token", {
            "client_id": self.CLIENT_ID,
            "client_secret": self.CLIENT_SECRET,
            "grant_type": "client_credentials",
            "scope": "SPEECH,STTC"
        })
        content = json.loads(response.content)
        self.TOKEN = content["access_token"]


    def text_from_file(self, path):

        with open(path, 'rb') as f:
            response = requests.post("https://api.att.com/speech/v3/speechToText",
                headers = {
                    "Authorization": "Bearer %s" % self.TOKEN,
                    "Accept": "application/json",
                    "Content-Type": "audio/wav",
                    "X-SpeechContext": "Generic",
            }, data=f)
        content = json.loads(response.content)
        return content
.

https://sites.google.com/site/brssbrss/attspeechapi <./ P>

http : //changingjasper.blogspot.COM / 2014 / 06 / Jasper-USE-AT-SPEEP-API.HTML

사용법은 아래와 같습니다.

에이 파일을 저장했습니다.
from ATTEngine import ATTSpeech
a = ATTSpeech()
a.text_from_file('/Users/issackelly/Desktop/here.wav')
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top