blob: b2eadec3dcae301b5629dc746b6f7643b88f8bff [file] [log] [blame]
// Copyright (c) 2012 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.
//
// Header for SVOX Pico TTS engine implementation.
#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_PICO_PICO_TTS_ENGINE_H_
#define SPEECH_CLIENT_SYNTHESIS_SERVICE_PICO_PICO_TTS_ENGINE_H_
#include <map>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "pico/picoapi.h"
#include "pico/picodbg.h"
#include "pico/picodefs.h"
#include "tts_engine.h"
namespace speech_synthesis {
//TODO(chaitanyag): Add a comment about the units of these values once we hear
// back from the SVox.
// Speaking speed
const int PICO_MIN_RATE = 20;
const int PICO_MAX_RATE = 500;
const int PICO_DEF_RATE = 100;
// Speaking pitch
const int PICO_MIN_PITCH = 50;
const int PICO_MAX_PITCH = 200;
const int PICO_DEF_PITCH = 100;
// Speaking volume
const int PICO_MIN_VOL = 0;
const int PICO_MAX_VOL = 500;
const int PICO_DEF_VOL = 120;
struct PicoTtsVoice : public TtsVoice {
public:
std::string ta_lingware;
std::string sg_lingware;
std::string utpp_lingware;
};
// Thread-safe. Unfortunately Pico is not 64-bit clean.
class PicoTtsEngine : public TtsEngine {
public:
// A hack to prevent infinite loops.
static int max_iterations_without_apparent_progress;
explicit PicoTtsEngine(const std::string& base_path);
virtual ~PicoTtsEngine();
// TtsEngine overrides:
virtual tts_result Init() OVERRIDE;
virtual tts_result Shutdown() OVERRIDE;
virtual tts_result Stop() OVERRIDE;
virtual int GetVoiceCount() OVERRIDE;
virtual const TtsVoice* GetVoiceInfo(int voice_index) OVERRIDE;
virtual tts_result SetVoice(int voice_index) OVERRIDE;
virtual void SetReceiver(TtsDataReceiver* receiver) OVERRIDE;
virtual tts_result SetProperty(const char *property,
const char *value) OVERRIDE;
virtual tts_result SetRate(float rate) OVERRIDE;
virtual tts_result SetPitch(float pitch) OVERRIDE;
virtual tts_result SetVolume(float volume) OVERRIDE;
virtual tts_result GetProperty(const char *property,
const char **value) OVERRIDE;
virtual int GetSampleRate() OVERRIDE;
virtual tts_result SynthesizeText(const char *text,
int16_t* audio_buffer,
int audio_buffer_size,
int* out_total_samples) OVERRIDE;
private:
tts_result LoadVoices(const std::string& filename);
void CleanResources();
tts_result InitVoice(int voice_index);
tts_result GetAudioFromTts(int16_t* audio_buffer,
int audio_buffer_size,
int* out_total_samples);
tts_result SetProperty(const char *property, float value);
void AppendProperties(const char *text, std::string *synth_text);
std::string base_path_;
std::vector<PicoTtsVoice> voices_;
int current_voice_index_;
std::map<std::string, std::string> properties_;
void * mem_area_;
pico_System system_;
pico_Engine engine_;
pico_Resource ta_resource_;
pico_Resource sg_resource_;
TtsDataReceiver *receiver_;
DISALLOW_COPY_AND_ASSIGN(PicoTtsEngine);
};
} // namespace speech_synthesis
#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_PICO_PICO_TTS_ENGINE_H_