4 Replies Latest reply on Aug 11, 2015 3:55 PM by SiddRajput

    USB microphone on Intel Edison with Ubilinux

    SiddRajput

      Hello,

       

      I need help getting my USB microphone working on my Intel Edison. I've connected the mic with an OTG cable and I can see it if I send a lsusb. It's an AKM5370 mic and I'm using Ubilinux.

       

      root@ubilinux:/home/edison/justincode/dspjustin/src# lsusb
      Bus 001 Device 002: ID 0556:0001 Asahi Kasei Microsystems Co., Ltd AK5370 I/F A/D Converter
      Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
      Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
      

       

      I'm trying to use pyaudio to record audio from it but I can't seem to get any audio. It can create a .wav file, but there is no sound in it. Please help.

        • 1. Re: USB microphone on Intel Edison with Ubilinux
          CMata_Intel

          Hi SiddRajput,

           

          Are you sure you have all the drivers needed for this microphone?

          Could you post the commands you are using to record the audio?

           

          Kind regards,

          Charlie

          • 2. Re: USB microphone on Intel Edison with Ubilinux
            SiddRajput

            I don't know if I have all the drivers.  Hoping someone can tell me what I need.

             

            I'm using a Python script to record shown below.  The same script works on my Ubuntu machine with the same mic.

             

            More info on Pyaudio here: http://people.csail.mit.edu/hubert/pyaudio/

             

            """PyAudio example: Record a few seconds of audio and save to a WAVE file."""
            
            import pyaudio
            import wave
            
            CHUNK = 1024
            FORMAT = pyaudio.paInt16
            CHANNELS = 2
            RATE = 44100
            RECORD_SECONDS = 5
            WAVE_OUTPUT_FILENAME = "output.wav"
            
            p = pyaudio.PyAudio()
            
            stream = p.open(format=FORMAT,
              channels=CHANNELS,
              rate=RATE,
              input=True,
              frames_per_buffer=CHUNK)
            
            print("* recording")
            
            frames = []
            
            for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
              data = stream.read(CHUNK)
              frames.append(data)
            
            print("* done recording")
            
            stream.stop_stream()
            stream.close()
            p.terminate()
            
            wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
            wf.setnchannels(CHANNELS)
            wf.setsampwidth(p.get_sample_size(FORMAT))
            wf.setframerate(RATE)
            wf.writeframes(b''.join(frames))
            wf.close()

             

            Sidd

            • 3. Re: USB microphone on Intel Edison with Ubilinux
              CMata_Intel

              Hi Sidd,

               

              Have you tried with arecord, to test the functionality of the microphone?

              How are you trying to play this file? Are you using the board and a Sound Card or are you sending the file to another machine with audio features?

              Is the size of the file greater than 0 bytes?

               

              Regards,

              Charlie

              • 4. Re: USB microphone on Intel Edison with Ubilinux
                SiddRajput

                I got it working.  I had to set the default recording device as described here: USB mic on Linux - Audacity Wiki.

                Specifically this part:

                 

                Setting default recording device

                Editing ~/.asoundrc and putting this snippet below might work for some:

                pcm.!default {

                  type asym

                  playback.pcm {

                  type plug

                  slave.pcm "hw:0,0"

                  }

                  capture.pcm {

                  type plug

                  slave.pcm "hw:1,0"

                  }

                }

                This little ALSA configuration setting uses the default soundcard as playback device (hw:0,0) and sets hw:1,0 (that suppose to be your USB-mic) to become the default capture device.

                 

                Yes I tried arecord and it worked also after changing the above.  I'm saving the file as a .wav and transferring it to another computer and playing it there.

                Sidd