Created
March 26, 2019 23:33
-
-
Save deivguerrero/51124c6cd6ad3750e9ac89127746699b to your computer and use it in GitHub Desktop.
Script que obtiene la transcripción de un audio alojado en Cloud Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import audioread | |
from google.cloud import speech | |
from google.cloud.speech import enums | |
from google.cloud.speech import types | |
AUDIO_CHANNELS = 2 | |
AUDIO_RATE = 16000 | |
BLOB_PATH = "audio.flac" | |
BUCKET_NAME = "audio-devlife" | |
LANG_CODE = 'es-MX' | |
with audioread.audio_open(BLOB_PATH) as f: | |
AUDIO_CHANNELS = int(f.channels) | |
AUDIO_RATE = int(f.samplerate) | |
gcs_uri = "gs://{}/{}".format(BUCKET_NAME, BLOB_PATH) | |
client = speech.SpeechClient() | |
audio = types.RecognitionAudio(uri=gcs_uri) | |
config = types.RecognitionConfig( | |
encoding=enums.RecognitionConfig.AudioEncoding.FLAC, | |
language_code=LANG_CODE, | |
audio_channel_count=AUDIO_CHANNELS, | |
enable_separate_recognition_per_channel=True) | |
operation = client.long_running_recognize(config, audio) | |
response = operation.result() | |
for result in response.results: | |
for alternative in result.alternatives: | |
print('=' * 20) | |
print(alternative.transcript) | |
print(alternative.confidence) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment