romanz / amodem

Audio MODEM Communication Library in Python
Other
950 stars 118 forks source link

Server side wav generation #21

Closed medouederni closed 8 years ago

medouederni commented 8 years ago

@romanz can I use this module to generate a wav file from a string ? I want to generate the wav file in a virtual machine in the cloud (without a sound card/system).

romanz commented 8 years ago

Generate PCM audio file:

$ amodem send -vv --audio-library=- --input=data.tx --output=audio.pcm
2016-03-10 19:20:31,384 DEBUG      Audio OFDM MODEM v1.13: 1.0 kb/s (2-QAM x 1 carriers) Fs=8.0 kHz                                     __main__.py:222
2016-03-10 19:20:31,405 INFO       Sending 0.800 seconds of training audio                                                              main.py:21
2016-03-10 19:20:31,405 INFO       Starting modulation                                                                                  main.py:26
2016-03-10 19:20:31,425 DEBUG      Sent      0.125 kB                                                                                   send.py:49
2016-03-10 19:20:31,444 DEBUG      Sent      0.250 kB                                                                                   send.py:49
2016-03-10 19:20:31,463 DEBUG      Sent      0.375 kB                                                                                   send.py:49
2016-03-10 19:20:31,482 DEBUG      Sent      0.500 kB                                                                                   send.py:49
2016-03-10 19:20:31,501 DEBUG      Sent      0.625 kB                                                                                   send.py:49
2016-03-10 19:20:31,520 DEBUG      Sent      0.750 kB                                                                                   send.py:49
2016-03-10 19:20:31,539 DEBUG      Sent      0.875 kB                                                                                   send.py:49
2016-03-10 19:20:31,559 DEBUG      Sent      1.000 kB                                                                                   send.py:49
2016-03-10 19:20:31,563 INFO       Sent 1.000 kB @ 8.201 seconds                                                                        main.py:31
2016-03-10 19:20:31,563 DEBUG      Finished I/O                                                                                         __main__.py:249

Set WAV header parameters:

$ sox -traw -c1 -esigned-integer -b16 -r8000 audio.pcm audio.wav  
$ ls -l audio.*
-rw-r--r-- 1 roman roman 148016 Mar 10 19:20 audio.pcm
-rw-r--r-- 1 roman roman 148060 Mar 10 19:20 audio.wav

Note that the sampling rate must match (Fs = 8.0 kHz ==> "-r8000" sox flag).

romanz commented 8 years ago

Also, note that the sampling rate changes for higher bitrates.