Exemplo n.º 1
0
            def __call__(self, data):
                try:
                    for i in range(self.retries):
                        url = GOOGLE_SPEECH_API_URL.format(lang=self.language,
                                                           key=self.api_key)
                        headers = {
                            "Content-Type": "audio/x-flac; rate=%d" % self.rate
                        }

                        try:
                            resp = requests.post(url,
                                                 data=data,
                                                 headers=headers)
                        except requests.exceptions.ConnectionError:
                            continue

                        for line in resp.content.split("\n"):
                            try:
                                line = json.loads(line)
                                return line['result'][0]['alternative'][0][
                                    'transcript'].capitalize()
                            except:
                                # no result
                                continue

                except KeyboardInterrupt:
                    return
Exemplo n.º 2
0
    def __call__(self, data):
        try:
            for i in range(self.retries):
                url = GOOGLE_SPEECH_API_URL.format(lang=self.language,
                                                   key=self.api_key)
                headers = {"Content-Type": "audio/x-flac; rate=%d" % self.rate}

                try:
                    http_proxy = "http://127.0.0.1:10801"
                    proxyDict = {"http": http_proxy}
                    resp = requests.post(url,
                                         data=data,
                                         headers=headers,
                                         proxies=proxyDict)
                except requests.exceptions.ConnectionError:
                    continue

                for line in resp.content.split("\n"):
                    try:
                        line = json.loads(line)
                        line = line['result'][0]['alternative'][0][
                            'transcript']
                        return line[:1].upper() + line[1:]
                    except:
                        # no result
                        continue

        except KeyboardInterrupt:
            return
Exemplo n.º 3
0
    def __call__(self, data):
        try:
            for _ in range(self.retries):
                url = GOOGLE_SPEECH_API_URL.format(lang=self.language,
                                                   key=self.api_key)
                headers = {"Content-Type": "audio/x-flac; rate=%d" % self.rate}

                try:
                    resp = requests.post(url, data=data, headers=headers)
                except requests.exceptions.ConnectionError:
                    continue

                for line in resp.content.decode(encoding='UTF-8').split("\n"):
                    try:
                        line = json.loads(line)
                        line = line['result'][0]['alternative'][0][
                            'transcript']
                        return line[:1].upper() + line[1:]
                    except IndexError:
                        # no result
                        continue
                    except JSONDecodeError:
                        continue

        except KeyboardInterrupt:
            return None
Exemplo n.º 4
0
    def __call__(self, data):
        try:
            #print(self.proxy['use'])
            #print(self.proxy['http'])
            for i in range(self.retries):
                url = GOOGLE_SPEECH_API_URL.format(lang=self.language,
                                                   key=self.api_key)
                headers = {"Content-Type": "audio/x-flac; rate=%d" % self.rate}

                try:
                    if self.proxy['use']:
                        #print("Use a proxy server")
                        resp = requests.post(url,
                                             data=data,
                                             headers=headers,
                                             proxies=self.proxy)
                    else:
                        #print("Do not use a proxy server")
                        resp = requests.post(url, data=data, headers=headers)
                except requests.exceptions.ConnectionError:
                    continue

                for line in resp.content.split("\n"):
                    try:
                        line = json.loads(line)
                        line = line['result'][0]['alternative'][0][
                            'transcript']
                        return line[:1].upper() + line[1:]
                    except:
                        # no result
                        continue

        except KeyboardInterrupt:
            return