0 0 Votes

Android Audio Recorder

Question by Xchris | 14/11/2013 at 19:06

I’m really new in java programming. I’m trying to build an android application that will be enabled by NFC, record sound (during sleep) continuously (in separated files of 1-2 minutes length and then start a new recording file), uploading each one of them (right after it’s recorded) on a server and then deleting them from the phone. Also I want to add a UTC timestamp to every file, to be able to synchronize these sounds recordings with other signals, on the same graph.

I’ve found this (http://androidcodeexamples.blogspot.gr/2012/06/voice-recording-in-android.html) open source app, which records audio. I need to make it to: 

1. Start while I put the phone on the NFC
2. Record files with 1-2 minutes max length
3. Upload each one on the server and then delete it from the phone
4. Add UTC timestamps

Could you help me with any of these? Any Help would be appreciated.
Thanks in advance!

ReplyPositiveNegativeDateVotes

Computer Expert

Show Profile | Message
Avatar
11 Vote

Hi Xchris, that are many questions in one. It would be better if you split your task into several sub-tasks and open a new question for each of those tasks.

Otherwise, it is hard to help you, because we do not know at which point you cannot go on with your work.

Possible questions are "How to react to NFC", "How to stop/start file recording after a time/with a time limit", "How to delete files" and so on. Than we can link all of this questions here.

If I have some more time this evening, I will look up some of this questions for you.
14/11/2013 at 21:22

ReplyPositive Negative

Xchris

Show Profile | Message
Avatar
00 Votes

Thanks for your response!

Ok, I'll split my questions.

As I said, I'm new in Java (still learning). Could you suggest me a page which I could have free java lessons and excersises? Should I also have lessons for android?
15/11/2013 at 20:45

ReplyPositive Negative

SmartUser

Show Profile | Message
Avatar
11 Vote

My advice: Learning by doing.

Just start making a simple tool and google for the functions you want or the troubles you are running in.

You should have basic Java knowledge, but if you want to interact with the phone or if you want to use the GUI elements, than you have to learn Android specific thinks. In my opinion, it is 30 % Java and 70 % Android stuff.
16/11/2013 at 03:42

Positive Negative

Xchris

Show Profile | Message
Avatar
00 Votes

Thanks. I'll try build it and I hope if I have any questions, you could answer them.
16/11/2013 at 19:45

Positive Negative

Xchris

Show Profile | Message
Avatar
00 Votes

Hi again
My professor changed the requirements of the application and now the first thing I need to do is to make it "hear" the sound and display the amplitude of it. I use the getMaxAmplitude method, but it returns 0 always.Here's my code :

public class MainActivity extends Activity {	
private static final String LOG_TAG = "AudioRecordTest";
private static String mFileName = null;

private RecordButton mRecordButton = null;
private MediaRecorder mRecorder = null;

private PlayButton mPlayButton = null;
private MediaPlayer mPlayer = null;

public int currentAmplitude;

private void onRecord(boolean start) {
  if (start) {
    startRecording(); 
  } else {
    stopRecording();
  }
}

private void onPlay(boolean start) {
  if (start) {
    startPlaying();
  } else {
    stopPlaying();
  }
}

private void startPlaying() {
  mPlayer = new MediaPlayer();
  try {
    mPlayer.setDataSource(mFileName);
    mPlayer.prepare();
    mPlayer.start();
  } catch (IOException e) {
    Log.e(LOG_TAG, "prepare() failed");
  }
}

private void stopPlaying() {
  mPlayer.release();
  mPlayer = null;
}

private void startRecording() {
  mRecorder = new MediaRecorder();
  mRecorder.setAudioSource(
  MediaRecorder.AudioSource.MIC);
  mRecorder.setOutputFormat(
  MediaRecorder.OutputFormat.THREE_GPP);
  mRecorder.setOutputFile(mFileName);
  mRecorder.setAudioEncoder(
  MediaRecorder.AudioEncoder.AMR_NB);

  try {
    mRecorder.prepare();
  } catch (IOException e) {
    Log.e(LOG_TAG, "prepare() failed");
  }

  mRecorder.start();
  getAmplitude();
}

private void stopRecording() {
  mRecorder.stop();
  mRecorder.release();
  mRecorder = null;
}

public double getAmplitude() {
  if (mRecorder != null) {
    currentAmplitude = mRecorder.getMaxAmplitude();
    return currentAmplitude;
  } else return 0;
}

class RecordButton extends Button {
  boolean mStartRecording = true;

  OnClickListener clicker = new OnClickListener() {
    public void onClick(View v) {
      onRecord(mStartRecording);
      if (mStartRecording) {
        setText("Stop recording");
      } else {
        setText("Start recording");
      }
    mStartRecording = !mStartRecording;
  }
};

public RecordButton(Context ctx) {
  super(ctx);
  setText("Start recording");
  setOnClickListener(clicker);
  }
}

class PlayButton extends Button {
  boolean mStartPlaying = true;

  OnClickListener clicker = new OnClickListener() {
    public void onClick(View v) {
    onPlay(mStartPlaying);
    if (mStartPlaying) {
      setText("Stop playing");
    } else {
      setText("Start playing");
    }
    mStartPlaying = !mStartPlaying;
  }
};

public PlayButton(Context ctx) {
  super(ctx);
  setText("Start playing");
  setOnClickListener(clicker);
  }
}

public MainActivity() {
  theDate date = new theDate();
  String sDate = date.curDate();
  String sTime = date.curTime();
  mFileName = 
  Environment.getExternalStorageDirectory()
  .getAbsolutePath();
  mFileName += 
  "/TSP_Recordings/Date_"+sDate+"_Time_"+sTime+".3gp";
}

@Override
public void onCreate(Bundle icicle) {
  super.onCreate(icicle);

  LinearLayout ll = new LinearLayout(this);
  mRecordButton = new RecordButton(this);
  ll.addView(mRecordButton,
  new LinearLayout.LayoutParams(
  ViewGroup.LayoutParams.WRAP_CONTENT,
  ViewGroup.LayoutParams.WRAP_CONTENT,
  0));
  mPlayButton = new PlayButton(this);
  ll.addView(mPlayButton,
  new LinearLayout.LayoutParams(
  ViewGroup.LayoutParams.WRAP_CONTENT,
  ViewGroup.LayoutParams.WRAP_CONTENT,
  0));
  TextView tv = new TextView(this);
  ll.addView(tv,
  new LinearLayout.LayoutParams(
  ViewGroup.LayoutParams.WRAP_CONTENT,
  ViewGroup.LayoutParams.WRAP_CONTENT,
  0));
  tv.setText(Integer.toString(currentAmplitude));
  setContentView(ll);
}

@Override
public void onPause() {
  super.onPause();
  if (mRecorder != null) {
    mRecorder.release();
    mRecorder = null;
  }

if (mPlayer != null) {
  mPlayer.release();
  mPlayer = null;
}
} 
}

03/12/2013 at 11:42

ReplyPositive Negative
Reply

Related Topics

What is actually Android?
Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.