blob: 208dd64becb800ea2e9cf52964e82aa3aee76080 [file] [log] [blame]
// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Defined an interface to be implemented for passing as a callback
// to receive synthesized audio data from the TTS engine.
#include <stdint.h>
#include <cstring>
#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_TTS_RECEIVER_H_
#define SPEECH_CLIENT_SYNTHESIS_SERVICE_TTS_RECEIVER_H_
namespace speech_synthesis {
enum tts_synth_status {
TTS_SYNTH_DONE = 0, // Only the LAST call to Receive() for a given
// synthesis should have status = TTS_SYNTH_DONE.
TTS_SYNTH_PENDING = 1
};
enum tts_callback_status {
TTS_CALLBACK_CONTINUE = 1, // The normal case: continue if there's more data.
TTS_CALLBACK_HALT = 0, // Stop synthesis. The engine should
// return TTS_SUCCESS from SynthesizeText().
TTS_CALLBACK_ERROR = 2 // Stop synthesis due to error. The engine should
// return TTS_FAILURE from SynthesizeText().
};
template <class DataElement>
class TtsGenericDataReceiver {
public:
virtual ~TtsGenericDataReceiver() {}
// Note that 'data' may be null if num_data_elements is zero;
// this is often used with status = TTS_SYNTH_DONE to signal
// the end of data.
// TODO(fergus): refactor this to remove the status parameter
// and instead use a separate Done() method.
virtual tts_callback_status Receive(int rate, int num_channels,
const DataElement* data, int num_data_elements,
tts_synth_status status) = 0;
};
// For raw audio (linear 16 bit encoding).
typedef TtsGenericDataReceiver<int16_t> TtsDataReceiver;
// For compressed audio (arbitrary encoding).
typedef TtsGenericDataReceiver<char> TtsEncodedDataReceiver;
}
#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_TTS_RECEIVER_H_