I,m trying to work through and test a Voice Recognition example based on the VoiceRecognition.java example at http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html
but when click on the button to create the activity, I get a dialog that says Connection problem. My Manifest file is using the Internet Permission, and I understand it passes the to the Google Servers. Do I need to do anything else to use this. Code below
UPDATE 2:
Thanks to Steve, I have been able to install the USB Driver and debug the app directly on my Droid. Here is the LogCat output from clicking on my mic button:
03-08 18:36:45.686: INFO/ActivityManager(1017): Starting activity: Intent { act=android.speech.action.RECOGNIZE_SPEECH cmp=com.google.android.voicesearch/.IntentApiActivity (has extras) }
03-08 18:36:45.686: WARN/ActivityManager(1017): Activity is launching as a new task, so cancelling activity result.
03-08 18:36:45.787: DEBUG/NetworkLocationProvider(1017): setMinTime: 120000
03-08 18:36:45.889: INFO/ActivityManager(1017): Displayed activity com.google.android.voicesearch/.IntentApiActivity: 135 ms (total 135 ms)
03-08 18:36:45.905: DEBUG/NetworkLocationProvider(1017): onCellLocationChanged [802,0,0,4192,3]
03-08 18:36:45.951: INFO/MicrophoneInputStream(1429): Starting voice recognition with audio source VOICE_RECOGNITION
03-08 18:36:45.998: DEBUG/AudioHardwareMot(990): Codec sampling rate already 16000
03-08 18:36:46.092: INFO/RecognitionService(1429): ssfe url=http://www.google.com/m/voice-search
03-08 18:36:46.092: WARN/RecognitionService(1429): required parameter 'calling_package' is missing in IntentAPI request
03-08 18:36:46.115: DEBUG/AudioHardwareMot(990): Codec sampling rate already 16000
03-08 18:36:46.131: WARN/InputManagerService(1017): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy#4487d240 (uid=10090 pid=3132)
03-08 18:36:46.131: WARN/IInputConnectionWrapper(3132): showStatusIcon on inactive InputConnection
03-08 18:36:46.248: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.334: DEBUG/dalvikvm(3206): GC freed 3682 objects / 369416 bytes in 293ms
03-08 18:36:46.358: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.412: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.444: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.475: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.506: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
The line that concerns me is the warning of the missing parameter calling-package.
UPDATE:
Ok, I was able to replace my emulator image with one from HTC that appears to come with Google Voice Search, however now when I run from the emulator, i'm getting an Audio Problem message with Speak Again or Cancel buttons. It appears to make it back to the onActivityResult(), but the resultCode is 0.
Here is the LogCat output:
03-07 20:21:25.396: INFO/ActivityManager(578): Starting activity: Intent { action=android.speech.action.RECOGNIZE_SPEECH comp={com.google.android.voicesearch/com.google.android.voicesearch.RecognitionActivity} (has extras) }
03-07 20:21:25.406: WARN/ActivityManager(578): Activity is launching as a new task, so cancelling activity result.
03-07 20:21:25.968: WARN/ActivityManager(578): Activity pause timeout for HistoryRecord{434f7850 {com.ikonicsoft.mileagegenie/com.ikonicsoft.mileagegenie.MileageGenie}}
03-07 20:21:26.206: WARN/AudioHardwareInterface(554): getInputBufferSize bad sampling rate: 16000
03-07 20:21:26.256: ERROR/AudioRecord(819): Recording parameters are not supported: sampleRate 16000, channelCount 1, format 1
03-07 20:21:26.696: INFO/ActivityManager(578): Displayed activity com.google.android.voicesearch/.RecognitionActivity: 1295 ms
03-07 20:21:29.890: DEBUG/dalvikvm(806): threadid=3: still suspended after undo (s=1 d=1)
03-07 20:21:29.896: INFO/dalvikvm(806): Uncaught exception thrown by finalizer (will be discarded):
03-07 20:21:29.896: INFO/dalvikvm(806): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor#435d3c50 on ml_trackdata that has not been deactivated or closed
03-07 20:21:29.896: INFO/dalvikvm(806): at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
03-07 20:21:29.896: INFO/dalvikvm(806): at dalvik.system.NativeStart.run(Native Method)
03-07 20:21:31.468: DEBUG/dalvikvm(806): threadid=5: still suspended after undo (s=1 d=1)
03-07 20:21:32.436: WARN/IInputConnectionWrapper(806): showStatusIcon on inactive InputConnection
I,m still not sure why I,m getting the Connect problem on the Droid. I can use Voice Search ok. I also tried clearing the cache, and data as described in some posts, butstill not working??
/**
* Fire an intent to start the speech recognition activity.
*/
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handle the results from the recognition activity.
*/
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
// Fill the list view with the strings the recognizer thought it could have heard
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
matches));
}
super.onActivityResult(requestCode, resultCode, data);
}
Ok... problem fixed.
It appears you cannot use android:launchMode="singleInstance" when using the RecognizerIntent. I removed this from the manifest and the Voice Search runs correctly.
Thanks again Steve, for the info on USB debugging on the device. Very handy.
You can also use android:launchMode="singleTask"
It works fine with VS.
Related
I have a MusicService for MediaPlayback, wich uses a MediaPlayer with the settings:
player.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
and those Listeners are set:
OnPreparedListener, OnCompletionListener, OnErrorListener, OnSeekCompleteListener
The MediaPlayer is used for mp3-Playback. When one Song is finished, onCompletion is called. Then PlayNext is called, wich resets the MediaPlayer, then sets the Datasource with the URI of the next Track. Uri is loaded with:
Uri trackUri = ContentUris
.withAppendedId(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, songId);
Then the Player is prepared, then the player is started. This is working fine, but only sometimes, when the Device is locked and played about 1-3 Songs while it was locked and the next Song should start, the Player doesn't prepare until i hit the power button. Figured out, that if I don't hit the PowerButton it takes the Player about 2 Minutes to prepare.
I've Logged everything now and made a few custom outputs with Log.e(...).
This is put out before prepare() (prepareAsync() delivers the same result) is called:
E/MusicService: Preparing now...
This is put out, when onPrepared is called:
E/MusicService: Player prepared.
So this is the full Device-Output after "Preparing now..." is put out:
04-02 13:54:55.506 12517-12517/at.htlleonding.musync E/MusicService: Preparing now.
04-02 13:54:55.525 811-888/? E/libsuspend: Error writing to /sys/power/state: Device or resource busy
04-02 13:54:55.544 246-14756/? D/offload_visualizer: thread exit
04-02 13:54:55.546 246-14754/? V/offload_effect_bundle: offload_effects_bundle_hal_stop_output output 1879 pcm_id 9
04-02 13:54:55.546 246-14754/? D/hardware_info: hw_info_append_hw_type : device_name = speaker
04-02 13:54:55.549 246-14752/? E/audio_hw_primary: offload_thread_loop: Compress handle is NULL
04-02 13:54:55.549 246-924/? D/audio_hw_primary: adev_close_output_stream: enter:stream_handle(0xb5bfa640)
04-02 13:54:55.549 246-924/? D/audio_hw_primary: out_standby: enter: stream (0xb5bfa640) usecase(3: compress-offload-playback)
04-02 13:54:55.555 246-924/? W/AudioFlinger: moveEffectChain_l() effect chain for session 0 not on source thread 0xb59fa000
04-02 13:54:55.611 246-15030/? I/FFmpegExtractor: android-source:0xb1834060
04-02 13:54:55.820 811-888/? E/libsuspend: Error writing to /sys/power/state: Device or resource busy
04-02 13:54:55.972 246-15030/? I/FFMPEG: [mp3 # 0xae2f4400] Skipping 0 bytes of junk at 2177007.
... Then theres no output until i hit the PowerButton. Then the Song is prepared.
If someone is interested in the full output after I hit the PowerButton until "Player prepared" is called, I created a Gist here.
Sidenote:
While the App is used, a few Album-Covers are displayed in some Fragments. They are loaded with Picasso, so I don't need to worry about memory caching. Some ImageViews are filled without Picasso (for example the ImageViews that hold the drawables of my PlayerControls). Maybe there are Problems with the memory/resources?
I might have found the answer in another thread where some faced the same problem while streaming music here.
My final solution is to use a WakeLock, wich I require before preparing a Song and release again onPrepared and onError and onDestroy of my Service. It's important to release it again to save Battery. Make sure to check if the WakeLock is held before releasing it.
I create my WakeLock like this in onCreate of my Service:
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MusicService");
aquire:
wakeLock.acquire();
release:
if(wakeLock.isHeld())
wakeLock.release();
Tested the Playback now for about 10 Minutes and didn't stop until now. I don't know if this is a very battery-saving solution
i am trying to make a voice reminder which take a text to be remembered and on the time the application convert the text to say it in voice i did the code of the reminder and i create another class extend broad cast receiver and did the code to the reminder to fire in time but it run when i make it show a toast but when i write the code of the speech in the receiver to fire in the time set but it gives me " the application force to close" could you please answer me i wrote this in the onreceive but it doesn't work
public class ReadyToSpeak extends BroadcastReceiver
{
VoiceAlert voicealert= new VoiceAlert();
#Override
public void onReceive(Context context, Intent intent){
// TODO Auto-generated method stub
Intent scheduledIntent = new Intent(context,VoiceAlert.class);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(scheduledIntent);
Toast.makeText(context, "onresive", Toast.LENGTH_LONG).show();
// voicealert.speak();
voicealert.txs.speak("Hello", TextToSpeech.QUEUE_FLUSH, null);
}
}
I did the code all over again and didn't work and that is what appear in the logcat
10-27 10:23:06.920: WARN/KeyCharacterMap(127): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-27 10:23:12.671: WARN/KeyCharacterMap(119): No keyboard for id 0
10-27 10:23:12.671: WARN/KeyCharacterMap(119): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-27 10:23:14.081: DEBUG/dalvikvm(127): GC_EXPLICIT freed 2068 objects / 132776 bytes in 77ms
10-27 10:23:33.990: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=org.anddev.android.speechreminder/.ReminderActivity }
10-27 10:23:34.470: INFO/ActivityManager(58): Starting activity: Intent { act=android.speech.tts.engine.CHECK_TTS_DATA cmp=com.svox.pico/.CheckVoiceData }
10-27 10:23:34.710: INFO/ActivityManager(58): Displayed activity org.anddev.android.speechreminder/.ReminderActivity: 577 ms (total 577 ms)
10-27 10:23:34.720: WARN/KeyCharacterMap(313): No keyboard for id 0
10-27 10:23:34.720: WARN/KeyCharacterMap(313): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-27 10:23:34.780: VERBOSE/TtsService(319): TtsService.onCreate()
10-27 10:23:34.830: VERBOSE/TtsService(319): About to load /system/lib/libttspico.so, applyFilter=true
10-27 10:23:34.910: VERBOSE/TtsService(319): TtsService.setLanguage(eng, USA, )
10-27 10:23:35.120: INFO/ActivityManager(58): Process com.android.alarmclock (pid 170) has died.
10-27 10:23:35.141: INFO/SVOX Pico Engine(319): loaded en-US successfully
10-27 10:23:35.141: INFO/SynthProxy(319): setting speech rate to 100
10-27 10:23:44.870: DEBUG/dalvikvm(296): GC_EXPLICIT freed 1918 objects / 108296 bytes in 159ms
10-27 10:23:49.990: WARN/KeyCharacterMap(114): No keyboard for id 0
10-27 10:23:50.001: WARN/KeyCharacterMap(114): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-27 10:24:18.050: WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#44fe6228
10-27 10:24:20.550: DEBUG/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
Taghrid, It looks like you're getting a Stackoverflow error. This indicates that somewhere in your code you have Infinite recursion. It looks like it's VoiceAlert and ReadyToSpeak functions that keep calling one another. Are you sure the package your using, org.androiddev.android.test is of good quality? Are you using a release version of it?
I'm using an extra thread for AudioTrack to play back a wave file I have previously recorded in another activity.
When I start playback, I get the following output in LogCat:
09-13 09:13:13.207: WARN/Archive(1066): audioplayThread is running..., state is: READY
09-13 09:13:21.187: WARN/Archive(1066): wave file /mnt/sdcard/myrecording/myrecording_3_12-09-2011_14-14.wav
09-13 09:13:22.582: WARN/Archive(1066): audioPlayer bufferSize 4090
09-13 09:13:22.582: WARN/Archive(1066): audioPlayer wave length 206432
09-13 09:13:22.601: DEBUG/AudioHardware(75): AudioHardware pcm playback is exiting standby.
09-13 09:13:22.601: DEBUG/AudioHardware(75): openPcmOut_l() mPcmOpenCnt: 0
09-13 09:13:22.683: WARN/AudioFlinger(75): write blocked for 82 msecs, 1 delayed writes, thread 0xcb08
09-13 09:13:24.816: WARN/Archive(1066): playbackHeadposition is: 49591
09-13 09:13:24.816: WARN/Archive(1066): audiostate is: 3
09-13 09:13:26.089: WARN/AudioTrack(1066): obtainBuffer() track 0x298b18 disabled, restarting
09-13 09:13:27.214: WARN/AudioTrack(1066): obtainBuffer() track 0x298b18 disabled, restarting
09-13 09:13:28.332: WARN/AudioTrack(1066): obtainBuffer() track 0x298b18 disabled, restarting
09-13 09:13:29.457: WARN/AudioTrack(1066): obtainBuffer() track 0x298b18 disabled, restarting
...
I just saw the logcat: obtainBuffer() track 0x298b18 disabled, restarting ..
that is to say : you have not got audio data and the input audio stream have been stopped .so the buffer must wait for the audio stream in. i think you should check the inputstream and the read method. you must ensure that you have read the audio data continuously.
I've had the same problem before. I used vitamio bundle which is a counterpart of Android's Media Player and has more audio support. Try adding this code to your manifest:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I hope this helped.
I have observed the same issue when number of written samples is not divisible by number of channels.
For example:
number of channels: 2
mAudioTrack.write(buffer, 0, 75);
Some users of our app are reporting that ringtones fail to load as expected. I've included a typical logcat output from one of these users below. It seems that the request for the default ringtone is returning null ("Failed to open ringtone content://settings/system/ringtone"). I've asked these users to change ringtones, and sometimes this resolves the issue, but in other cases (HTC Hero in both the ones I know of) changing the ringtone does not fix the problem. I have been unable to reproduce this problem on any of our test devices. Any thoughts as to what might cause this, how to debug, or how to resolve?
D/Ringtone( 743): create mAudio
D/MediaPlayer( 743): setDataSource(44, 0, 576460752303423487) pid = 743
E/Mp3HwPlayer( 56): ID:24, new Mp3HwPlayer
E/MediaPlayerService( 56): getPlayerType(): Has ID3 info, size = 1024
E/MediaPlayerService( 56): getPlayerType(): Input buffer is MPA format
E/Mp3HwPlayer( 56): ID:24, destory Mp3HwPlayer
D/MediaPlayerService( 56): Create Player playertype=6
D/MediaPlayerService( 56): new PVPlayer for MP3
D/PVPlayer( 56): setDataSource(25, 0, 180143)
D/MediaPlayerService( 56): MediaPlayerService::Client::setDataSource exit
D/MediaPlayerService( 56): returned from setDataSource() in MediaPlayerService::create
D/MediaPlayerService( 56): [23] prepareAsync
I/PlayerDriver( 56): OpenCore disable firewall payload
W/MediaPlayer( 743): info/warning (1, 26)
E/PlayerDriver( 56): Command PLAYER_PREPARE completed with an error or info PVMFErrResource
E/MediaPlayer( 743): error (1, -17)
E/RingtoneManager( 743): Failed to open ringtone content://settings/system/ringtone
E/RingtoneManager( 743): unable to find a usable ringtone
E/IncomingRinger( 743): Couldn't find a ringtone for URI: content://settings/system/ringtone
It looks like the ringtone is stored on a SD card, and you haven't permission to read SD data, so it returns null. I got similar problem with my mediaPlayer.
My application plays ShoutCast Streaming and the target OS is 1.6 and above. I have applied some code from NPR application with some modification.
Here is the code
mediaPlayer = new MediaPlayer();
mediaPlayer.reset();
mediaPlayer.setDataSource(url);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// Log.d(LOG_TAG, "Preparing: " + playUrl);
mediaPlayer.prepareAsync();
mediaPlayer.start();`
The code doesnot play anything on simulator or device(Testing in Samsung Galaxy with 2.1).
Here is the LogCat message.
About to play http://88.191.81.31:8206
12-08 14:16:42.229: WARN/MediaPlayer(5520): info/warning (1, 26)
12-08 14:16:42.239: ERROR/PlayerDriver(1870): Command PLAYER_INIT completed with an error or info PVMFFailure
12-08 14:16:42.239: ERROR/MediaPlayer(5520): error (1, -1)
12-08 14:16:42.239: WARN/PlayerDriver(1870): PVMFInfoErrorHandlingComplete
12-08 14:16:42.259: ERROR/MediaPlayer(5520): start called in state 0
12-08 14:16:42.259: ERROR/MediaPlayer(5520): error (-38, 0)
12-08 14:16:42.299: INFO/MediaPlayer(5520): Info (1,26)
12-08 14:16:42.299: ERROR/MediaPlayer(5520): Error (1,-1)
12-08 14:16:42.304: ERROR/MediaPlayer(5520): Error (-38,0)
Here is the question. 1. Can you tell me whats happening in device? 2. How to solve this error?.
You are calling start() too soon. Javadocs of MediaPlayer explain it (look at the picture):
Either you have to call prepare() before you call start(), or
You call prepareAsync() and wait for OnPreparedListener.onPrepared() to be called, then (possibly inside this method) call start().
Updated:
Shoutcast streams are nativelly supported only on 2.2. For earlier versions you must create local proxy that changes the response protocol from ICY (shoutcast) to HTTP, which the
mediaplayer will support. Take a look at this:
http://code.google.com/p/npr-android-app/source/browse/trunk/Npr/src/org/npr/android/news/StreamProxy.java
This has previously been discussed:
Listen to a shoutcast with Android