Skip to content

Instantly share code, notes, and snippets.

@mouseos
Last active March 12, 2022 12:31
Show Gist options
  • Save mouseos/c66154199c2b118809a40dd36644a9de to your computer and use it in GitHub Desktop.
Save mouseos/c66154199c2b118809a40dd36644a9de to your computer and use it in GitHub Desktop.
import wave
import time
#ffmpeg -i test.ogg -vn -ar 44100 -ac 2 test.wavしておく
#ffplay output -ar 44.1k -ac 2 -f s16leで再生
#ffmpeg -ar 44.1k -ac 2 -f s16le -i output out.wavで録音
wf = wave.open('test.wav', mode='rb')
#事前にmkfifo outputしておく
owf= open('output', 'w+b', 0)
frames=int(wf.getnframes())
for i in range(int(frames/8)):
data=(wf.readframes(8) )
print(data)
owf.write(data)
time.sleep(1/44100)
while True:#音声がない場合に無音を書き込む処理
owf.write(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
time.sleep(1/44100)
@mouseos
Copy link
Author

mouseos commented Mar 12, 2022

  • fifoにPCM signed 16-bit little-endianを送る。再生後は無音を送信。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment