-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathw.py
30 lines (23 loc) · 881 Bytes
/
w.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from google.cloud import speech_v1p1beta1 as speech
from grpc._cython import cygrpc
client = speech.SpeechClient()
speech_file = "me.m4a"
first_lang = "en-US"
second_lang = "es"
with open(speech_file, "rb") as audio_file:
content = audio_file.read()
audio = speech.RecognitionAudio(content=content)
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=44100,
audio_channel_count=2,
language_code=first_lang,
alternative_language_codes=[second_lang],
)
print("Waiting for operation to complete...")
response = client.recognize(config=config, audio=audio)
for i, result in enumerate(response.results):
alternative = result.alternatives[0]
print("-" * 20)
print(u"First alternative of result {}: {}".format(i, alternative))
print(u"Transcript: {}".format(alternative.transcript))