Skip to content

Commit

Permalink
Merge pull request #651 from kuzmoyev/master
Browse files Browse the repository at this point in the history
Comment out prints that shouldn't be printed by default
  • Loading branch information
ftnext authored Jan 12, 2023
2 parents ebb3a7e + 7379a84 commit 010382b
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions speech_recognition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,25 +893,20 @@ def recognize_google(self, audio_data, key=None, language="en-US", pfilter=0, sh
except URLError as e:
raise RequestError("recognition connection failed: {}".format(e.reason))
response_text = response.read().decode("utf-8")
# print('response_text:')
# pprint(response_text, indent=4)

# ignore any blank blocks
actual_result = []
for line in response_text.split("\n"):
if not line: continue
result = json.loads(line)["result"]
# print('result1:')
# pprint(result, indent=4)
result = json.loads(line)["result"]
if len(result) != 0:
actual_result = result[0]
break

# return results
if show_all:
return actual_result
print('result2:')
pprint(actual_result, indent=4)

if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()

if "confidence" in actual_result["alternative"]:
Expand Down Expand Up @@ -1124,8 +1119,6 @@ def recognize_azure(self, audio_data, key, language="en-US", profanity="masked",
result = json.loads(response_text)

# return results
print('result:')
pprint(result, indent=4)
if show_all:
return result
if "RecognitionStatus" not in result or result["RecognitionStatus"] != "Success" or "NBest" not in result:
Expand Down Expand Up @@ -1305,8 +1298,6 @@ def recognize_houndify(self, audio_data, client_id, client_key, show_all=False):

# return results
if show_all: return result
print('result:')
pprint(result, indent=4)
if "Disambiguation" not in result or result["Disambiguation"] is None:
raise UnknownValueError()
return result['Disambiguation']['ChoiceData'][0]['Transcription'], result['Disambiguation']['ChoiceData'][0]['ConfidenceScore']
Expand Down Expand Up @@ -1395,17 +1386,13 @@ def recognize_amazon(self, audio_data, bucket_name=None, access_key_id=None, sec
raise

job = status['TranscriptionJob']
print('status0:')
pprint(status, indent=4)
if job['TranscriptionJobStatus'] in ['COMPLETED'] and 'TranscriptFileUri' in job['Transcript']:

# Retrieve transcription JSON containing transcript.
transcript_uri = job['Transcript']['TranscriptFileUri']
import urllib.request, json
with urllib.request.urlopen(transcript_uri) as json_data:
d = json.load(json_data)
print('result:')
pprint(d, indent=4)
confidences = []
for item in d['results']['items']:
confidences.append(float(item['alternatives'][0]['confidence']))
Expand Down Expand Up @@ -1506,7 +1493,6 @@ def read_file(filename, chunk_size=5242880):
}
response = requests.get(endpoint, headers=headers)
data = response.json()
print('Raw response: %s' % data)
status = data['status']

if status == 'error':
Expand All @@ -1533,9 +1519,7 @@ def read_file(filename, chunk_size=5242880):
response = requests.post('https://api.assemblyai.com/v2/upload',
headers=headers,
data=read_file(audio_data))
print(response.json())
upload_url = response.json()['upload_url']
print('upload_url:', upload_url)

# Queue file for transcription.
endpoint = "https://api.assemblyai.com/v2/transcript"
Expand All @@ -1548,7 +1532,6 @@ def read_file(filename, chunk_size=5242880):
}
response = requests.post(endpoint, json=json, headers=headers)
data = response.json()
print(data)
transciption_id = data['id']
exc = TranscriptionNotReady()
exc.job_name = transciption_id
Expand Down Expand Up @@ -1595,8 +1578,6 @@ def recognize_ibm(self, audio_data, key, language="en-US", show_all=False):
# return results
if show_all:
return result
print('result:')
pprint(result, indent=4)
if "results" not in result or len(result["results"]) < 1 or "alternatives" not in result["results"][0]:
raise UnknownValueError()

Expand Down

0 comments on commit 010382b

Please sign in to comment.