Skip to content

Instantly share code, notes, and snippets.

@IuryAlves

IuryAlves/audio_device.py

Last active May 19, 2016
Embed
What would you like to do?
# 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