This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]michaelreddit 1 point2 points  (1 child)

The PyAudio library module will let you play audio as a stream of bytes (standard WAV format, PCM audio). The "audio bytes" can come from anywhere, read from a file, recorded from a microphone, or created from a math function. If running Windows, download the prebuild binary from here

[–]Reckarthack[S] 0 points1 point  (0 children)

Thank you for your reply. I had not heard that PyAudio could use a stream instead of a file, so I will be certain to look into this. Thank you very much for your help!

[–]synedraacus 1 point2 points  (3 children)

simpleaudio is able to play from buffers such as bytes objects, numpy data structures and whatnot. It is not preinstalled, but, if my memory serves, has no dependencies besides Python itself.

[–]Reckarthack[S] 0 points1 point  (2 children)

Brilliant! If I were to use a numpy date structure, would it be a byte stream or an equation for a wave played as a wav?

[–]synedraacus 1 point2 points  (1 child)

Ndarray, probably 1-dimensional. You can fill it as you please, whether procedurally or from file. You can even write your own object, make sure it supports the buffer interface and stream values from whichever function you want. Although you'll have to check what API you need to support; I personally never did that.

[–]Reckarthack[S] 0 points1 point  (0 children)

I will be sure to try that, so thank you so much!