Android Open Source - SpeechWriter Audio Cntl






From Project

Back to project page SpeechWriter.

License

The source code is released under:

MIT License

If you think the Android project SpeechWriter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.psu.rcy5017.speechwriter.controller;
//  w w w  .  j a v a  2s .  com
import java.io.IOException;

import edu.psu.rcy5017.speechwriter.constant.MiscConstants;

import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.util.Log;

/**
 * A controller for recording and playing audio files.
 * Used: https://developer.android.com/guide/topics/media/audio-capture.html as example.
 * @author Ryan Yosua
 *
 */
public enum AudioCntl {
    
    INSTANCE;
    
    private final String TAG = "AudioCntl";
    private  MediaRecorder recorder;
    private  MediaPlayer player;
    
       
    /**
     * Starts playing an audio recording.
     * @param fileName the name of the file to play ex: "/testRecording.3gp"
     */
    public void startPlaying(String fileName) {
        player = new MediaPlayer();
        try {
            player.setDataSource(MiscConstants.FILE_DIRECTORY + fileName + MiscConstants.AUDIO_EXTENSION);
            player.prepare();
            player.start();
        } catch (IOException e) {
            Log.d(TAG, "prepare() failed");
        }
    }
    
    /**
     * Stops playing the audio recording.
     */
    public void stopPlaying() {
        player.release();
        player = null;
    }
    
    /**
     * Starts recording an audio recording.
     * @param fileName the name of the file to record ex: "/testRecording.3gp"
     */
    public void startRecording(String fileName) {
        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setOutputFile(MiscConstants.FILE_DIRECTORY + fileName + MiscConstants.AUDIO_EXTENSION);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        
        Log.d(TAG, MiscConstants.FILE_DIRECTORY + fileName + MiscConstants.AUDIO_EXTENSION);
        
        try {
            recorder.prepare();
        } catch (IOException e) {
            Log.d(TAG, "prepare() failed");
        }

        recorder.start();
    }
    
    /**
     * Stops recording the audio recording.
     */
    public void stopRecording() {
        recorder.stop();
        recorder.release();
        recorder = null;
    }
}




Java Source Code List

com.ericharlow.DragNDrop.DragListener.java
com.ericharlow.DragNDrop.DragNDropAdapter.java
com.ericharlow.DragNDrop.DragNDropListView.java
com.ericharlow.DragNDrop.DropListener.java
com.ericharlow.DragNDrop.RemoveListener.java
edu.psu.rcy5017.speechwriter.DatabaseHelper.java
edu.psu.rcy5017.speechwriter.activity.EditTextActivity.java
edu.psu.rcy5017.speechwriter.activity.MainActivity.java
edu.psu.rcy5017.speechwriter.activity.NoteCardListActivity.java
edu.psu.rcy5017.speechwriter.activity.NoteListActivity.java
edu.psu.rcy5017.speechwriter.activity.OptionsActivity.java
edu.psu.rcy5017.speechwriter.activity.SpeechListActivity.java
edu.psu.rcy5017.speechwriter.activity.SpeechRecordingListActivity.java
edu.psu.rcy5017.speechwriter.activity.SplashScreenActivity.java
edu.psu.rcy5017.speechwriter.adapter.TabsPagerAdapter.java
edu.psu.rcy5017.speechwriter.constant.DefaultValues.java
edu.psu.rcy5017.speechwriter.constant.MiscConstants.java
edu.psu.rcy5017.speechwriter.constant.RequestCodes.java
edu.psu.rcy5017.speechwriter.controller.AudioCntl.java
edu.psu.rcy5017.speechwriter.controller.OptionsCntl.java
edu.psu.rcy5017.speechwriter.datasource.DataSource.java
edu.psu.rcy5017.speechwriter.datasource.NoteCardDataSource.java
edu.psu.rcy5017.speechwriter.datasource.NoteDataSource.java
edu.psu.rcy5017.speechwriter.datasource.SpeechDataSource.java
edu.psu.rcy5017.speechwriter.datasource.SpeechRecordingDataSource.java
edu.psu.rcy5017.speechwriter.fragment.NoteCardFragement.java
edu.psu.rcy5017.speechwriter.listener.ChangeFontSizeListener.java
edu.psu.rcy5017.speechwriter.listener.DragListenerImpl.java
edu.psu.rcy5017.speechwriter.listener.DropListenerImpl.java
edu.psu.rcy5017.speechwriter.listener.DropReorderListener.java
edu.psu.rcy5017.speechwriter.listener.RemoveListenerImpl.java
edu.psu.rcy5017.speechwriter.model.NoteCard.java
edu.psu.rcy5017.speechwriter.model.Note.java
edu.psu.rcy5017.speechwriter.model.SpeechRecording.java
edu.psu.rcy5017.speechwriter.model.Speech.java
edu.psu.rcy5017.speechwriter.task.ChangeNoteTextTask.java
edu.psu.rcy5017.speechwriter.task.CreateNoteCardTask.java
edu.psu.rcy5017.speechwriter.task.CreateNoteTask.java
edu.psu.rcy5017.speechwriter.task.CreateSpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.CreateSpeechTask.java
edu.psu.rcy5017.speechwriter.task.DeleteTask.java
edu.psu.rcy5017.speechwriter.task.GetAllTask.java
edu.psu.rcy5017.speechwriter.task.NoteCardTask.java
edu.psu.rcy5017.speechwriter.task.NoteTask.java
edu.psu.rcy5017.speechwriter.task.RenameNoteCardTask.java
edu.psu.rcy5017.speechwriter.task.RenameSpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.RenameSpeechTask.java
edu.psu.rcy5017.speechwriter.task.SpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.SpeechTask.java
edu.psu.rcy5017.speechwriter.task.UpdateOrderTask.java