示例#1
0
#!/usr/bin/env python
"""
Simplest demo of using PySoundDevice to playback audio from Python
https://www.scivision.dev/playing-sounds-from-numpy-arrays-in-python/

python -m pip install sounddevice

http://python-sounddevice.readthedocs.io/en/latest/#usage
"""
import sounddevice
from time import sleep
from pyimagevideo import dialtone

fs = 8000  # Hz
T = 1

x = (dialtone(fs, T) * 32768).astype('int16')  # scale to int16 for sound card

sounddevice.play(x, fs)  # releases GIL


sleep(T)  # NOTE: Since sound playback is async, allow sound playback to finish before Python exits
示例#2
0
#!/usr/bin/env python
"""
this doesn't current work with Oct2Py
"""
import numpy as np
from oct2py import Oct2Py
from pyimagevideo import dialtone

fs = 8000 # Hz

x  = (dialtone(fs)*32768).astype(np.int16)  # scale to int16 for sound card

with Oct2Py() as oc:
#    print(oc.audiodevinfo())
    a = oc.audioplayer(x,fs)
    oc.play(a)