-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
21 lines (20 loc) · 791 Bytes
/
test.py
File metadata and controls
21 lines (20 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import time, io
from google.cloud import speech
client = speech.Client.from_service_account_json(r'C:\Users\Leon\PycharmProjects\Wearhacks2\Prompt-voice-d17c3c6b865a.json')
with io.open("audio.raw", 'rb') as audio_file:
content = audio_file.read()
sample = client.sample(content=content,
encoding=speech.Encoding.LINEAR16,
sample_rate=44100)
operation = sample.async_recognize(max_alternatives=2)
retry_count = 100
while retry_count > 0 and not operation.complete:
retry_count -= 1
time.sleep(10)
operation.poll() # API call
print(operation.complete)
for result in operation.results:
for alternative in result.alternatives:
print('=' * 20)
print(alternative.transcript)
print(alternative.confidence)