I want to output the speech to traditional chinese but it output to simplify chinese instead. My codes:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "zh-TW");
I also tried to set EXTRA_LANGUAGE to "zh_TW", "TW" and Locale.TAIWAN but it doesn't work too.
In my Android 7.0 settings "Traditional Chinese"(繁體中文) is added in Language preferences. I able to select it in keyboard & type it.
Is this a bug of google speech recognizer?
Finally I found the solution, need to use
cmn-Hant-TW for EXTRA_LANGUAGE.
Google documentation is sucks.
I want to create an Android app which can play songs from cloud (using Saavn/Google Music/ Hungama/Gaana/Spotify/SoundCloud etc.) using some APIs or intents. Is there any way to do that?
I already tried by passing as an intent_action_media_play_from_search from my app but that doesn't play song directly through the streaming app and it shows ambiguous screen.
And in google music it plays some random radio corresponding that.
try {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
/* intent.setComponent(new ComponentName(
"com.google.android.music",
"com.google.android.music.ui.search.VoiceActionsActivity"));*/
//intent.putExtra(SearchManager.QUERY, "Song_name");
intent.putExtra(SearchManager.QUERY, "Song_name");
v.getContext().startActivity(intent);
}
I expect it to play the searched song directly or if possible using some APIs, I may receive the ambiguous results and then play with some particular id.
I want to support my app to multiple languages.I implemented for static strings through localization but what i want is if user change app language from English to any other and input Edit text with google voice then that string will b shown in user selected language rather than English language. As in google translate app happens,i input text by voice and what result is found that string is in that selected language.
Can anyone please help me??
There is limited supported language but you need to invoke Speech Recognition by putting extra intent parameter
private void listen() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//Specify language
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.SIMPLIFIED_CHINESE)
// Specify language model
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// Specify how many results to receive
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
// Start listening
startActivityForResult(intent, SR_CODE);
}
check full answer
I'm planning on doing a application for Android 2.1 that changes song every minute (through what I hope exists in Android, "next") for the application using the audio device atm.
So if I have Spotify running in background already, playing music, can I through my program change to the next track?
Let me know if I was unclear about anything.
Thanks in advance!
I know this is a bit old question, but it took me some time searching something other then what is mentioned here.
There is a workaround - broadcasting media button action. There is one catch - receiver can recognize if the broadcast was from system or from another app, so they can ignore the non-system broadcasts.
Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
synchronized (this) {
i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
sendOrderedBroadcast(i, null);
i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT));
sendOrderedBroadcast(i, null);
}
There's no universal audio transport API for music applications, so you'd need to see if the music applications you're targeting publicly expose service bindings or intents. If not, you won't be able to do this.
Just posted a relevant answer here
Using the AudioManager's dispatchMediaKeyEvent() method with a defined KeyEvent worked for me using the latest SDK.
The system music homescreen widget sends this intent for the built-in music player:
final ComponentName serviceName = new ComponentName(context,
MediaPlaybackService.class);
intent = new Intent(MediaPlaybackService.NEXT_ACTION);
intent.setComponent(serviceName);
pendingIntent = PendingIntent.getService(context,
0 /* no requestCode */, intent, 0 /* no flags */);
views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
But it looks like this might take some hackery to implement outside packages in the music app itself because the MediaPlaybackService only accepts explicit Intents and isn't accessible from the outside. This thread seems to indicate it's possible with a bit of hackery, though.
But even then, as Roman said, not every music player will respect that Intent. You'll have to check with Spotify/Pandora/Last.fm themselves and see if they have any available intents to bind like that.
Looks that it's possible to use AudioManager to inject media keys.
Here is a snippet from another question
this.mAudioManager = (AudioManager) this.context.getSystemService(Context.AUDIO_SERVICE);
long eventtime = SystemClock.uptimeMillis();
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT, 0);
mAudioManager.dispatchMediaKeyEvent(downEvent);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT, 0);
mAudioManager.dispatchMediaKeyEvent(upEvent);
The same way you can inject PlayPause button and some others.
I've tested it within a background service controlling Youtube and it worked for Android 6
I want to create an Android application that is a client for an Internet radio station. And I want it look native to Android? But im confused with Android API logic and documentation. What i've got is that I need MediaPlayer and MediaController classes. Am I right, and is there any good example of AUDIO player for Android?
Especially, I'm very interested how to use MediaPlayer and MediaController classes together.
UPD:
Finally I've got the code, that does exactly what I want:
Intent i = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.parse(%file_uri%));
i.setData(u);
startActivity(i);
you can look at those links :
http://www.helloandroid.com/tutorials/musicdroid-audio-player-part-i
Hope it will help.
[EDIT]
You have also some example on the official android developer website :
http://developer.android.com/guide/topics/media/index.html