Skip to content

Instantly share code, notes, and snippets.

@IuryAlves
Last active May 19, 2016 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IuryAlves/d3c28a5d5acd0a923e9d946ff9ffacd8 to your computer and use it in GitHub Desktop.
Save IuryAlves/d3c28a5d5acd0a923e9d946ff9ffacd8 to your computer and use it in GitHub Desktop.
# coding: utf-8
"""
Instale:
pip install sounddevice
pip install soundfile
baixe esse arquivo de audio e renomeie para: audio.ogg
https://upload.wikimedia.org/wikipedia/en/9/9f/Sample_of_%22Another_Day_in_Paradise%22.ogg
"""
import sounddevice as sd
import soundfile as sf
# todos dispositivos de audio
devices = sd.query_devices(kind='output')
# abre um arquivo de audio
data, fs = sf.read('audio.ogg', dtype='float32')
# pulse audio on my system
selected_device = devices[6]['name'].encode("utf-8")
# toca o audio
# device precisa ser uma string, com unicode não funciona.
sd.play(data, blocking=True, device=selected_device)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment