in wearable/main.py [0:0]
def transcribe_audio(file: str) -> str:
# Use the credentials to authenticate your API request
headers = {
"Authorization": f"Bearer {get_token()}",
"Content-Type": "application/json",
}
# Speech recognition API endpoint
url = urlunparse(
URLComponents(
netloc="speech.googleapis.com",
path=["v1", "speech:recognize"],
).to_tuple()
)
# Sample request data
data = {
"config": {"languageCode": "en-US"},
"audio": {"content": encode_audio(file)},
}
# Make the API request
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()["results"][0]["alternatives"][0]["transcript"]