pyaudio bytes data to librosa floating point time series












0















when audio is recording using pyaudio with paInt16, it gives me 16 bits integer represented as two bytes. With some studying, I concluded that it must be # between -32768 to 32767.



I saved audio as wav file and load it back with librosa.core.load.
I did retrieved float value * 32767 and see whether it generates original 16bits integer but it was not matching at all.



My questions are




  1. Where is this mismatch coming from??

  2. is original 16-bit integer data represents frequency?

  3. librosa doc state that load function returns floating point time series. how do you calculate this value from the original 16-bit integer?










share|improve this question























  • How doc you compare the data? By default librosa resamples to 22050Hz, so if you are comparing raw values for the frames, they will not match at all.

    – jonnor
    Dec 5 '18 at 2:17











  • Scaling the int16 data by dividing by 32767 should make it be on the expected format of librosa. But pay attention to samplerate, pass in the value that pyaudio gives you

    – jonnor
    Dec 5 '18 at 2:19
















0















when audio is recording using pyaudio with paInt16, it gives me 16 bits integer represented as two bytes. With some studying, I concluded that it must be # between -32768 to 32767.



I saved audio as wav file and load it back with librosa.core.load.
I did retrieved float value * 32767 and see whether it generates original 16bits integer but it was not matching at all.



My questions are




  1. Where is this mismatch coming from??

  2. is original 16-bit integer data represents frequency?

  3. librosa doc state that load function returns floating point time series. how do you calculate this value from the original 16-bit integer?










share|improve this question























  • How doc you compare the data? By default librosa resamples to 22050Hz, so if you are comparing raw values for the frames, they will not match at all.

    – jonnor
    Dec 5 '18 at 2:17











  • Scaling the int16 data by dividing by 32767 should make it be on the expected format of librosa. But pay attention to samplerate, pass in the value that pyaudio gives you

    – jonnor
    Dec 5 '18 at 2:19














0












0








0








when audio is recording using pyaudio with paInt16, it gives me 16 bits integer represented as two bytes. With some studying, I concluded that it must be # between -32768 to 32767.



I saved audio as wav file and load it back with librosa.core.load.
I did retrieved float value * 32767 and see whether it generates original 16bits integer but it was not matching at all.



My questions are




  1. Where is this mismatch coming from??

  2. is original 16-bit integer data represents frequency?

  3. librosa doc state that load function returns floating point time series. how do you calculate this value from the original 16-bit integer?










share|improve this question














when audio is recording using pyaudio with paInt16, it gives me 16 bits integer represented as two bytes. With some studying, I concluded that it must be # between -32768 to 32767.



I saved audio as wav file and load it back with librosa.core.load.
I did retrieved float value * 32767 and see whether it generates original 16bits integer but it was not matching at all.



My questions are




  1. Where is this mismatch coming from??

  2. is original 16-bit integer data represents frequency?

  3. librosa doc state that load function returns floating point time series. how do you calculate this value from the original 16-bit integer?







audio wav pyaudio librosa






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 20:24









Brandon LeeBrandon Lee

676




676













  • How doc you compare the data? By default librosa resamples to 22050Hz, so if you are comparing raw values for the frames, they will not match at all.

    – jonnor
    Dec 5 '18 at 2:17











  • Scaling the int16 data by dividing by 32767 should make it be on the expected format of librosa. But pay attention to samplerate, pass in the value that pyaudio gives you

    – jonnor
    Dec 5 '18 at 2:19



















  • How doc you compare the data? By default librosa resamples to 22050Hz, so if you are comparing raw values for the frames, they will not match at all.

    – jonnor
    Dec 5 '18 at 2:17











  • Scaling the int16 data by dividing by 32767 should make it be on the expected format of librosa. But pay attention to samplerate, pass in the value that pyaudio gives you

    – jonnor
    Dec 5 '18 at 2:19

















How doc you compare the data? By default librosa resamples to 22050Hz, so if you are comparing raw values for the frames, they will not match at all.

