• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 
17 package com.android.inputmethod.leanback.voice;
18 
19 /**
20  * Keeps track of the speech level as last observed by the recognition
21  * engine as microphone data flows through it. Can be polled by the UI to
22  * animate its views.
23  */
24 public class SpeechLevelSource {
25     private volatile int mSpeechLevel;
26 
setSpeechLevel(int speechLevel)27     public void setSpeechLevel(int speechLevel) {
28         if (speechLevel < 0 || speechLevel > 100) {
29             throw new IllegalArgumentException();
30         }
31         mSpeechLevel = speechLevel;
32     }
33 
getSpeechLevel()34     public int getSpeechLevel() {
35         return mSpeechLevel;
36     }
37 
reset()38     public void reset() {
39         mSpeechLevel = -1;
40     }
41 
isValid()42     public boolean isValid() {
43         return mSpeechLevel > 0;
44     }
45 }
46 
47