zellostream icon indicating copy to clipboard operation
zellostream copied to clipboard

How to stream pre-record audio file ?

Open cevo2022 opened this issue 2 years ago • 2 comments

Thank you for wonderful code. It work perfectly. However I curious on how to let this code broadcast pre-recorded audio file?

cevo2022 avatar Jul 22 '22 17:07 cevo2022

Right now the source of the audio in the code is 60ms chunks of audio from the sound card here:

data = record(.06)

To send from a file, you'd probably want to instead use the Python wave module to read in the data from the file, and then iterate over it in 60 ms increments:

First call zello_ws = create_zello_connection() and start_stream(zello_ws), then iterate over the audiofile and in each iteration, encode the 60 ms chunk to opus format and then send it using zello_ws.send_binary. Then when done iterating over the file, call stop_stream and zello_ws.close().

For simplicity (least amount of code changes) you'd want the .wav file to be the same format and sampling rate as what the script is currently getting from the sound card - 16 bit mono at 16 kHz sampling rate.

aaknitt avatar Jul 23 '22 02:07 aaknitt

Can you provide some fully working code?

On Sat, Jul 23, 2022, 09:59 Andy Knitt @.***> wrote:

Right now the source of the audio in the code is 60ms chunks of audio from the sound card here:

data = record(.06)

To send from a file, you'd probably want to instead use the Python wave https://docs.python.org/3/library/wave.html module to read in the data from the file, and then iterate over it in 60 ms increments:

First call zello_ws = create_zello_connection() and start_stream(zello_ws), then iterate over the audiofile and in each iteration, encode the 60 ms chunk to opus format and then send it using zello_ws.send_binary. Then when done iterating over the file, call stop_stream and zello_ws.close().

For simplicity (least amount of code changes) you'd want the .wav file to be the same format and sampling rate as what the script is currently getting from the sound card - 16 bit mono at 16 kHz sampling rate.

— Reply to this email directly, view it on GitHub https://github.com/aaknitt/zellostream/issues/10#issuecomment-1193045622, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2F3IKJKSQCUPG546JFDRQTVVNNZZANCNFSM54MGZKCA . You are receiving this because you authored the thread.Message ID: @.***>

cevo2022 avatar Jul 23 '22 03:07 cevo2022