4

Context: I have a URL for a recorded audio stream which is originally in OGG_OPUS format. I am converting it the audio from URL into a byte stream (as required by Google API - https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionAudio).

When I provide this byte-stream into Google Speech-to-text API, I am receiving a null response !!

Question:

  1. Why is Google API returing a Null response here?
  2. Does Google API really support OGG_OPUS format for audio input?

Code Block

import time
from urllib.request import urlopen
from io import BytesIO
import requests
import base64

# Imports the Google Cloud client library
from google.cloud import speech

# Instantiates a client
client = speech.SpeechClient()
url = "https://drive.google.com/file/d/1zlJaptJYJe0ge_SkpB52N6uRTsEKUGG4/view?usp=sharing"

response  = requests.get(url,stream=True)
output = base64.b64encode(BytesIO(response.content).read())

audio = speech.RecognitionAudio(content=output)

config = speech.RecognitionConfig(
   encoding=speech.RecognitionConfig.AudioEncoding.OGG_OPUS,
   sample_rate_hertz=16000,
   language_code="en-US",
)

# Detects speech in the audio file
response = client.recognize(config=config, audio=audio)
print("response: ", response)
'''
Piyush Makhija
  • 304
  • 2
  • 11

0 Answers0