simpleaudio
NOTE: THIS PROJECT IS ARCHIVED
2021年11月にアーカイブされた(メンテナンスしないと宣言)
numpy==1.22.2
simpleaudio==1.0.4
code:python
>> import numpy as np
>> import simpleaudio as sa
>> frequency = 440
>> fs = 44100
>> seconds = 3
>> t = np.linspace(0, seconds, seconds * fs, False)
>> type(t)
<class 'numpy.ndarray'>
>> t.shape
(132300,)
>> t.dtype
dtype('float64')
>> note = np.sin(frequency * t * 2 * np.pi)
>> note.shape
(132300,)
>> note.dtype
dtype('float64')
>> audio = note * (2**15 - 1) / np.max(np.abs(note))
>> audio.shape
(132300,)
>> audio.dtype
dtype('float64')
>> audio = audio.astype(np.int16)
>> # play_bufferを呼び出すと再生が始まる(再生中、対話モードは入力を受け付ける)
>> play_obj = sa.play_buffer(audio, 1, 2, fs)
>> # wait_doneを呼び出すと、対話モードは再生が終わるまで待つ
>> play_obj.wait_done()