Correct way of making a simple "talking parrot" app

by Marko 艩tamcar » Wed, 30 Jun 2010 02:51:36 GMT


Sponsored Links
 Is the following code (especially the listen() function) a proper way
to do it? I'm not exactly happy with the sound quality I get from
it... thanks for your help/comments in advance!

Marko

------

public class Main extends Activity {

    private volatile Thread listener;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        listen();
    }

    @Override
    protected void onPause() {
        super.onPause();
        stopListen();
    }

    private void listen() {
        listener = new Thread() {
            @Override
            public void run() {
                Thread thisThread = Thread.currentThread();
 
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

                int bufferRead = 0;
                int bufferSize = AudioRecord.getMinBufferSize(8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
                short[] tempBuffer = new short[bufferSize];

                AudioRecord ar = new
AudioRecord(MediaRecorder.AudioSource.MIC, 8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, bufferSize);
                ar.startRecording();

                AudioTrack at = new
AudioTrack(AudioManager.STREAM_MUSIC, 8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, bufferSize * 2,
AudioTrack.MODE_STREAM);
                at.play();

                while (true) {
                    if (listener != thisThread) {
                        ar.stop();
                        ar.release();
                        at.stop();
                        at.release();
                        break;
                    }
                    bufferRead = ar.read(tempBuffer, 0, bufferSize);
                    at.write(tempBuffer, 0, bufferRead);
                }

            }
        };
        listener.start();
    }

    private void stopListen() {
        listener = null;
    }
}

--



Other Threads

1. Maven Integration for Android Development Tools 0.2.3 Released

Hi All

I just released version 0.2.3 of Maven Integration for Android
Development Tools (m2eclipse-android-integration): an Eclipse plug-in
adding integration support for M2Eclipse with the Android Developer
Tools (ADT) and the Maven Android Plugin.

With the m2eclipse-android-integration plug-in you can continue to build
your Android projects in Eclipse while taking advantage of Maven's
powerful project management features, including automatic project
configuration and dependency management.

The Getting Started wiki page details how to install and use the
plug-in:

http://code.google.com/p/m2eclipse-android-integration/wiki/GettingStarted

This is the first public beta release in anticipation of a fully working
0.3.0 release so it maybe buggy. If you find any issues or missing
features please report them here:

http://code.google.com/p/m2eclipse-android-integration/issues/entry

Or just send an email to the mailing list:

2. how to Log in to a website and retrieve messages and other information?

Hi,
I am a new developer to the android platform and I want to know..
is there any way that I can build an app that log in to a particular
website,
and then retrieve the information of that account..such as
messages,images...etc
<--if you have a useful link I will appreciate it..;)

thank you in advance..:)

-- 

3. adb shell command error

4. How can I return from BluetoothServerSocket.accept()?

5. How to access and deal with a website using a standalone app?

6. LGPL on Android

7. Error in the market: "Upload a valid APK."