extends:http://blog.csdn.net/trbbadboy/article/details/7865530
is a direct play microphone captured by the sound thread class:
classRecordthreadextendsthread{Static Final intfrequency = 44100; Static Final intChannelconfiguration =Audioformat.channel_configuration_mono; Static Final intAudioencoding =Audioformat.encoding_pcm_16bit; @Override Public voidrun () {//TODO auto-generated Method Stub intRecbufsize =audiorecord.getminbuffersize (Frequency, channelconfiguration, audioencoding)* *; intPlybufsize =audiotrack.getminbuffersize (Frequency, channelconfiguration, audioencoding)* *; Audiorecord Audiorecord=NewAudiorecord (MediaRecorder.AudioSource.MIC, Frequency, channelconfiguration, audioencoding, recbufsize); Audiotrack Audiotrack=NewAudiotrack (audiomanager.stream_music, Frequency, channelconfiguration, audioencoding, Plybufsize, AudioT Rack. Mode_stream); byte[] Recbuf =New byte[Recbufsize]; Audiorecord.startrecording (); Audiotrack.play (); while(true){ intReadlen = Audiorecord.read (recbuf, 0, recbufsize); Audiotrack.write (Recbuf,0, Readlen); } audiotrack.stop (); Audiorecord.stop (); } }
When used, this is the line:
New Recordthread (); Rec.start ();
You need to add routing permissions in the Androidmanifest.xml file:
<android:name= "Android.permission.RECORD_AUDIO"/>
Android Microphone self-recorded demo