简体   繁体   中英

How To Play Back Certain Parts Of A WAV File Depending On Incoming Data?

I am making a program that reads various data from a car, live.

While my Raspberry Pi 3 B+ does this over Bluetooth, it needs to read a wav file and play a certain parts depending on the RPM. But I don't know how to reference certain parts of the wav file using the RPM.

Anyone have any ideas?

You could use Python's included wav module to read the wave file and then, say, wav_read.setpos to set the position in the file (in bytes) and read the file from there.

Or, if you want to install it, pydub is higher level, and everything will be a bit easier, for example, you can use standard slice notation to specify a part of the file using milliseconds.

Once you have the part of the file, you could use a tool like pyaudio to play the data directly from your program, or you could write out a new file and make a system call from Python to play that new file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM