Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1bb004c authored by Brandon Ballinger's avatar Brandon Ballinger Committed by The Android Open Source Project
Browse files

AI 146615: am: CL 146613 Move Recognition service declarations to...

AI 146615: am: CL 146613 Move Recognition service declarations to frameworks/base/core/java/android/speech. Hide them from public API by default (no changes to current.xml).
  Original author: brandonb

Automated import of CL 146615
parent 9c3209db
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -99,6 +99,8 @@ LOCAL_SRC_FILES += \
	core/java/android/view/IWindow.aidl \
	core/java/android/view/IWindowManager.aidl \
	core/java/android/view/IWindowSession.aidl \
	core/java/android/speech/IRecognitionListener.aidl \
	core/java/android/speech/IRecognitionService.aidl \
	core/java/com/android/internal/app/IBatteryStats.aidl \
	core/java/com/android/internal/app/IUsageStats.aidl \
	core/java/com/android/internal/appwidget/IAppWidgetService.aidl \
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.speech;

import android.os.Bundle;

/**
 * Listener for speech recognition events, used with RecognitionService.
 *  This gives you both the final recognition results, as well as various
 *  intermediate events that can be used to show visual feedback to the user.
 *  {@hide}
 */
interface IRecognitionListener {
    /** Called when the endpointer is ready for the user to start speaking. */
    void onReadyForSpeech(in Bundle noiseParams);

    /** The user has started to speak. */
    void onBeginningOfSpeech();

    /** The sound level in the audio stream has changed. */
    void onRmsChanged(in float rmsdB);

    /**
     * More sound has been received. Buffer is a byte buffer containing
     * a sequence of 16-bit shorts. 
     */
    void onBufferReceived(in byte[] buffer);

    /** Called after the user stops speaking. */
    void onEndOfSpeech();

    /** A network or recognition error occurred. */
    void onError(in String error);

    /** 
     * Called when recognition transcripts are ready.
     * results: an ordered list of the most likely transcripts (N-best list).
     * @hide
     */
    void onResults(in List<String> results);
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.speech;

import android.os.Bundle;
import android.speech.IRecognitionListener;

// A Service interface to speech recognition. Call startListening when
// you want to begin capturing audio; RecognitionService will automatically
// determine when the user has finished speaking, stream the audio to the
// recognition servers, and notify you when results are ready.
/** {@hide} */
interface IRecognitionService {
    // Start listening for speech. Can only call this from one thread at once.
    void startListening(in Bundle recognitionParams,
        in IRecognitionListener listener);

    void cancel();
}
+93 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package android.speech;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;

import java.util.List;

/**
 * Utils for Google's network-based speech recognizer, which lets you perform
 * speech-to-text translation through RecognitionService. IRecognitionService
 * and IRecognitionListener are the core interfaces; you begin recognition
 * through IRecognitionService and subscribe to callbacks about when the user
 * stopped speaking, results come in, errors, etc. through IRecognitionListener.
 * RecognitionServiceUtil includes default IRecognitionListener and
 * ServiceConnection implementations to reduce the amount of boilerplate.
 *
 * The Service provides no user interface. See RecognitionActivity if you
 * want the standard voice search UI.
 *
 * Below is a small skeleton of how to use the recognizer:
 *
 * ServiceConnection conn = new RecognitionServiceUtil.Connection();
 * mContext.bindService(RecognitionServiceUtil.sDefaultIntent,
 *     conn, Context.BIND_AUTO_CREATE);
 * IRecognitionListener listener = new RecognitionServiceWrapper.NullListener() {
 *         public void onResults(List<String> results) {
 *             // Do something with recognition transcripts
 *         }
 *     }
 *
 * // Must wait for conn.mService to be populated, then call below
 * conn.mService.startListening(null, listener);
 *
 * {@hide}
 */
public class RecognitionServiceUtil {
    public static final Intent sDefaultIntent = new Intent(
            RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

    public static final String NOISE_LEVEL = "NoiseLevel";
    public static final String SIGNAL_NOISE_RATIO = "SignalNoiseRatio";

    private RecognitionServiceUtil() {}

    /**
     * IRecognitionListener which does nothing in response to recognition
     * callbacks. You can subclass from this and override only the methods
     * whose events you want to respond to.
     */
    public static class NullListener extends IRecognitionListener.Stub {
        public void onReadyForSpeech(Bundle bundle) {}
        public void onBeginningOfSpeech() {}
        public void onRmsChanged(float rmsdB) {}
        public void onBufferReceived(byte[] buf) {}
        public void onEndOfSpeech() {}
        public void onError(String error) {}
        public void onResults(List<String> results) {}
    }

    /**
     * Basic ServiceConnection which just records mService variable.
     */
    public static class Connection implements ServiceConnection {
        public IRecognitionService mService;

        public synchronized void onServiceConnected(ComponentName name, IBinder service) {
            mService = IRecognitionService.Stub.asInterface(service);
        }

        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }
    }
}