This file contains 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
# Let's process only mp3 files | |
if storage_uri[-4:] ==".mp3": | |
client = speech_v1p1beta1.SpeechClient() | |
# Sample rate in Hertz of the audio data sent | |
sample_rate_hertz = 8000 | |
# The language of the supplied audio | |
language_code = "en-US" | |
model = "phone_call" | |
# Encoding of audio data sent. This sample sets this explicitly. | |
# This field is optional for FLAC and WAV audio formats. | |
encoding = enums.RecognitionConfig.AudioEncoding.MP3 | |
config = { | |
"sample_rate_hertz": sample_rate_hertz, | |
"language_code": language_code, | |
"encoding": encoding, | |
"model": model, | |
"use_enhanced": True, | |
"enable_automatic_punctuation": True, | |
"enable_speaker_diarization": True, | |
"diarization_speaker_count": 2, | |
"speech_contexts": [{ | |
"phrases": ["Thank you for calling ABC", | |
"Thank you for contacting ABC", | |
"Welcome to ABC", | |
"ABC customer service", | |
"Thank you for calling ABC customer support."] | |
}] | |
} | |
audio = {"uri": storage_uri} | |
operation = client.long_running_recognize(config, audio) | |
#print(u"Waiting for operation to complete...") | |
response = operation.result() | |
transcript = "" | |
transcriptw = "" | |
sendtrans = False | |
keyword = "Empty Audio" | |
speaker = "" | |
for result in response.results: | |
words_info = result.alternatives[0].words | |
for word_info in words_info: | |
if str(word_info.speaker_tag) != "0": | |
if str(word_info.speaker_tag) != str(speaker): | |
#print(str(word_info.speaker_tag) + " is not " + str(speaker)) | |
speaker = str(word_info.speaker_tag) | |
transcriptw = transcriptw + "\n-------\n*Speaker " + speaker + ":* " + word_info.word | |
else: | |
#print(str(word_info.speaker_tag) + " is " + speaker) | |
transcriptw = transcriptw + " " + word_info.word | |
speaker = str(word_info.speaker_tag) | |
sendtrans = False | |
keyword = "Empty Audio" | |
print(transcriptw) | |
if transcriptw.strip() == "": | |
transcriptw = "*No Sound*" | |
sendtrans = True | |
else: | |
list = ["bitcoin","payment", "invoice", "bill", "utilities", "utility", "electricity", "credit card", "package", "testing","kits","financial", "supplies", "mask", "symptoms", "isolate","oxygen","ventilator","social security","government","internal revenue","covid", "world health", "national institute", "virus", "corona","quarantine","stimulus","relief","cdc","disease","pandemic","epidemic","sickness"] | |
# Using for loop | |
for i in list: | |
if i.lower() in transcriptw.lower(): | |
keyword = i.lower() | |
sendtrans = True | |
break | |
if sendtrans == True: | |
print(f"Sending to Slack: {file['name']}.") | |
filename = file['name'] | |
send_slack(transcript.strip(),filename,keyword) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment