Ticket #437 (new defect)

Opened 11 years ago

Last modified 10 years ago

USB Microphone doesn't work with Speech Submission App

Reported by: kmaclean Owned by: kmaclean
Priority: major Milestone: SpeechSubmission 0.1.7
Component: SpeechSubmission Version: SpeechSubmission0.1.6
Keywords: Cc:

Description (last modified by kmaclean) (diff)

Email from a user:

I can't get your java app to work on my box. I have a Sennheiser USB headset, which works fine for VOIP, but hardly gets a blip when recording on your app (with volume maxed out). In audacity it's also lower than you suggest, but it sounds okay... (except, it's buggy, and I can only record one clip).

Follow-up email:

I was able to get it working with the mic on my usb webcam (Logitech Pro 9000). I guess the sound quality is good enough, but I still don't know why the headset--which should be much better--doesn't work.

Possible Code Fix

This article: A JavaSound Primer provides some excellent background on the issue, and somde code examples for a possible fix for the speechsubmission app

Change History

comment:1 Changed 11 years ago by kmaclean

In retrospect, it likely has something to do with the fact that your mic is a USB device, and the computer sets it as a separate input device from the default analog input device... running "arecord --list-devices" from a command line will likely confirm this.

See this post: http://www.voxforge.org/home/read2/java/comments/no-sound for more info. Sergey, in that case disabled his on-board audio card, and this allowed the applet to work correctly.

Another approach might be to modify the sound.properties file in the JRE\lib directory of your JDK installation (using the output from arecord; quote taken from this post):

Note: With JDK 1.5, it is possible to use a sound.properties file in the JRE\lib directory of your JDK installation. This sound.properties file can be used to specify the default Mixer that will be used when AudioSystem?.getLine() is called for the various type of Line. In my case, the sound.properties file contains:

javax.sound.sampled.Port=#Port SB Audigy Audio [C400] javax.sound.sampled.Sourc#SB Audigy Audio [C400] javax.sound.sampled.TargetDataLine?=#SB Audigy Audio [C400]

The mixer name is placed after the # sign. These are actually the defaults for my machine, so this file is not strictly necessary.

comment:2 Changed 11 years ago by kmaclean

In this particular case, it might be that this was a case of the usb webcam being the default mixer, rather than the usb mike.

comment:3 Changed 11 years ago by kmaclean

  • Description modified (diff)
  • Summary changed from USB Microphones don't work with Speech Submission App to USB Microphone doesn't work with Speech Submission App

comment:4 Changed 11 years ago by kmaclean

From the Sphinx4 FAQ page:

How do I select a different microphone (e.g., a USB headset) on my machine?

By default, Sphinx-4 will use the getLine method of the Java Sound AudioSystem? class to obtain a TargetDataLine? (i.e., the object used to interface to your microphone). This method grabs a line from any of the available Mixers known to the AudioSystem?. As such, when using the AudioSystem? to obtain the TargetDataLine?, you have little control over which line is chosen if more than one line matches the requirements of the front end. For example, if you plug in a USB headset into a Macintosh PowerBook?, the getLine method of the AudioSystem? class will typcially never select a line from the USB device.

This behavior can be frustrating, especially when you have a nice USB microphone you'd like to use.

To override the default behavior, you can set the selectMixer property of the Microphone class. In Java Sound, a Mixer is an audio device with one or more lines. In practice, a Mixer tends to be mapped to a particular system audio device. For example, on the Mac, there's a Mixer associated with the built-in audio hardware. Furthermore, when you plug in a USB headset, a new Mixer will appear for that headset. The selectMixer property allows you to specify which specific Mixer Sphinx-4 will use to select the TargetDataLine?.

The value of the selectMixer property can be "default," which means let the AudioSystem? decide which line to use from all the available Mixers, "last," which means select the last Mixer supported by the AudioSystem? (USB headsets tend to be associated with the last Mixer), or an integer value that represents the index of the Mixer.Info that is returned by AudioSystem?.getMixerInfo().

To get the list of Mixer.Info objects available on your system, along with their integer index values, run the AudioTool? application with a command line argument of "-dumpMixers".

To set the selectMixer property of the Microphone, you need to have a component in your config file that defines the microphone. In the examples in Sphinx-4, this component is aptly named "microphone." In the configuration for the microphone component, you can the set the selectMixer property in the config file for the application. For example:

<property name="selectMixer" value="last"/>

You can also set the selectMixer property from the command line. For example:

java -Dmicrophone[selectMixer]=last -jar bin/AudioTool.jar

In both of these examples, the last Mixer discovered by the Java Sound AudioSystem? class will be used to select the TargetDataLine? for the microphone.

comment:5 Changed 10 years ago by kmaclean

From this post by Greg Howell:

Hey guys - I was suffering with this too, just figured it out for JMStudio, the sun demo app that lets you record video/audio: the default audio is STEREO, whereas my USB mic only recorded in MONO.

Changing from stereo to mono suddenly made the USB mixer/mic selected for audio input instead of the soundcards "line-in".

hope that works for somebody else out there too,

Greg

comment:6 Changed 10 years ago by kmaclean

From this post by Greg Howell: p.s. stereo -> mono only worked when I modified sound.properties with this line, which was in the output of the code below it:

javax.sound.sampled.TargetDataLine?=#U0x46d0x8d7 [plughw:1,0]

Sergey I noticed you used the same line the other fellow used, but probably your mic is called something else on your system.

import javax.sound.sampled.*;

public class HelloWorld {
  public static void main( String[] args ) {
    for ( Mixer.Info info : AudioSystem.getMixerInfo() ) {
      Mixer mixer = AudioSystem.getMixer(info);
      Line.Info lineInfo = new Line.Info(DataLine.class);

      System.out.println( "Mixer " + info.getName() +
              " desc: " + info.getDescription() +
              " vend: " + info.getVendor() +
              " ver: " + info.getVersion()    );

      if ( mixer.isLineSupported( lineInfo ) ) {
    for ( Line.Info linfo : mixer.getTargetLineInfo(lineInfo) ) {
      for ( AudioFormat form : ((DataLine.Info) linfo).getFormats() )
        System.out.println( "  " + form );
    }
      }
    }
  }
}

good luck,

Greg

comment:7 Changed 10 years ago by kmaclean

looks like USB microphone problems are fixed in newest Fedora 12 release:

voxforge works on fedora12 and firefox.ogv.flv

I don't have Fedora 12 installed yet, but when I do, I will test with my USB mic.

Note: See TracTickets for help on using tickets.