– jonnor
Dec 5 '18 at 2:17





How doc you compare the data? By default librosa resamples to 22050Hz, so if you are comparing raw values for the frames, they will not match at all.

– jonnor
Dec 5 '18 at 2:17













Scaling the int16 data by dividing by 32767 should make it be on the expected format of librosa. But pay attention to samplerate, pass in the value that pyaudio gives you

– jonnor
Dec 5 '18 at 2:19





Scaling the int16 data by dividing by 32767 should make it be on the expected format of librosa. But pay attention to samplerate, pass in the value that pyaudio gives you

– jonnor
Dec 5 '18 at 2:19












1 Answer
1






active

oldest

votes


















0














After studying and exploring the librosa code, here are my findings.




  1. The mismatch comes from the fact that wav byte array is little endian


  2. The representation is called Pulse-code modulation(PCM). Each sample (single integer) represents the magnitude of audio scaled to the range of prespecified bit range, (usually 16 bits). refer audio bit depth for detail


  3. Given PCM is 16 bits representation, each sample has a range of [-32768, 32767]. librosa simply transform 16 bits into signed short and divide by 32768 (not 32767!) to scale down to [-1, 1] range. please refer to my sample code for exact conversion







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462062%2fpyaudio-bytes-data-to-librosa-floating-point-time-series%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    After studying and exploring the librosa code, here are my findings.




    1. The mismatch comes from the fact that wav byte array is little endian


    2. The representation is called Pulse-code modulation(PCM). Each sample (single integer) represents the magnitude of audio scaled to the range of prespecified bit range, (usually 16 bits). refer audio bit depth for detail


    3. Given PCM is 16 bits representation, each sample has a range of [-32768, 32767]. librosa simply transform 16 bits into signed short and divide by 32768 (not 32767!) to scale down to [-1, 1] range. please refer to my sample code for exact conversion







    share|improve this answer




























      0














      After studying and exploring the librosa code, here are my findings.




      1. The mismatch comes from the fact that wav byte array is little endian


      2. The representation is called Pulse-code modulation(PCM). Each sample (single integer) represents the magnitude of audio scaled to the range of prespecified bit range, (usually 16 bits). refer audio bit depth for detail


      3. Given PCM is 16 bits representation, each sample has a range of [-32768, 32767]. librosa simply transform 16 bits into signed short and divide by 32768 (not 32767!) to scale down to [-1, 1] range. please refer to my sample code for exact conversion







      share|improve this answer


























        0












        0








        0







        After studying and exploring the librosa code, here are my findings.




        1. The mismatch comes from the fact that wav byte array is little endian


        2. The representation is called Pulse-code modulation(PCM). Each sample (single integer) represents the magnitude of audio scaled to the range of prespecified bit range, (usually 16 bits). refer audio bit depth for detail


        3. Given PCM is 16 bits representation, each sample has a range of [-32768, 32767]. librosa simply transform 16 bits into signed short and divide by 32768 (not 32767!) to scale down to [-1, 1] range. please refer to my sample code for exact conversion







        share|improve this answer













        After studying and exploring the librosa code, here are my findings.




        1. The mismatch comes from the fact that wav byte array is little endian


        2. The representation is called Pulse-code modulation(PCM). Each sample (single integer) represents the magnitude of audio scaled to the range of prespecified bit range, (usually 16 bits). refer audio bit depth for detail


        3. Given PCM is 16 bits representation, each sample has a range of [-32768, 32767]. librosa simply transform 16 bits into signed short and divide by 32768 (not 32767!) to scale down to [-1, 1] range. please refer to my sample code for exact conversion








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 6 '18 at 17:13









        Brandon LeeBrandon Lee

        676




        676
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462062%2fpyaudio-bytes-data-to-librosa-floating-point-time-series%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            To store a contact into the json file from server.js file using a class in NodeJS

            Redirect URL with Chrome Remote Debugging Android Devices

            Dieringhausen