Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Accept audio at 16khz , 16bit via USB.

  1. #1
    Junior Member
    Join Date
    Jul 2020
    Location
    India
    Posts
    3

    Accept audio at 16khz , 16bit via USB.

    I am working on some voice recognition based projects and my machine learning model only accepting 16khz sample rate data(Model limitations).

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    
    // GUItool: begin automatically generated code
    AudioInputAnalog         adc1;           //xy=133,142
    AudioEffectBitcrusher    bitcrusher1;    //xy=354,165
    AudioOutputUSB           usb1;           //xy=605,218
    AudioConnection          patchCord1(adc1, bitcrusher1);
    AudioConnection          patchCord2(bitcrusher1, 0, usb1, 1);
    AudioConnection          patchCord3(bitcrusher1, 0, usb1, 0);
    // GUItool: end automatically generated code
    int current_CrushBits = 16; //this defaults to passthrough.
    int current_SampleRate = 16000; // this defaults to passthrough.
    
    void setup() {
      delay(1000);
      Serial.begin(9600);
      AudioMemory(8);
      bitcrusher1.bits(current_SampleRate);
      bitcrusher1.sampleRate(current_SampleRate);
    
    }
    
    void loop() {
    
    }
    This code is to send audio from analog pin to USB and it is working perfectly.

    Now the query is, whenever I change Sample rate frequency from 44100 to 16000 according to this thread
    streaming of sound stopped working.

    So can someone help to find a solution for transmitting sound from analog pin to USB at the 16khz sample rate?

    Thank you for your support.

  2. #2
    Senior Member
    Join Date
    Jan 2020
    Location
    Toscana
    Posts
    129
    Up to now USB audio is 16bit 44.1kHz only.
    If using a Windows computer, this will connect to Microsoft Soundmapper, which does resampling if necessary. An app connecting to the Teensy needs to use Soundmapper if different than default samplerate is required.
    WASAPI and ASIO will not work due to the way Teensy USB audio is made.

  3. #3
    Junior Member
    Join Date
    Jul 2020
    Location
    India
    Posts
    3
    Dear flashburn, Thank you for your quick replay.

    My voice recognition-based app is dynamic. It can run on raspberry pi and Ubuntu, So can you explain possible options for Linux systems?

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    320
    16kHz is every 3rd sample from 48kSPS, which is a standard rate supported by all I2S hardware, although not
    supported out of the box for Audio library. Don't see why simple resampling can't be done in your front end?
    Low pass filter and decimate by 3 ought to work even with 44.1kSPS as the absolute pitch of speech isn't critical?

  5. #5
    Junior Member
    Join Date
    Jul 2020
    Location
    India
    Posts
    3
    Dear MarkT, Thank you for your quick replay.

    I also developed python code using PyAudio and Sample rate library, but the problem is a delay. My python code not able to work in real-time. In that scenario, teensy works perfectly for me and I don't want to run my resampling code on one processor(raspberry pi), due to less processing power availability. So I am just using two different processors for two different work.

  6. #6
    Senior Member
    Join Date
    Jan 2020
    Location
    Toscana
    Posts
    129
    You did not mention linux in your post.
    Unfortunately I do not know the recent developments in PyAudio on RPi.

    JACK Audio Connection Kit has resampling features with libsamplerate
    https://jackaudio.org/
    https://github.com/erikd/libsamplerate

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •