Question

J'essaie d'utiliser le discours AT & T en SMS API.Jusqu'à présent, je peux obtenir le jeton d'accès

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

Jusqu'à présent, c'est ce que j'ai pour l'envoi du fichier audio pour obtenir la réponse 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'}

Mais je ne sais pas comment envoyer le fichier.Quelqu'un peut-il aider?

Était-ce utile?

La solution

C'est ce que je viens de travailler, en utilisant la bibliothèque de demandes et quelques autres ressources que je vais relier ci-dessous

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/bryssbrss/attspeechapi <

http://changegingjasper.blogspot.COM / 2014/06 / maquillage-jasper-user-at-thec-Api.html

L'utilisation est quelque chose comme ci-dessous, en supposant que vous avez enregistré ce fichier comme attengine

from ATTEngine import ATTSpeech
a = ATTSpeech()
a.text_from_file('/Users/issackelly/Desktop/here.wav')

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top