Search code examples
audioraspberry-piadc

Read voice from Raspberry Pi values (ADC)


Hello I'm using ADC to read voice (from client 1) then I send it to a server from which client 2 can read it. I tried to register values I got in an array and read it through windows media player to be sure that sound is well recorded but I found nothing.

Any help please about which type of values should be in the file and how to read it well.

Values in the file are like this :

4163 87401 39840 34224 8410 39539 84134 34412 40238 93974 7434 41739 34023 83412 41742 73903 93374 40341 24264 2400 42041 4174 22406 40939 93884 8419 37041 73933 77410 40745 44044 2385 39440 74114 13405 43940 14244 4455 41836 23993 83435 36738 63964 11397 38140 74044 12366 38041 24034 31403 38938 13954 17407 42340 23883 79398 39644 34183 99391...


Solution

  • With Python you can try the following to convert the raw samples stored in text, to the wave file. Please note that you must know the sampling frequency of your signal and samples are assumed to be int16.

    from __future__ import print_function
    import scipy.io.wavfile as wavf
    import numpy as np
    from sys import argv
    
    def txt2wav(in_f, out_f, fs):
        txtdata = np.genfromtxt(in_f, dtype='int16')
        wavf.write(out_f, int(fs), txtdata)
    
    if __name__ == "__main__":
        if len(argv) != 4:
            print("usage: txt2wav.py input.txt out.wav samp_freq")
        elif len(argv) == 4:
            txt2wav(*argv[1:])