- 浏览: 1481456 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (419)
- XMPP (19)
- Android (180)
- Java (59)
- Network (4)
- HTML5 (13)
- Eclipse (9)
- SCM (23)
- C/C++ (4)
- UML (4)
- Libjingle (15)
- Tools&Softwares (29)
- Linphone (5)
- Linux&UNIX (6)
- Windows (18)
- Google (10)
- MISC (3)
- SIP (6)
- SQLite (5)
- Security (4)
- Opensource (29)
- Online (2)
- 文章 (3)
- MemoryLeak (10)
- Decompile (5)
- Ruby (1)
- Image (1)
- Bat (4)
- TTS&ASR (28)
- Multimedia (1)
- iOS (20)
- Asciiflow - ASCII Flow Diagram Tool.htm (1)
- Networking (1)
- DLNA&UPnP (2)
- Chrome (2)
- CI (1)
- SmartHome (0)
- CloudComputing (1)
- NodeJS (3)
- MachineLearning (2)
最新评论
-
bzhao:
点赞123!
Windows的adb shell中使用vi不乱码方法及AdbPutty -
wahahachuang8:
我觉得这种东西自己开发太麻烦了,就别自己捣鼓了,找个第三方,方 ...
HTML5 WebSocket 技术介绍 -
obehavior:
view.setOnTouchListenerview是什么
[转]android 一直在最前面的浮动窗口效果 -
wutenghua:
[转]android 一直在最前面的浮动窗口效果 -
zee3.lin:
Sorry~~
When I build "call ...
Step by Step about How to Build libjingle 0.4
Here it is, my fist JAVA application for Android. This is very simple application which introduce how you can get sound from microphone of your phone analyze it and record it on your phones SD card. What new I learn writing this application
- Initializing AudioRecorder
- Analyzing every byte of audio buffer
- Create .wav file from existing audio buffer.
Below you can see whole code of my application. As this is mt first JAVA application for Android maybe it contains some mistakes, but I promise to modify this version.
package com.vproject.voicedetection; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; public class VoiceDetectionActivity extends Activity { // Constant members. private static final int SAMPLE_RATE_IN_HZ = 8000; private static final int RECORDER_BPP = 16; private static final int CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO; private static final int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT; private static final int AUDIO_SOURCE = MediaRecorder.AudioSource.MIC; private static final String TAG = "VoiceDetection"; private static final int MAX_VOL = 600; private static final int MIN_VAL = 0; private static final int START_RECORD_FROM = 350; private static final int CHECK_BLOCK_COUNT = 5; private Thread onCreateThread = null; private AudioRecord audioRecorder = null; private int minBufferSizeInBytes = 0; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView textView = (TextView)findViewById(R.id.textView3); Button button = (Button)findViewById(R.id.button1); button.setVisibility( android.view.View.INVISIBLE ); textView.setVisibility( android.view.View.VISIBLE ); Start(); } public void Start( ) { // Create Handler final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { int value = msg.what; ImageView picture = (ImageView) findViewById(R.id.imageView); int resID[] = { R.drawable.image0001, R.drawable.image20, R.drawable.image40, R.drawable.image60, R.drawable.image80, R.drawable.image100 }; for( int i=MIN_VAL, step = (MAX_VOL - MIN_VAL)/resID.length; i<resID.length; i++ ) { if( value >= i*step && value <= i*step + step ) picture.setImageResource( resID[i] ); } // Set image for maximum value. if( value >= MAX_VOL ) picture.setImageResource( R.drawable.image100 ); } }; // Text change handler final Handler changeTexthandler = new Handler() { @Override public void handleMessage(Message msg) { TextView textView = (TextView)findViewById(R.id.textView3); Button button = (Button)findViewById(R.id.button1); switch( msg.what ) { case 0: textView.setText("Waiting"); button.setVisibility( android.view.View.INVISIBLE ); textView.setVisibility( android.view.View.VISIBLE ); break; case 1: textView.setText("Recording"); button.setVisibility( android.view.View.INVISIBLE ); textView.setVisibility( android.view.View.VISIBLE ); break; default: button.setVisibility( android.view.View.VISIBLE ); textView.setVisibility( android.view.View.INVISIBLE ); break; } } }; // Initialize minimum buffer size in bytes. minBufferSizeInBytes = AudioRecord.getMinBufferSize( SAMPLE_RATE_IN_HZ, CHANNEL_CONFIG, AUDIO_FORMAT ); if( minBufferSizeInBytes == AudioRecord.ERROR_BAD_VALUE ) Log.e( TAG, "Bad Value for \"minBufferSize\", recording parameters are not supported by the hardware" ); if( minBufferSizeInBytes == AudioRecord.ERROR ) Log.e( TAG, "Bad Value for \"minBufferSize\", implementation was unable to query the hardware for its output properties" ); // Initialize Audio Recorder. try { audioRecorder = new AudioRecord( AUDIO_SOURCE, SAMPLE_RATE_IN_HZ, CHANNEL_CONFIG, AUDIO_FORMAT, minBufferSizeInBytes ); } catch(IllegalArgumentException ex) { Log.e( TAG, "Illegal Arguments: " + ex.getMessage() ); } // Launch Thread. onCreateThread = new Thread( new Runnable() { @Override public void run() { // Starts recording from the AudioRecord instance. audioRecorder.startRecording(); int numberOfBytesRead = 0; byte audioBuffer[] = new byte[minBufferSizeInBytes]; float tempBuffer[] = new float[CHECK_BLOCK_COUNT]; int tempIndex = 0; boolean isRecording = false; int totalReadBytes = 0; byte totalByteBuffer[] = new byte[60 * 44100 * 2]; // While data coming from microphone. while( true ) { float totalAbsValue = 0.0f; short sample = 0; numberOfBytesRead = audioRecorder.read( audioBuffer, 0, minBufferSizeInBytes ); // Analyze income sound. for( int i=0; i<minBufferSizeInBytes; i+=2 ) { sample = (short)( (audioBuffer[i]) | audioBuffer[i + 1] << 8 ); totalAbsValue += Math.abs( sample ) / (numberOfBytesRead/2); } // Set Animation of microphone. handler.sendEmptyMessage((int)totalAbsValue); // Analyze tempBuffer. tempBuffer[tempIndex%CHECK_BLOCK_COUNT] = totalAbsValue; float tempBufferTotalCount = 0.0f; for( int i=0; i<CHECK_BLOCK_COUNT; ++i ) tempBufferTotalCount += tempBuffer[i]; // Finalize value. tempBufferTotalCount = tempBufferTotalCount/CHECK_BLOCK_COUNT; // Waiting for load speak to start recording. if( (tempBufferTotalCount >=0 && tempBufferTotalCount <= START_RECORD_FROM) && !isRecording ) { Log.i("TAG", "Waiting for voice to start record."); tempIndex++; changeTexthandler.sendEmptyMessage(0); continue; } if( tempBufferTotalCount > START_RECORD_FROM && !isRecording ) { Log.i("TAG", "Recording"); changeTexthandler.sendEmptyMessage(1); isRecording = true; } // Stop Recording and save data to file. if( (tempBufferTotalCount >= 0 && tempBufferTotalCount <= START_RECORD_FROM) && isRecording ) { Log.i("TAG", "Stop Recording and Save data to file"); changeTexthandler.sendEmptyMessage(2); audioRecorder.stop(); audioRecorder.release(); audioRecorder = null; SaveDataToFile( totalReadBytes, totalByteBuffer ); totalReadBytes = 0; tempIndex++; break; } // Record Sound. for( int i=0; i<numberOfBytesRead; i++ ) totalByteBuffer[totalReadBytes + i] = audioBuffer[i]; totalReadBytes += numberOfBytesRead; tempIndex++; } } }, "Voice Detection Thread" ); // Run the Thread. onCreateThread.start(); //*/ } public void SaveDataToFile( int totalReadBytes, byte[] totalByteBuffer ) { // Save audio to file. String filepath = Environment.getExternalStorageDirectory().getPath(); File file = new File( filepath, "VioceDetectionDemo" ); if( !file.exists( ) ) file.mkdirs(); // String fileName = file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".wav"; // File always saved by same name. String fileName = file.getAbsolutePath() + "/" + "VoiceDetectionDemo" + ".wav"; long totalAudioLen = 0; long totalDataLen = totalAudioLen + 36; long longSampleRate = SAMPLE_RATE_IN_HZ; int channels = 1; long byteRate = RECORDER_BPP * SAMPLE_RATE_IN_HZ * channels/8; totalAudioLen = totalReadBytes; totalDataLen = totalAudioLen + 36; byte finalBuffer[] = new byte[totalReadBytes + 44]; finalBuffer[0] = 'R'; // RIFF/WAVE header finalBuffer[1] = 'I'; finalBuffer[2] = 'F'; finalBuffer[3] = 'F'; finalBuffer[4] = (byte) (totalDataLen & 0xff); finalBuffer[5] = (byte) ((totalDataLen >> 8) & 0xff); finalBuffer[6] = (byte) ((totalDataLen >> 16) & 0xff); finalBuffer[7] = (byte) ((totalDataLen >> 24) & 0xff); finalBuffer[8] = 'W'; finalBuffer[9] = 'A'; finalBuffer[10] = 'V'; finalBuffer[11] = 'E'; finalBuffer[12] = 'f'; // 'fmt ' chunk finalBuffer[13] = 'm'; finalBuffer[14] = 't'; finalBuffer[15] = ' '; finalBuffer[16] = 16; // 4 bytes: size of 'fmt ' chunk finalBuffer[17] = 0; finalBuffer[18] = 0; finalBuffer[19] = 0; finalBuffer[20] = 1; // format = 1 finalBuffer[21] = 0; finalBuffer[22] = (byte) channels; finalBuffer[23] = 0; finalBuffer[24] = (byte) (longSampleRate & 0xff); finalBuffer[25] = (byte) ((longSampleRate >> 8) & 0xff); finalBuffer[26] = (byte) ((longSampleRate >> 16) & 0xff); finalBuffer[27] = (byte) ((longSampleRate >> 24) & 0xff); finalBuffer[28] = (byte) (byteRate & 0xff); finalBuffer[29] = (byte) ((byteRate >> 8) & 0xff); finalBuffer[30] = (byte) ((byteRate >> 16) & 0xff); finalBuffer[31] = (byte) ((byteRate >> 24) & 0xff); finalBuffer[32] = (byte) (2 * 16 / 8); // block align finalBuffer[33] = 0; finalBuffer[34] = RECORDER_BPP; // bits per sample finalBuffer[35] = 0; finalBuffer[36] = 'd'; finalBuffer[37] = 'a'; finalBuffer[38] = 't'; finalBuffer[39] = 'a'; finalBuffer[40] = (byte) (totalAudioLen & 0xff); finalBuffer[41] = (byte) ((totalAudioLen >> 8) & 0xff); finalBuffer[42] = (byte) ((totalAudioLen >> 16) & 0xff); finalBuffer[43] = (byte) ((totalAudioLen >> 24) & 0xff); for( int i=0; i<totalReadBytes; ++i ) finalBuffer[44+i] = totalByteBuffer[i]; FileOutputStream out; try { out = new FileOutputStream(fileName); try { out.write(finalBuffer); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } public void OnClickButtonTryAgain(View view) { Start(); } }
发表评论
-
[Android] 为Android安装BusyBox —— 完整的bash shell
2013-12-27 10:19 1409http://www.cnblogs.com/xiaowen ... -
Windows的adb shell中使用vi不乱码方法及AdbPutty
2013-12-27 10:17 7391http://www.veryhuo.com/down/ht ... -
AppMobi推出新XDK,可创建测试PhoneGap项目
2012-09-03 13:39 2527AppMobi今天发布了一个新的工具PhoneGap Mobi ... -
Sencha
2012-09-03 12:59 1136http://www.sencha.com/ Se ... -
jQuery Mobile学习
2012-09-01 12:33 1625使用Jquery Mobile设计Android通讯录 ... -
BackBone
2012-09-01 12:34 1218Backbone.js 是一种重量级javascript M ... -
jQTouch
2012-08-30 15:57 934A Zepto/jQuery plugin for mobil ... -
SwiFTP
2012-08-30 15:43 1241SwiFTP is a FTP server that run ... -
kWS
2012-08-30 15:41 1144kWS is a lightweight and fast W ... -
jQuery Mobile
2012-08-30 15:07 974http://jquerymobile.com/ -
PhoneGap
2012-08-30 15:07 992http://phonegap.com/ -
Android Button background image pressed/highlighted and disabled states without
2012-08-06 12:49 1623http://shikii.net/blog/android- ... -
[AndriodTips]Image, saved to sdcard, doesn't appear in Android's Gallery app
2012-08-04 16:15 1109http://stackoverflow.com/questi ... -
[AndroidTip]local reference table overflow (max=512)的错误解决
2012-07-22 22:56 5949JNI层coding经常会遇到ReferenceTable o ... -
[AndroidTip]EditText如何初始状态不获得焦点?
2012-07-22 15:35 1181最简单的办法是在EditText前面放置一个看不到的Linea ... -
[AndroidTip]android textview滚动条
2012-07-21 14:29 1257本来是想做一个显示文字信息的,当文字很多时View的高度不能超 ... -
Google公布Android 4.1完整功能
2012-07-16 09:48 3137http://www.android.com/about/je ... -
Android开发:使用AudioTrack播放PCM音频数据【附源码】
2012-07-13 15:20 20770http://www.linuxidc.com/Linux/2 ... -
Android上的行车记录仪
2012-07-11 22:31 1963MyCar Recorder DailyRoads -
Google hired one of Nuance soft engineers to help work around all Nuance patents
2012-07-10 14:33 1046很有趣的消息: http://forums.macrumor ...
相关推荐
Voice activity detection (VAD) toolkit including DNN, bDNN, LSTM and ACAM based VAD
Voice Activity Detection in the Tiger Platform.pdf--etd
Void A fast and light voice liveness detection system
android音频开发的口袋书,属于一个很新,比较收欢迎的android口袋书系列。短小精悍,适合作为音频开发入门书籍。美国亚马逊上4星半
voice record for different sampling rate and store in different format on android. optionally display the audio
voicebox for matlab matlab中的voicebox工具箱,主要功能是进行语音分析。 解压到matlab安装路径中的toolbox文件夹中, 之后在matlab主界面点击“设置路径”然后将voicebox工具箱添加路径即可。好东西,不解释。
voice-music-detection_人声_voice-detection_人声识别_music-detection_用双门限法_源码.rar.rar
voice-music-detection_人声_voice-detection_人声识别_music-detection_用双门限法_源码.zip
各种语音活动检测的文章和噪底估计的文章,是远场语音唤醒的第一步,也是低功耗语音识别系统的第一步。
Voice Changer Premium「语音转换器」v1.8.1 for Android 支持许多不同的效果,唱卡拉OK和录音更容易
The payoff for us as developers is that Xamarin is laser-focused on Mono for Android and MonoTouch, and on making those the best products available for development on mobile with Android and iPhone....
great voice or you’ve recently discovered a hidden talent for creating characters, this book is for you. Voice Acting For Dummies is packed with helpful information that explains in plain English how...
FireMonkey-Android-Voice-master
To create their own voice "skills," users need to learn some new device toolkits, the basics of Voice UI design, and some emerging best practices for building and deploying on these diverse platforms....
使用说明在这里 https://blog.csdn.net/yj13811596648/article/details/88737623
Voice Activity Detection system (Matlab-based implementation).zip
把一段音频放到android系统上,能够实现音频的播放
Voice overlay helps you turn your user's voice into text, providing a polished UX while handling for you the necessary permission. Demo You can clone this repo, then run the Demo ...
使用说明在这里:https://blog.csdn.net/yj13811596648/article/details/88737623