mirror of
https://github.com/romanz/amodem.git
synced 2026-04-20 21:26:39 +08:00
switch to PyAudio package for portability
This commit is contained in:
@@ -1,32 +1,33 @@
|
||||
from amodem import audio
|
||||
import subprocess as sp
|
||||
import signal
|
||||
from amodem import config
|
||||
|
||||
import mock
|
||||
|
||||
|
||||
def test_launch():
|
||||
p = audio.ALSA(tool='true', Fs=32000).launch()
|
||||
assert p.wait() == 0
|
||||
def test_pyaudio_mock():
|
||||
m = mock.Mock()
|
||||
m.paInt16 = 8
|
||||
m.PyAudio.return_value = m
|
||||
m.open.return_value = m
|
||||
|
||||
cfg = config.fastest()
|
||||
interface = audio.Interface(config=cfg, library=m)
|
||||
recorder = interface.recorder()
|
||||
n = 1024
|
||||
data = recorder.read(n)
|
||||
|
||||
def test_exit():
|
||||
p = audio.ALSA(tool='python', Fs=32000).launch(fname='-', stdin=sp.PIPE)
|
||||
s = b'import sys; sys.exit(42)'
|
||||
p.stdin.write(s)
|
||||
p.stdin.close()
|
||||
assert p.wait() == 42
|
||||
data = '\x00' * n
|
||||
player = interface.player()
|
||||
player.write(data)
|
||||
|
||||
|
||||
def test_io():
|
||||
p = audio.ALSA(tool='python', Fs=32000)
|
||||
p = p.launch(fname='-', stdin=sp.PIPE, stdout=sp.PIPE)
|
||||
s = b'Hello World!'
|
||||
p.stdin.write(b'print("' + s + b'")\n')
|
||||
p.stdin.close()
|
||||
assert p.stdout.read(len(s)) == s
|
||||
|
||||
|
||||
def test_kill():
|
||||
p = audio.ALSA(tool='python', Fs=32000)
|
||||
p = p.launch(fname='-', stdin=sp.PIPE, stdout=sp.PIPE)
|
||||
p.kill()
|
||||
assert p.wait() == -signal.SIGKILL
|
||||
kwargs = dict(
|
||||
channels=1, frames_per_buffer=cfg.samples_per_buffer,
|
||||
rate=cfg.Fs, format=m.paInt16
|
||||
)
|
||||
assert m.mock_calls == [
|
||||
mock.call.PyAudio(),
|
||||
mock.call.open(input=True, **kwargs),
|
||||
mock.call.read(n // cfg.sample_size),
|
||||
mock.call.open(output=True, **kwargs),
|
||||
mock.call.write(data)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user