Skip to content

Instantly share code, notes, and snippets.

@JosXa
Last active May 3, 2017 22:36
Show Gist options
  • Save JosXa/9368a9cfa4707f8b1b34744c67ab08c2 to your computer and use it in GitHub Desktop.
Save JosXa/9368a9cfa4707f8b1b34744c67ab08c2 to your computer and use it in GitHub Desktop.
Sending an audio file without actually downloading it to hard disk
def some_handler(bot, update):
chat_id = update.message.chat_id
import urllib.request
import io
url = "https://talkpython.fm/episodes/download/110/data-democratization-with-redash.mp3"
response = urllib.request.urlopen(url)
bytestring = response.read() # a `bytes` object
file_like_object = io.BytesIO(bytestring) # convert `bytes` to file-like object
bot.sendAudio(chat_id, file_like_object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment