amsehili / auditok

An audio/acoustic activity detection and audio segmentation tool
MIT License
745 stars 96 forks source link

Callback data format #12

Closed dcam0050 closed 6 years ago

dcam0050 commented 7 years ago

Hi I'm using auditok to segment sentences from speech and I would like to convert the data returned in the callback into an int16 wav format for use with a different application. Could you tell me how I could go about doing that?

amsehili commented 7 years ago

Hi there, If you need to run your other command every time a new utterance is detected you can use -C option in the command line:

auditok [args] -C "sox -t raw -r 16000 -c 1 -b 16 -e signed $ -r 16000 -b 16 audio.wav ; your_command audio.wav"

This will call sox (which you need to install) to write audio data as a wav file (named audio.wav) then call your external program, giving it audio.wav as an argument.

Note that the first -r option in the sox command refers to you input data, hence it can have a different value (e.g., 32000, 44100, etc., anyway this must be your the sampling rate of your input data) whereas the the second -r is used for your output file and should be what you application expects (here 16000 but it can be another value). The second -b however must always be 16 as you want your wav file to be 16-bit.