Created
May 24, 2019 23:59
-
-
Save kjaymiller/a763d12519f7033c0c09c50ba78217e5 to your computer and use it in GitHub Desktop.
PIT Transcription Tool
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
from google.cloud import speech | |
from google.cloud.speech import enums | |
from google.cloud.speech import types | |
from google.cloud.storage import Blog | |
import sys | |
speech_client = speech.SpeechClient() | |
base_uri = sys.argv[1] | |
audio = types.RecognitionAudio(uri=base_uri) | |
config = types.RecognitionConfig( | |
encoding=enums.RecognitionConfig.AudioEncoding.FLAC, | |
language_code='en-GB') | |
operation = speech_client.long_running_recognize(config, audio) | |
audio_lines = [] | |
response = operation.result() | |
for result in response.results: | |
script = result.alternatives | |
confidence = script[0].confidence | |
if len(script) > 1: | |
alternatives = '; '.join(result.alternatives[1:]) | |
else: | |
alternatives = 'No Alternatives' | |
message = f'{script[0]} :Confidence:{confidence} Alternatives: {alternatives}' | |
audio_lines.append(message) | |
transcript = '\n'.join(audio_lines) | |
with open(f'transcript_{base_uri}', 'w') as transcript_file: | |
transcript_file.write(transcript) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment