Skip to content

Instantly share code, notes, and snippets.

@gmyrianthous
Created February 8, 2022 15:06
Show Gist options
  • Select an option

  • Save gmyrianthous/26f2ec5b7e4204e12a074b9ed301a459 to your computer and use it in GitHub Desktop.

Select an option

Save gmyrianthous/26f2ec5b7e4204e12a074b9ed301a459 to your computer and use it in GitHub Desktop.
Topic Detection with Python - Part 2
AUDIO_FILE = '/path/to/your/audio/file.mp3'
UPLOAD_ENDPOINT = 'https://api.assemblyai.com/v2/upload'
def read_audio_file(file):
"""Helper method that reads in audio files"""
with open(file, 'rb') as f:
while True:
data = f.read(5242880)
if not data:
break
yield data
res_upload = requests.post(
UPLOAD_ENDPOINT,
headers=headers,
data=read_audio_file(AUDIO_FILE)
)
upload_url = res_upload.json()['upload_url']
"""
Example response from AssemblyAI upload endpoint
pprint(res_upload.json())
{'upload_url': 'https://cdn.assemblyai.com/upload/b017e8c0-b31a-4d09-9dc2-8dee0ee0d3c8'}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment