12c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi/*
250e657bb2d005568f5dd8bc1d904d07b0d94018fBjorn Bringert * Copyright (C) 2011 The Android Open Source Project
32c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi *
42c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License");
52c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi * you may not use this file except in compliance with the License.
62c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi * You may obtain a copy of the License at
72c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi *
82c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi *      http://www.apache.org/licenses/LICENSE-2.0
92c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi *
102c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi * Unless required by applicable law or agreed to in writing, software
112c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS,
122c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi * See the License for the specific language governing permissions and
142c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi * limitations under the License.
152c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi */
16f85aa5a4d4e6f1ef7e07638568e27d709b8085c6Charles Chenpackage android.speech.tts;
172c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi
182c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi/**
1950e657bb2d005568f5dd8bc1d904d07b0d94018fBjorn Bringert * Interface for callbacks from TextToSpeechService
202c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi *
212c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi * {@hide}
222c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi */
2350e657bb2d005568f5dd8bc1d904d07b0d94018fBjorn Bringertoneway interface ITextToSpeechCallback {
2490d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak    /**
25c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * Tells the client that the synthesis has started playing.
2690d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     *
27c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param utteranceId Unique id identifying the synthesis request.
2890d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     */
29754c72ed9e8e83e5a913aa7552fc2e1b1b5277e0Narayan Kamath    void onStart(String utteranceId);
3090d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak
3190d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak    /**
32c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * Tells the client that the synthesis has finished playing.
3390d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     *
34c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param utteranceId Unique id identifying the synthesis request.
3590d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     */
3690d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak    void onSuccess(String utteranceId);
3790d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak
3890d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak    /**
3990d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     * Tells the client that the synthesis was stopped.
4090d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     *
41c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param utteranceId Unique id identifying the synthesis request.
4290d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     */
434b73867a12a9339c7788e8949aac4a32d2eee22bPrzemyslaw Szczepaniak    void onStop(String utteranceId, boolean isStarted);
4490d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak
4590d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak    /**
4690d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     * Tells the client that the synthesis has failed.
4790d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     *
48c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param utteranceId Unique id identifying the synthesis request.
4990d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     * @param errorCode One of the values from
50fc4b2890378eb1b6e0b11d60d703eb6854268064Przemyslaw Szczepaniak     *        {@link android.speech.tts.v2.TextToSpeech}.
5190d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak     */
5290d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak    void onError(String utteranceId, int errorCode);
5390d15d2371ad85f22254be6985455aa2baa5d15dPrzemyslaw Szczepaniak
54c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts    /**
55c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * Tells the client that the TTS engine has started synthesizing the audio for a request.
56c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     *
57c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * <p>
58c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * This doesn't mean the synthesis request has already started playing (for example when there
59c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * are synthesis requests ahead of it in the queue), but after receiving this callback you can
60c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * expect onAudioAvailable to be called.
61c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * </p>
62c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     *
63c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param utteranceId Unique id identifying the synthesis request.
64c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param sampleRateInHz Sample rate in HZ of the generated audio.
65c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param audioFormat The audio format of the generated audio in the {@link #onAudioAvailable}
66c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     *        call. Should be one of {@link android.media.AudioFormat.ENCODING_PCM_8BIT},
67c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     *        {@link android.media.AudioFormat.ENCODING_PCM_16BIT} or
68c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     *        {@link android.media.AudioFormat.ENCODING_PCM_FLOAT}.
69c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param channelCount The number of channels.
70c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     */
71c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts    void onBeginSynthesis(String utteranceId, int sampleRateInHz, int audioFormat, int channelCount);
72c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts
73c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts    /**
74c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * Tells the client about a chunk of the synthesized audio.
75c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     *
76c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * <p>
77c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * Called when a chunk of the synthesized audio is ready. This may be called more than once for
78c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * every synthesis request, thereby streaming the audio to the client.
79c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * </p>
80c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     *
81c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param utteranceId Unique id identifying the synthesis request.
82c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * @param audio The raw audio bytes. Its format is specified by the {@link #onStartAudio}
83c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     * callback.
84c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts     */
85c99ba1c3edf725e070383b27724c9ed63e1e5765Niels Egberts    void onAudioAvailable(String utteranceId, in byte[] audio);
862c0c2af2ea518cd754318cdbe0ee93997a26c4ccJean-Michel Trivi}
87