• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.car.voicecontrol;
17 
18 import android.content.Context;
19 import android.content.Intent;
20 import android.os.Bundle;
21 import android.speech.SpeechRecognizer;
22 import android.util.Log;
23 
24 import com.android.car.assist.CarVoiceInteractionSession;
25 
26 /**
27  * Sample interaction session. Most of the voice interaction business logic is implemented here.
28  * This sample interaction session uses the {@link SpeechRecognizer} API to implement STT. Other
29  * implementations might choose to access the microphone directly and stream the audio to their
30  * backend services.
31  */
32 public class InteractionSession extends CarVoiceInteractionSession {
33     private static final String TAG = "Mica.Session";
34 
InteractionSession(Context context)35     public InteractionSession(Context context) {
36         super(context);
37     }
38 
39     @Override
onPrepareShow(Bundle args, int showFlags)40     public void onPrepareShow(Bundle args, int showFlags) {
41         super.onPrepareShow(args, showFlags);
42         setUiEnabled(false);
43     }
44 
45     @Override
onShow(String action, Bundle args, int showFlags)46     protected void onShow(String action, Bundle args, int showFlags) {
47         Log.i(TAG, "onShow(action: " + action + ", args: " + LogUtils.parcelableToString(args)
48                 + ", flags: " + LogUtils.flagsToString(showFlags) + ")");
49         closeSystemDialogs();
50         Intent intent = new Intent(getContext(), VoicePlateActivity.class);
51         intent.putExtra(VoicePlateActivity.EXTRA_ACTION, action);
52         intent.putExtra(VoicePlateActivity.EXTRA_ARGS, args);
53         startAssistantActivity(intent);
54     }
55 }
56