I need to give users a method to launch their phone's voice assistant from my app, be it Google Now or anything else.
When searching on how to do this I keep finding explanations on how to get voice input while I just want to launch Google Now in "listening" mode. This question clearly asks for the same thing but the accepted answer explains how to open voice input:
How to programmatically initiate a Google Now voice search?
I know this can't be a rare case, how can it be done?
startActivity(new Intent(Intent.ACTION_VOICE_COMMAND).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
worked for me and seems more intuitive.
It is not very clear what exactly you are trying to achieve, but I hope following will be helpful.
The code given at How to programmatically initiate a Google Now voice search? will launch the default speech recognizer (or "voice assistant" as you have put it).
Following, however, will explicitly open (if available) Google's speech recognizer:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.google.android.googlequicksearchbox",
"com.google.android.googlequicksearchbox.VoiceSearchActivity");
try {
startActivity(intent);
} catch (ActivityNotFoundException anfe) {
Log.d(TAG, "Google Voice Search is not found");
}
Related
I am trying to use the googlequicksearchbox to do some actions directly, without the click button confirmation...
for example:
When I click at the mic of Google Now and say "Me acorde às 9:00" (Wake-up me at 9)... Google now makes an alarm for 9 without needing confirmation. Like this:
But if I use this intent:
String query = "Me acorde às 9:00";
final Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.setPackage("com.google.android.googlequicksearchbox");
intent.putExtra(SearchManager.QUERY, query);
startActivity(intent);
to start googlequicksearchbox with the same text that was recognized, Google Now makes the alarm, but now requires confirmation click at the blue button (reminders, etc, also requires). Like that Screenshot >> Screenshot alarm require confirmation
Someone knows some way of make the intent start google search with a query and not requires the click confirmation? like "simulate a google now voice command"??
P.S1.: I am using my own voice recognition inside of my app for other purposes, and I am trying to make the Google Now interpret the voice for just some commands... So, unfortunately, I can't execute the google now voice recog...
P.S2.: I don't know how to interpret the voice (get the hour, minutes, etc.) and make the alarm by the direct intent... then, use the google now to interpret is the best option for me.
I have tried every simple combo I have found but not sure how to do this.
I even tried to simulate the home long press but you get google now voice, lookint at logcat it shows this
com.google.android.googlequicksearchbox/com.google.android.apps.gsa.staticplugins.opa.OpaActivity
but not sure if this is what I am looking for or how to replicate it.
This works:
startActivity(new Intent(Intent.ACTION_VOICE_COMMAND).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
So I've been trying to do the same thing, and just discovered something when I'm trying to launch the Assistant with an Intent like this:
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
launchIntent.setPackage("com.google.android.googlequicksearchbox");
launchIntent.setClassName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.staticplugins.opa.OpaActivity");
startActivity(launchIntent);
Although this doesn't throw an ActivityNotFoundException, it does throw a Permission Denial. This is shown to happen because Google Assistant must be launched from the googlequicksearchbox package from above. Hopefully this will change when/if they release an API for it. Fingers crossed.
I am trying to develop an application for Android wear that on a button click will ask the user to speak something and send it to a webserver. I also need to have a list of pre-defined templates, similar to what Hangouts works.
What I have tried:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Send to server");
startActivityForResult(intent, SPEECH_REQUEST_CODE);
This works, but I cannot supply the user a set of pre-defined templates.
Reading this - https://developer.android.com/training/wearables/notifications/voice-input.html I see that it is possible to do this in a notification... but this will not be in the front, I need this UI to be modal/blocking, so a notification is not good for my use case.
What are my options? How can I implement this?
Unfortunately, other than Receiving Voice Input in a Notification there is no way to use voice recognition with pre-defined text responses.
Based on the documentation : Adding Voice Capabilities
Voice actions are an important part of the wearable experience. They let users carry out actions hands-free and quickly. Wear provides two types of voice actions:
System-provided
These voice actions are task-based and are built into the Wear platform. You filter for them in the activity that you want to start when the voice action is spoken. Examples include "Take a note" or "Set an alarm".
App-provided
These voice actions are app-based, and you declare them just like a launcher icon. Users say "Start " to use these voice actions and an activity that you specify starts.
Also as discussed in 24543484 and 22630600, both implemented a notification in their android to get the voice input.
Hope this helps.
Is there a way to automatically start Google Now on Music Recognition? I'd need it to create a DashClock extension that start Music Recognizing...
As far as I speak, I can start package com.google.android.googlequicksearchbox successfully but I cannot start voice input... I would not use startActivity for result since I would not need a result, I would really just start Google Now voice recognition feature, is there a way to do it programmatically?
Otherwise, to simply launch Google Now Song Recognition service (without having to tap on "Listen to Music", to be clear), you can create an Intent with the string
"com.google.android.googlequicksearchbox.MUSIC_SEARCH";
that would launch directly the proper interface.
I just found a way to achieve my goal:
Intent intent = new Intent();
intent.setClassName("com.google.android.googlequicksearchbox","com.google.android.googlequicksearchbox.VoiceSearchActivity");
starting this intent will bring up voice search window.
So I've searched far and wide for some sort of solution to the issue regarding removing Google's Voice Recognition UI dialog when a user wants to perform a Voice Command but have been unable to find any solution. I am trying to implement an app which displays a menu to the user and the user can either click on the options or say the options out loud which will open the new pages. So far ive been unable to implement this unless I use Googles RecognizerIntent but I dont want the dialog box to pop up. Anyone have any ideas? Or has anyone solved this issue or found a workaround? Thanks
EDIT: As a compromise maybe there is a way to move the dialog to the bottom of the screen while still being able to view my menu?
Does How can I use speech recognition without the annoying dialog in android phones help?
I'm pretty sure the Nuance/Dragon charges for production or commercial applications that use their services. If this is just a demo, you may be fine with the developer account. Android speech services are free for all Android applications.
You know that you can do this with google's APIs.
You've probably been looking at the documentation for the speech recognition intent. Look instead at the RecognitionListener interface to the speech recognition APIs.
Here's some code to help you
public class SpeechRecognizerExample extends Activity implements RecognitionListener{
//This would go down in your onCreate
SpeechRecognizer recognizer = SpeechRecognizer.createSpeechRecognizer(this);
recognizer.setRecognitionListener(this);
//Then you'd need to start it when the user clicks or selects a text field or something
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");
intent.putExtra("calling_package",
"yourcallingpackage");
recognizer.startListening(intent);
//Then you'd need to implement the RecognitionListener functions - basically works just like a click listener
Here's the docs for a RecognitionListener:
http://developer.android.com/reference/android/speech/RecognitionListener.html