ai.api.android.AIConfiguration Java Examples
The following examples show how to use
ai.api.android.AIConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProtocolTestBase.java From dialogflow-android-client with Apache License 2.0 | 6 votes |
@Test public void errorVoiceRequestTest() { final AIConfiguration config = new AIConfiguration("WRONG_ACCESS_TOKEN", AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); updateConfig(config); final AIDataService aiDataService = new AIDataService(RuntimeEnvironment.application, config); final InputStream voiceStream = getClass().getClassLoader().getResourceAsStream("what_is_your_name.raw"); try { aiDataService.voiceRequest(voiceStream); assertTrue("Method should produce exception", false); } catch (final AIServiceException e) { assertNotNull(e.getResponse()); assertEquals("unauthorized", e.getResponse().getStatus().getErrorType()); assertEquals("Authorization failed. Please check your access keys.", e.getMessage()); } }
Example #2
Source File: ProtocolTestBase.java From dialogflow-android-client with Apache License 2.0 | 6 votes |
@Test public void errorTextRequestTest() { final AIConfiguration config = new AIConfiguration("WRONG_ACCESS_TOKEN", AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); updateConfig(config); final AIDataService aiDataService = new AIDataService(RuntimeEnvironment.application, config); final AIRequest aiRequest = new AIRequest(); aiRequest.setQuery("Hello"); try { aiDataService.request(aiRequest); assertTrue("Method should produce exception", false); } catch (final AIServiceException e) { assertNotNull(e.getResponse()); assertEquals("unauthorized", e.getResponse().getStatus().getErrorType()); assertEquals("Authorization failed. Please check your access keys.", e.getMessage()); } }
Example #3
Source File: ProtocolTestBase.java From dialogflow-android-client with Apache License 2.0 | 6 votes |
@Test public void testBrazilLanguage() throws AIServiceException { final AIConfiguration config = new AIConfiguration(getPtBrAccessToken(), AIConfiguration.SupportedLanguages.PortugueseBrazil, AIConfiguration.RecognitionEngine.System); updateConfig(config); final AIDataService aiDataService = new AIDataService(RuntimeEnvironment.application, config); final AIRequest aiRequest = new AIRequest(); aiRequest.setQuery("oi"); final AIResponse aiResponse = makeRequest(aiDataService, aiRequest); assertFalse(TextUtils.isEmpty(aiResponse.getResult().getResolvedQuery())); assertEquals("helloAction", aiResponse.getResult().getAction()); assertEquals("como você está", aiResponse.getResult().getFulfillment().getSpeech()); }
Example #4
Source File: MainActivity.java From Krishi-Seva with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listenButton = (Button) findViewById(R.id.listenButton); resultTextView = (TextView) findViewById(R.id.resultTextView); final AIConfiguration config = new AIConfiguration("1e03efe2dfdc4a37a3e21e5d1056a4ec", AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); int permission = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO); if (permission != PackageManager.PERMISSION_GRANTED) { Log.i(TAG, "Permission to record denied"); makeRequest(); } aiService = AIService.getService(this, config); aiService.setListener(this); }
Example #5
Source File: ProtocolTestBase.java From dialogflow-android-client with Apache License 2.0 | 6 votes |
@Test public void testRussianLanguage() throws AIServiceException { final AIConfiguration config = new AIConfiguration(getRuAccessToken(), AIConfiguration.SupportedLanguages.Russian, AIConfiguration.RecognitionEngine.System); updateConfig(config); final AIDataService aiDataService = new AIDataService(RuntimeEnvironment.application, config); final AIRequest aiRequest = new AIRequest("привет"); final AIResponse aiResponse = makeRequest(aiDataService, aiRequest); assertFalse(TextUtils.isEmpty(aiResponse.getResult().getResolvedQuery())); assertEquals("helloAction", aiResponse.getResult().getAction()); assertEquals("Добрый день", aiResponse.getResult().getFulfillment().getSpeech()); }
Example #6
Source File: ProtocolTestBase.java From dialogflow-android-client with Apache License 2.0 | 6 votes |
@Test @Ignore("Voice recognition is not supported anymore") public void outputContextVoiceTest() throws AIServiceException { final AIConfiguration config = new AIConfiguration(getAccessToken(), AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.Speaktoit); updateConfig(config); final AIDataService aiDataService = new AIDataService(RuntimeEnvironment.application, config); final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("what_is_your_name.raw"); final AIResponse aiResponse = aiDataService.voiceRequest(inputStream); assertNotNull(aiResponse); assertFalse(aiResponse.getStatus().getErrorDetails(), aiResponse.isError()); assertFalse(TextUtils.isEmpty(aiResponse.getId())); assertNotNull(aiResponse.getResult()); final String resolvedQuery = aiResponse.getResult().getResolvedQuery(); assertFalse(TextUtils.isEmpty(resolvedQuery)); assertTrue(resolvedQuery.contains("what is your")); assertContainsContext(aiResponse, "name_question"); }
Example #7
Source File: AIButtonSampleActivity.java From dialogflow-android-client with Apache License 2.0 | 6 votes |
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_aibutton_sample); resultTextView = (TextView) findViewById(R.id.resultTextView); aiButton = (AIButton) findViewById(R.id.micButton); final AIConfiguration config = new AIConfiguration(Config.ACCESS_TOKEN, AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); config.setRecognizerStartSound(getResources().openRawResourceFd(R.raw.test_start)); config.setRecognizerStopSound(getResources().openRawResourceFd(R.raw.test_stop)); config.setRecognizerCancelSound(getResources().openRawResourceFd(R.raw.test_cancel)); aiButton.initialize(config); aiButton.setResultsListener(this); }
Example #8
Source File: GoogleRecognitionServiceImpl.java From dialogflow-android-client with Apache License 2.0 | 6 votes |
public GoogleRecognitionServiceImpl(final Context context, final AIConfiguration config) { super(config, context); final ComponentName component = RecognizerChecker.findGoogleRecognizer(context); if (component == null) { Log.w(TAG, "Google Recognizer application not found on device. " + "Quality of the recognition may be low. Please check if Google Search application installed and enabled."); } versionConfig = VersionConfig.init(context); if (versionConfig.isAutoStopRecognizer()) { stopRunnable = new Runnable() { @Override public void run() { stopListening(); } }; } }
Example #9
Source File: V20150415ProtocolTest.java From dialogflow-android-client with Apache License 2.0 | 6 votes |
@Test public void legacyContextsWithoutParametersTest() throws AIServiceException { final AIConfiguration config = new AIConfiguration( "3485a96fb27744db83e78b8c4bc9e7b7", AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); config.setProtocolVersion(PROTOCOL_VERSION); final AIDataService aiDataService = new AIDataService(RuntimeEnvironment.application, config); final AIContext weatherContext = new AIContext("weather"); weatherContext.setParameters(Collections.singletonMap("location", "London")); final List<AIContext> contexts = Collections.singletonList(weatherContext); final AIRequest aiRequest = new AIRequest(); aiRequest.setQuery("and for tomorrow"); aiRequest.setContexts(contexts); final AIResponse aiResponse = aiDataService.request(aiRequest); // Old protocol doesn't support parameters, so response will not contains city name assertEquals("Weather in for tomorrow", aiResponse.getResult().getFulfillment().getSpeech()); }
Example #10
Source File: AIDialog.java From dialogflow-android-client with Apache License 2.0 | 6 votes |
public AIDialog(final Context context, final AIConfiguration config, final int customLayout) { this.context = context; this.config = config; dialog = new Dialog(context); handler = new Handler(Looper.getMainLooper()); dialog.setCanceledOnTouchOutside(true); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(customLayout); partialResultsTextView = (TextView) dialog.findViewById(R.id.partialResultsTextView); aiButton = (AIButton) dialog.findViewById(R.id.micButton); aiButton.initialize(config); setAIButtonCallback(aiButton); }
Example #11
Source File: MainActivity.java From Build-an-AI-Startup-with-PyTorch with MIT License | 5 votes |
private void initService(final LanguageConfig languageConfig) { final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(languageConfig.getLanguageCode()); final AIConfiguration config = new AIConfiguration(languageConfig.getAccessToken(), lang, AIConfiguration.RecognitionEngine.System); aiDataService = new AIDataService(this, config); }
Example #12
Source File: ProtocolTestBase.java From dialogflow-android-client with Apache License 2.0 | 5 votes |
@Test public void sessionTest() throws AIServiceException { final AIConfiguration config = new AIConfiguration(getAccessToken(), AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); updateConfig(config); final AIDataService firstService = new AIDataService(RuntimeEnvironment.application, config); final AIDataService secondService = new AIDataService(RuntimeEnvironment.application, config); { final AIRequest weatherRequest = new AIRequest(); weatherRequest.setQuery("weather"); final AIResponse weatherResponse = makeRequest(firstService, weatherRequest); assertNotNull(weatherResponse); } { final AIRequest checkSecondRequest = new AIRequest(); checkSecondRequest.setQuery("check weather"); final AIResponse checkSecondResponse = makeRequest(secondService, checkSecondRequest); assertNotNull(checkSecondResponse.getResult().getAction()); } { final AIRequest checkFirstRequest = new AIRequest(); checkFirstRequest.setQuery("check weather"); final AIResponse checkFirstResponse = makeRequest(firstService, checkFirstRequest); assertNotNull(checkFirstResponse.getResult().getAction()); assertTrue(checkFirstResponse.getResult().getAction().equalsIgnoreCase("checked")); } }
Example #13
Source File: ProtocolTestBase.java From dialogflow-android-client with Apache License 2.0 | 5 votes |
private AIDataService createDataService(final String accessToken) { final AIConfiguration config = new AIConfiguration(accessToken, AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); updateConfig(config); SessionIdStorage.resetSessionId(RuntimeEnvironment.application); return new AIDataService(RuntimeEnvironment.application, config); }
Example #14
Source File: ProtocolTestBase.java From dialogflow-android-client with Apache License 2.0 | 5 votes |
private AIDataService createDataService() { final AIConfiguration config = new AIConfiguration(getAccessToken(), AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); updateConfig(config); SessionIdStorage.resetSessionId(RuntimeEnvironment.application); return new AIDataService(RuntimeEnvironment.application, config); }
Example #15
Source File: AIButton.java From dialogflow-android-client with Apache License 2.0 | 5 votes |
public void initialize(final AIConfiguration config) { aiService = AIService.getService(getContext(), config); aiService.setListener(this); if (aiService instanceof GoogleRecognitionServiceImpl) { ((GoogleRecognitionServiceImpl) aiService).setPartialResultsListener(new PartialResultsListener() { @Override public void onPartialResults(final List<String> partialResults) { if (partialResultsListener != null) { partialResultsListener.onPartialResults(partialResults); } } }); } }
Example #16
Source File: AITextSampleActivity.java From dialogflow-android-client with Apache License 2.0 | 5 votes |
private void initService(final LanguageConfig selectedLanguage) { final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(selectedLanguage.getLanguageCode()); final AIConfiguration config = new AIConfiguration(selectedLanguage.getAccessToken(), lang, AIConfiguration.RecognitionEngine.System); aiDataService = new AIDataService(this, config); }
Example #17
Source File: AIDialogSampleActivity.java From dialogflow-android-client with Apache License 2.0 | 5 votes |
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_aidialog_sample); resultTextView = (TextView) findViewById(R.id.resultTextView); final AIConfiguration config = new AIConfiguration(Config.ACCESS_TOKEN, AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); aiDialog = new AIDialog(this, config); aiDialog.setResultsListener(this); }
Example #18
Source File: AIServiceSampleActivity.java From dialogflow-android-client with Apache License 2.0 | 5 votes |
private void initService(final LanguageConfig selectedLanguage) { final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(selectedLanguage.getLanguageCode()); final AIConfiguration config = new AIConfiguration(selectedLanguage.getAccessToken(), lang, AIConfiguration.RecognitionEngine.System); if (aiService != null) { aiService.pause(); } aiService = AIService.getService(this, config); aiService.setListener(this); }
Example #19
Source File: MainActivity.java From dialogflow-java-client with Apache License 2.0 | 5 votes |
@Override protected void onResume() { super.onResume(); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); String address = settings.getString("pref_ipAddress", ""); addressEdit.setText(address); final AIConfiguration config = new AIConfiguration( settings.getString("pref_apiKey", "a07bc2127c61497fad437dd8c197f951"), AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); aiButton.initialize(config); aiButton.setResultsListener(new AIButton.AIButtonListener() { @Override public void onResult(AIResponse aiResponse) { if (!aiResponse.isError()) { Log.i(TAG, aiResponse.getResult().getResolvedQuery()); commandText.setText(aiResponse.getResult().getAction()); processResponse(aiResponse); } else { commandText.setText(aiResponse.getStatus().getErrorDetails()); } } @Override public void onError(AIError aiError) { commandText.setText(aiError.getMessage()); } @Override public void onCancelled() { } }); }
Example #20
Source File: MainActivity.java From android-dialogflow-chatbot-sample with MIT License | 5 votes |
private void initService(final LanguageConfig languageConfig) { final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(languageConfig.getLanguageCode()); final AIConfiguration config = new AIConfiguration(languageConfig.getAccessToken(), lang, AIConfiguration.RecognitionEngine.System); aiDataService = new AIDataService(this, config); }
Example #21
Source File: MainActivity.java From DialogflowChat with Apache License 2.0 | 5 votes |
private void initChatbot() { final AIConfiguration config = new AIConfiguration(BuildConfig.ClientAccessToken, AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); aiDataService = new AIDataService(this, config); customAIServiceContext = AIServiceContextBuilder.buildFromSessionId(uuid);// helps to create new session whenever app restarts aiRequest = new AIRequest(); }
Example #22
Source File: MainActivity.java From Watch-Me-Build-a-Finance-Startup with MIT License | 5 votes |
private void initService(final LanguageConfig languageConfig) { final AIConfiguration.SupportedLanguages lang = AIConfiguration.SupportedLanguages.fromLanguageTag(languageConfig.getLanguageCode()); final AIConfiguration config = new AIConfiguration(languageConfig.getAccessToken(), lang, AIConfiguration.RecognitionEngine.System); aiDataService = new AIDataService(this, config); }
Example #23
Source File: AIDialog.java From dialogflow-android-client with Apache License 2.0 | 4 votes |
public AIDialog(final Context context, final AIConfiguration config) { this(context, config, R.layout.aidialog); }
Example #24
Source File: SpeaktoitRecognitionServiceImpl.java From dialogflow-android-client with Apache License 2.0 | 4 votes |
public SpeaktoitRecognitionServiceImpl(final Context context, final AIConfiguration config) { super(config, context); init(); }
Example #25
Source File: SimpleProtocolTestingService.java From dialogflow-android-client with Apache License 2.0 | 4 votes |
public SimpleProtocolTestingService(final Context context, final AIConfiguration config) { super(context, config); }
Example #26
Source File: AIWidgetActivity.java From dialogflow-android-client with Apache License 2.0 | 4 votes |
@Override protected void onCreate(final Bundle savedInstanceState) { supportRequestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.activity_widget_sample); final AIConfiguration config = new AIConfiguration(Config.ACCESS_TOKEN, AIConfiguration.SupportedLanguages.English, AIConfiguration.RecognitionEngine.System); aiDialog = new AIDialog(this, config); aiDialog.setResultsListener(new AIDialog.AIDialogListener() { @Override public void onResult(final AIResponse aiResponse) { // TODO Process aiResponse aiDialog.close(); Toast.makeText(getApplicationContext(), String.format("%s %s","Successful response: ", aiResponse.getResult().getResolvedQuery()), Toast.LENGTH_SHORT).show(); AIWidgetActivity.this.finish(); } @Override public void onError(final AIError aiError) { // TODO show error message aiDialog.close(); Toast.makeText(getApplicationContext(), aiError.getMessage(), Toast.LENGTH_SHORT).show(); AIWidgetActivity.this.finish(); } @Override public void onCancelled() { aiDialog.close(); Toast.makeText(getApplicationContext(), "Process cancelled", Toast.LENGTH_SHORT).show(); AIWidgetActivity.this.finish(); } }); aiDialog.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(final DialogInterface dialog) { Toast.makeText(getApplicationContext(), "Dialog dismissed by user", Toast.LENGTH_SHORT).show(); AIWidgetActivity.this.finish(); } }); }
Example #27
Source File: ProtocolTestBase.java From dialogflow-android-client with Apache License 2.0 | 2 votes |
protected void updateConfig(final AIConfiguration config) { }