Remove Pico-based speech synthesis service.
This capability is now being provided by a component extension.
BUG=chromium-os:36744
TEST=none
CQ-DEPEND=38858
Change-Id: I3e48f9542f97942a6b8b78e9c31ef28e59dddf52
Reviewed-on: https://gerrit.chromium.org/gerrit/38856
Commit-Ready: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
Tested-by: Dominic Mazzoni <dmazzoni@chromium.org>
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index d251496..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 6c6730b..0000000
--- a/Makefile
+++ /dev/null
@@ -1,53 +0,0 @@
-# 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.
-
-CXX ?= g++
-BASE_VER ?= 125070
-PKG_CONFIG ?= pkg-config
-
-PC_DEPS = alsa dbus-1 dbus-glib-1 gobject-2.0 \
- libchrome-$(BASE_VER) libchromeos-$(BASE_VER)
-PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS))
-PC_LIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS))
-
-CXXFLAGS += -Wall -Werror
-CPPFLAGS += -I. $(PC_CFLAGS)
-LDLIBS = -lpico -lresample
-LDLIBS += $(PC_LIBS)
-
-DBUS_SOURCE=speech_synthesizer.xml
-DBUS_SERVER=bindings/server.h
-BINDINGS_DIR=bindings
-
-CC_SRCS = linux/audio_output_alsa.cc linux/threading.cc \
-pico/pico_tts_engine.cc pico/load_pico_voices_static.cc resampler.cc \
-tts_engine.cc tts_service.cc speech_synthesizer_main.cc \
-speech_synthesizer_service.cc interface.cc
-HEADERS = audio_output.h pico/pico_tts_engine.h resampler.h ringbuffer.h \
-threading.h tts_engine.h tts_receiver.h tts_service.h log.h \
-speech_synthesizer_service.h interface.h
-
-all: speech_synthesizer
-
-clean:
- rm -rf libttspico.so objs/
-
-dirs:
- mkdir -p objs/pico objs/linux
-
-CC_OBJS = $(CC_SRCS:%.cc=objs/%.o)
-OBJS = $(CC_OBJS)
-
-$(CC_OBJS): objs/%.o: %.cc $(HEADERS) $(DBUS_SERVER) | dirs
- $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
-
-speech_synthesizer: $(OBJS)
- $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
-
-$(BINDINGS_DIR):
- mkdir -p $(BINDINGS_DIR)
-
-$(DBUS_SERVER): $(DBUS_SOURCE) | $(BINDINGS_DIR)
- dbus-binding-tool --mode=glib-server \
- --prefix=`basename $(DBUS_SOURCE) .xml` $(DBUS_SOURCE) > $(DBUS_SERVER)
diff --git a/OWNERS b/OWNERS
deleted file mode 100644
index 6143f98..0000000
--- a/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-dmazzoni@chromium.org
-hashimoto@chromium.org
diff --git a/README b/README
deleted file mode 100644
index 6f4e81b..0000000
--- a/README
+++ /dev/null
@@ -1,7 +0,0 @@
-<Summary>
-This directory contains code to implement a text-to-speech (TTS) service on
-client platforms including Android and Chrome. This includes wrappers for
-various TTS engines and code to manage background processes/threads to
-process incoming text buffers and spool generated audio samples to the
-audio I/O api. See http://wiki/Main/SpeechLibDesignDoc
-</Summary>
diff --git a/SpeechSynthesizer.conf b/SpeechSynthesizer.conf
deleted file mode 100644
index 645b340..0000000
--- a/SpeechSynthesizer.conf
+++ /dev/null
@@ -1,36 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<!--
- 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.
--->
-<busconfig>
- <policy user="chronos">
- <!-- introspection is denied -->
- <deny send_destination="org.chromium.SpeechSynthesizer"
- send_interface="org.freedesktop.DBus.Introspectable" />
- <!-- properties denied -->
- <deny send_destination="org.chromium.SpeechSynthesizer"
- send_interface="org.freedesktop.DBus.Properties" />
- <!-- own this dbus service -->
- <allow own="org.chromium.SpeechSynthesizer" />
- <allow send_destination="org.chromium.SpeechSynthesizer" />
- <!-- allow explicit methods -->
- <allow send_destination="org.chromium.SpeechSynthesizer"
- send_interface="org.chromium.SpeechSynthesizerInterface"
- send_member="Speak"/>
- <allow send_destination="org.chromium.SpeechSynthesizer"
- send_interface="org.chromium.SpeechSynthesizerInterface"
- send_member="Stop"/>
- <allow send_destination="org.chromium.SpeechSynthesizer"
- send_interface="org.chromium.SpeechSynthesizerInterface"
- send_member="IsSpeaking"/>
- <allow send_destination="org.chromium.SpeechSynthesizer"
- send_interface="org.chromium.SpeechSynthesizerInterface"
- send_member="Shutdown"/>
- </policy>
- <policy context="default">
- <deny send_destination="org.chromium.SpeechSynthesizer" />
- </policy>
-</busconfig>
diff --git a/audio_output.h b/audio_output.h
deleted file mode 100644
index e793fae..0000000
--- a/audio_output.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// 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.
-//
-// An interface representing a real-time audio output system on a particular
-// platform.
-
-#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_AUDIO_OUTPUT_H_
-#define SPEECH_CLIENT_SYNTHESIS_SERVICE_AUDIO_OUTPUT_H_
-
-#include <stdlib.h>
-
-namespace speech_synthesis {
-
-// This is an interface defining the method that fills an audio buffer
-// for real-time audio output. Typically the TtsService implements this
-// method for AudioOutput, so that the service has all of the logic for
-// computing the samples to be computed, but AudioOutput has all of the logic
-// for dealing with the platform-specific audio hardware abstraction.
-class AudioProvider {
- public:
- virtual ~AudioProvider() { }
-
- // This method must return quickly and not block. It must always
- // fill all of the samples, with silence padding as needed.
- // Returns false if audio should completely stop.
- virtual bool FillAudioBuffer(int16_t* samples, int size) = 0;
-};
-
-// This is the abstract definition of a class that does real-time audio
-// output. You must provide an implementation of an AudioProvider that
-// provides the actual samples to output on demand (or silence, if there
-// are not enough samples available immediately). Subclasses of AudioOutput
-// implement these methods using various platform-specific methods.
-class AudioOutput {
- protected:
- AudioOutput() { }
-
- public:
- // Static factory method, creates whatever AudioOutput subclass
- // has been linked in.
- static AudioOutput* Create();
-
- virtual ~AudioOutput() {}
-
- // Initialize audio output, getting audio samples from the given provider.
- // Returns true on success. Safe to call more than once.
- virtual bool Init(AudioProvider *provider) = 0;
-
- virtual void StartAudio() = 0;
-
- virtual void StopAudio() = 0;
-
- virtual int GetSampleRate() = 0;
-
- virtual int GetChannelCount() = 0;
-
- // The typical number of samples that will be requested at once.
- // The TTS system may want to generate audio in increments of this
- // many samples, but it's just a hint.
- virtual int GetChunkSize() = 0;
-
- // The number of samples needed to completely fill the audio buffers.
- // The provider must be able to quickly produce at least this many
- // samples in order to avoid underflow.
- virtual int GetTotalBufferSize() = 0;
-};
-
-} // namespace speech_synthesis
-
-#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_AUDIO_OUTPUT_H_
diff --git a/inherit-review-settings-ok b/inherit-review-settings-ok
deleted file mode 100644
index e69de29..0000000
--- a/inherit-review-settings-ok
+++ /dev/null
diff --git a/interface.cc b/interface.cc
deleted file mode 100644
index a0b4c81..0000000
--- a/interface.cc
+++ /dev/null
@@ -1,80 +0,0 @@
-// 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.
-
-#include "interface.h"
-
-namespace speech_synthesis {
-namespace gobject {
-
-// Register with the glib type system.
-// This macro automatically defines a number of functions and variables
-// which are required to make speech_synthesizer functional as a GObject:
-// - speech_synthesizer_parent_class
-// - speech_synthesizer_get_type()
-// - dbus_glib_speech_synthesizer_object_info
-// It also ensures that the structs are setup so that the initialization
-// functions are called in the appropriate way by g_object_new().
-G_DEFINE_TYPE(SpeechSynthesizer, speech_synthesizer, G_TYPE_OBJECT);
-
-GObject* speech_synthesizer_constructor(GType gtype,
- guint n_properties,
- GObjectConstructParam *properties) {
- GObject* obj;
- GObjectClass* parent_class;
- // Instantiate using the parent class, then extend for local properties.
- parent_class = G_OBJECT_CLASS(speech_synthesizer_parent_class);
- obj = parent_class->constructor(gtype, n_properties, properties);
-
- SpeechSynthesizer* speech_synthesizer = reinterpret_cast<SpeechSynthesizer*>(obj);
- speech_synthesizer->service = NULL;
-
- // We don't have any thing we care to expose to the glib class system.
- return obj;
-}
-
-void speech_synthesizer_class_init(SpeechSynthesizerClass *real_class) {
- // Called once to configure the "class" structure.
- GObjectClass* gobject_class = G_OBJECT_CLASS(real_class);
- gobject_class->constructor = speech_synthesizer_constructor;
-}
-
-void speech_synthesizer_init(SpeechSynthesizer *self) { }
-
-// TODO(wad) add error messaging
-#define SPEECH_SYNTHESIZER_WRAP_METHOD(_NAME, s, e, args...) \
- if (!s->service) { \
- return FALSE; \
- } \
- return s->service->_NAME(args, e);
-
-#define SPEECH_SYNTHESIZER_WRAP_METHOD0(_NAME, s, e) \
- if (!s->service) { \
- return FALSE; \
- } \
- return s->service->_NAME(e);
-
-gboolean speech_synthesizer_speak(SpeechSynthesizer* self,
- gchar *text,
- gchar *properties,
- GError** error) {
- SPEECH_SYNTHESIZER_WRAP_METHOD(Speak, self, error, text, properties);
-}
-gboolean speech_synthesizer_stop(SpeechSynthesizer* self,
- GError** error) {
- SPEECH_SYNTHESIZER_WRAP_METHOD0(Stop, self, error);
-}
-gboolean speech_synthesizer_is_speaking(SpeechSynthesizer* self,
- gboolean* OUT_isSpeaking_requested,
- GError** error) {
- SPEECH_SYNTHESIZER_WRAP_METHOD(IsSpeaking, self, error,
- OUT_isSpeaking_requested);
-}
-gboolean speech_synthesizer_shutdown(SpeechSynthesizer* self,
- GError** error) {
- SPEECH_SYNTHESIZER_WRAP_METHOD0(Shutdown, self, error);
-}
-#undef SPEECH_SYNTHESIZER_WRAP_METHOD
-
-} // namespace gobject
-} // namespace speech_synthesis
diff --git a/interface.h b/interface.h
deleted file mode 100644
index acedc91..0000000
--- a/interface.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// 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.
-#ifndef SPEECH_SYNTHESIS_INTERFACE_H_
-#define SPEECH_SYNTHESIS_INTERFACE_H_
-
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-bindings.h>
-#include <glib-object.h>
-#include <stdlib.h>
-
-#include <base/logging.h>
-#include <chromeos/dbus/dbus.h>
-#include <chromeos/glib/object.h>
-
-#include "speech_synthesizer_service.h"
-
-// Helpers for using GObjects until we can get a C++ wrapper going.
-namespace speech_synthesis {
-namespace gobject { // Namespace hiding the GObject type data.
-
-struct SpeechSynthesizer {
- GObject parent_instance;
- SpeechSynthesizerService *service; // pointer to implementing service.
-};
-struct SpeechSynthesizerClass { GObjectClass parent_class; };
-
-// speech_synthesizer_get_type() is defined in interface.cc by the
-// G_DEFINE_TYPE() macro. This macro defines a number of other GLib
-// class system specific functions and variables discussed in
-// interface.cc.
-GType speech_synthesizer_get_type(); // defined by G_DEFINE_TYPE
-
-// Interface function prototypes which wrap service.
-gboolean speech_synthesizer_speak(SpeechSynthesizer *self,
- gchar *text,
- gchar *properties,
- GError **error);
-gboolean speech_synthesizer_stop(SpeechSynthesizer *self,
- GError **error);
-gboolean speech_synthesizer_is_speaking(SpeechSynthesizer *self,
- gboolean* OUT_isSpeaking_requested,
- GError **error);
-gboolean speech_synthesizer_shutdown(SpeechSynthesizer *self,
- GError **error);
-} // namespace gobject
-} // namespace speech_synthesis
-#endif // SPEECH_SYNTHESIS_INTERFACE_H_
diff --git a/linux/audio_output_alsa.cc b/linux/audio_output_alsa.cc
deleted file mode 100644
index d256361..0000000
--- a/linux/audio_output_alsa.cc
+++ /dev/null
@@ -1,231 +0,0 @@
-// 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.
-//
-// Implementation of audio output using the Linux ALSA interface.
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <vector>
-
-#include <alsa/asoundlib.h>
-
-#include "base/memory/scoped_ptr.h"
-
-#include "audio_output.h"
-#include "log.h"
-#include "threading.h"
-
-namespace speech_synthesis {
-
-namespace {
-
-const int kSampleRate = 44100;
-const int kChannelCount = 1;
-
-bool isDeviceReady() {
- snd_ctl_card_info_t *card_info;
- snd_ctl_card_info_alloca(&card_info);
-
- snd_pcm_info_t *pcm_info;
- snd_pcm_info_alloca(&pcm_info);
-
- int valid_playback_devices = 0;
- int card_index = -1;
-
- while(snd_card_next(&card_index) == 0 && card_index >= 0) {
- char card_name[20];
- snprintf(card_name, sizeof(card_name), "hw:%d", card_index);
- LOG(INFO) << "Checking ALSA sound card " << card_name;
-
- snd_ctl_t *ctl;
- if(snd_ctl_open(&ctl, card_name, 0) < 0)
- continue;
-
- snd_ctl_card_info(ctl, card_info);
-
- int dev_index = -1;
- while (snd_ctl_pcm_next_device(ctl, &dev_index) == 0 && dev_index >= 0) {
- char device_name[30];
- snprintf(device_name, sizeof(device_name),
- "hw:%d,%d", card_index, dev_index);
- LOG(INFO) << "Checking ALSA sound device " << device_name;
-
- /* Obtain info about this particular device */
- snd_pcm_info_set_device(pcm_info, dev_index);
- snd_pcm_info_set_subdevice(pcm_info, 0);
- snd_pcm_info_set_stream(pcm_info, SND_PCM_STREAM_PLAYBACK);
- if (snd_ctl_pcm_info(ctl, pcm_info) >= 0) {
- LOG(INFO) << " Valid playback device: " << device_name;
- valid_playback_devices++;
- }
- }
- snd_ctl_close(ctl);
- }
-
- LOG(INFO) << "Total valid playback devices: " << valid_playback_devices;
- if (valid_playback_devices == 0) {
- return false;
- }
- return true;
-}
-
-class LinuxAlsaAudioOutput : public AudioOutput, public Runnable {
- public:
- LinuxAlsaAudioOutput()
- : keep_running_(false),
- provider_(NULL),
- pcm_out_handle_(NULL),
- sample_rate_(0),
- channel_count_(0),
- chunk_size_(0),
- total_buffer_size_(0) {
- }
-
- virtual ~LinuxAlsaAudioOutput() {
- StopAudio();
- }
-
- // AudioOutput overrides:
- virtual bool Init(AudioProvider *provider) OVERRIDE {
- if (!provider) {
- LOG(ERROR) << "An AudioProvider is required.\n";
- return false;
- }
-
- if (provider_) {
- return true;
- }
-
- if (!isDeviceReady()) {
- return false;
- }
-
- int err = 0;
- if ((err = snd_pcm_open(&pcm_out_handle_,
- "default",
- SND_PCM_STREAM_PLAYBACK,
- 0)) < 0) {
- LOG(INFO) << "Can't open wave output: " << snd_strerror(err) << "\n";
- return false;
- }
-
- sample_rate_ = kSampleRate;
- channel_count_ = kChannelCount;
- int soft_resample = 1;
- unsigned int latency_us = 50000;
- if ((err = snd_pcm_set_params(pcm_out_handle_,
- SND_PCM_FORMAT_S16_LE,
- SND_PCM_ACCESS_RW_INTERLEAVED,
- channel_count_,
- sample_rate_,
- soft_resample,
- latency_us)) < 0) {
- LOG(INFO) << "Can't set pcm parameters " << snd_strerror(err);
- return false;
- }
-
- snd_pcm_uframes_t buffer_size = 0;
- snd_pcm_uframes_t period_size = 0;
- if ((err = snd_pcm_get_params(pcm_out_handle_, &buffer_size, &period_size))
- < 0) {
- LOG(INFO) << "Can't get pcm parameters: " << snd_strerror(err);
- return false;
- }
-
- chunk_size_ = period_size;
- total_buffer_size_ = buffer_size;
-
- if ((err = snd_pcm_prepare(pcm_out_handle_)) < 0) {
- LOG(INFO) << "Can't prepare: " << snd_strerror(err) << "\n";
- return false;
- }
-
- keep_running_ = true;
- provider_ = provider;
- return true;
- }
-
- virtual void StartAudio() OVERRIDE {
- thread_.reset(Thread::StartJoinableThread(this));
- }
-
- virtual void StopAudio() OVERRIDE {
- keep_running_ = false;
- if (thread_.get()) {
- thread_->Join();
- thread_.reset();
- }
- if (pcm_out_handle_) {
- snd_pcm_close(pcm_out_handle_);
- pcm_out_handle_ = NULL;
- }
- }
-
- virtual int GetSampleRate() OVERRIDE {
- return kSampleRate;
- }
-
- virtual int GetChannelCount() OVERRIDE {
- return kChannelCount;
- }
-
- virtual int GetChunkSize() OVERRIDE {
- return chunk_size_;
- }
-
- virtual int GetTotalBufferSize() OVERRIDE {
- return total_buffer_size_;
- }
-
- // Runnable override.
- virtual void Run() OVERRIDE {
- const int chunk_size = GetChunkSize();
- std::vector<int16_t> chunk(chunk_size);
-
- if (!provider_) {
- LOG(ERROR) << "Error: audio output was never initialized.\n";
- return;
- }
-
- LOG(INFO) << "In audio thread\n";
- while (keep_running_) {
- if (!provider_->FillAudioBuffer(&chunk[0], chunk_size)) {
- LOG(INFO) << "Could not fill audio buffer\n";
- break;
- }
-
- int err = snd_pcm_writei(pcm_out_handle_,
- &chunk[0],
- static_cast<snd_pcm_uframes_t>(chunk_size));
- if (err < 0) {
- LOG(INFO) << "Write error: " << err << snd_strerror(err) << "\n";
- do {
- sleep(1);
- LOG(INFO) << "Attempting to recover audio";
- } while (keep_running_ &&
- 0 != snd_pcm_recover(pcm_out_handle_, err, 0));
- }
- }
- }
-
- private:
- volatile bool keep_running_;
- AudioProvider* provider_;
- scoped_ptr<Thread> thread_;
- snd_pcm_t *pcm_out_handle_;
- int sample_rate_;
- int channel_count_;
- int chunk_size_;
- int total_buffer_size_;
-
- DISALLOW_COPY_AND_ASSIGN(LinuxAlsaAudioOutput);
-};
-
-} // namespace
-
-AudioOutput* AudioOutput::Create() {
- return new LinuxAlsaAudioOutput();
-}
-
-} // namespace speech_synthesis
diff --git a/linux/threading.cc b/linux/threading.cc
deleted file mode 100644
index c517d23..0000000
--- a/linux/threading.cc
+++ /dev/null
@@ -1,138 +0,0 @@
-// 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.
-//
-// Implementation of threading classes using Linux pthreads.
-// Also works under Native Client.
-#include "threading.h"
-
-#include <pthread.h>
-#include <sys/time.h>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-
-#include "log.h"
-
-namespace speech_synthesis {
-
-namespace {
-
-// Implementation of a Mutex using pthreads
-class PthreadMutex : public Mutex {
- public:
- PthreadMutex() {
- pthread_mutex_init(&mutex_, NULL);
- }
-
- virtual ~PthreadMutex() {
- pthread_mutex_destroy(&mutex_);
- }
-
- // Mutex overrides:
- virtual void Lock() OVERRIDE {
- pthread_mutex_lock(&mutex_);
- }
-
- virtual void Unlock() OVERRIDE {
- pthread_mutex_unlock(&mutex_);
- }
-
- private:
- pthread_mutex_t mutex_;
- friend class PthreadCondVar;
-
- DISALLOW_COPY_AND_ASSIGN(PthreadMutex);
-};
-
-class PthreadCondVar : public CondVar {
- public:
- PthreadCondVar() {
- pthread_cond_init(&cond_var_, NULL);
- }
-
- virtual ~PthreadCondVar() {
- pthread_cond_destroy(&cond_var_);
- }
-
- // CondVar overrides:
- virtual void Wait(Mutex* mutex) OVERRIDE {
- pthread_cond_wait(&cond_var_, &(static_cast<PthreadMutex*>(mutex))->mutex_);
- }
-
- virtual void WaitWithTimeout(Mutex* mutex, int timeout_ms) OVERRIDE {
- struct timeval now;
- struct timespec timeout;
- int future_us;
-
- gettimeofday(&now, NULL);
- future_us = now.tv_usec + timeout_ms * 1000;
- timeout.tv_nsec = (future_us % 1000000) * 1000;
- timeout.tv_sec = now.tv_sec + future_us / 1000000;
-
- pthread_cond_timedwait(&cond_var_,
- &(static_cast<PthreadMutex*>(mutex))->mutex_,
- &timeout);
- }
-
- virtual void Signal() OVERRIDE {
- pthread_cond_signal(&cond_var_);
- }
-
- private:
- pthread_cond_t cond_var_;
-
- DISALLOW_COPY_AND_ASSIGN(PthreadCondVar);
-};
-
-// Implementation of a joinable Thread using Pthread's Thread class
-class PthreadThread : public Thread {
- public:
- explicit PthreadThread(pthread_t *thread)
- : thread_(thread) { }
-
- virtual ~PthreadThread() {
- CHECK(thread_ == NULL);
- }
-
- // Thread override.
- virtual void Join() OVERRIDE {
- pthread_join(*thread_, NULL);
- delete thread_;
- thread_ = NULL;
- }
-
- private:
- pthread_t* thread_;
-
- DISALLOW_COPY_AND_ASSIGN(PthreadThread);
-};
-
-void* ThreadStart(void *userdata) {
- Runnable *action = static_cast<Runnable *>(userdata);
- action->Run();
-
- return NULL;
-}
-
-} // namespace
-
-// static
-Mutex* Mutex::Create() {
- return new PthreadMutex();
-}
-
-// static
-CondVar* CondVar::Create() {
- return new PthreadCondVar();
-}
-
-// static
-Thread* Thread::StartJoinableThread(Runnable *action) {
- pthread_t* thread = new pthread_t;
- pthread_create(thread, NULL, ThreadStart, action);
-
- return new PthreadThread(thread);
-}
-
-} // namespace speech_synthesis
diff --git a/log.h b/log.h
deleted file mode 100644
index 4b98482..0000000
--- a/log.h
+++ /dev/null
@@ -1,11 +0,0 @@
-// 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.
-
-#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_LOG_H_
-#define SPEECH_CLIENT_SYNTHESIS_SERVICE_LOG_H_
-
-#include <base/logging.h>
-
-#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_LOG_H_
-
diff --git a/org.chromium.SpeechSynthesizer.service b/org.chromium.SpeechSynthesizer.service
deleted file mode 100644
index 9c83a3b..0000000
--- a/org.chromium.SpeechSynthesizer.service
+++ /dev/null
@@ -1,4 +0,0 @@
-[D-BUS Service]
-Name=org.chromium.SpeechSynthesizer
-Exec=/usr/sbin/speech_synthesizer
-User=chronos
diff --git a/pico/load_pico_voices_static.cc b/pico/load_pico_voices_static.cc
deleted file mode 100644
index 64a0b51..0000000
--- a/pico/load_pico_voices_static.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// 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.
-//
-// Load pico voices and language files using hardcoded paths.
-// TODO(chaitanyag): Change this to load voices from a file.
-
-#include "pico/pico_tts_engine.h"
-
-#include "base/string_number_conversions.h"
-
-namespace speech_synthesis {
-
-// Load the supported languages and properties from hardcoded paths.
-tts_result PicoTtsEngine::LoadVoices(const string& filename) {
- {
- voices_.push_back(PicoTtsVoice());
- PicoTtsVoice* voice = &voices_.back();
- voice->language = "eng";
- voice->region = "USA";
- voice->name = "en-US";
- voice->sample_rate = 16000;
- voice->ta_lingware = "en-US_ta.bin";
- voice->sg_lingware = "en-US_lh0_sg.bin";
- voice->utpp_lingware = "en-US_utpp.bin";
- voice->quality = TTS_NORMAL_QUALITY;
-
- voices_.push_back(PicoTtsVoice());
- voice = &voices_.back();
- voice->language = "eng";
- voice->region = "GBR";
- voice->name = "en-GB";
- voice->sample_rate = 16000;
- voice->ta_lingware = "en-GB_ta.bin";
- voice->sg_lingware = "en-GB_kh0_sg.bin";
- voice->utpp_lingware = "en-GB_utpp.bin";
- voice->quality = TTS_NORMAL_QUALITY;
-
- voices_.push_back(PicoTtsVoice());
- voice = &voices_.back();
- voice->language = "deu";
- voice->region = "DEU";
- voice->name = "de-DE";
- voice->sample_rate = 16000;
- voice->ta_lingware = "de-DE_ta.bin";
- voice->sg_lingware = "de-DE_gl0_sg.bin";
- voice->utpp_lingware = "de-DE_utpp.bin";
- voice->quality = TTS_NORMAL_QUALITY;
-
- voices_.push_back(PicoTtsVoice());
- voice = &voices_.back();
- voice->language = "spa";
- voice->region = "ESP";
- voice->name = "es-ES";
- voice->sample_rate = 16000;
- voice->ta_lingware = "es-ES_ta.bin";
- voice->sg_lingware = "es-ES_zl0_sg.bin";
- voice->utpp_lingware = "es-ES_utpp.bin";
- voice->quality = TTS_NORMAL_QUALITY;
-
- voices_.push_back(PicoTtsVoice());
- voice = &voices_.back();
- voice->language = "fra";
- voice->region = "FRA";
- voice->name = "fr-FR";
- voice->sample_rate = 16000;
- voice->ta_lingware = "fr-FR_ta.bin";
- voice->sg_lingware = "fr-FR_nk0_sg.bin";
- voice->utpp_lingware = "fr-FR_utpp.bin";
- voice->quality = TTS_NORMAL_QUALITY;
-
- voices_.push_back(PicoTtsVoice());
- voice = &voices_.back();
- voice->language = "ita";
- voice->region = "ITA";
- voice->name = "it-IT";
- voice->sample_rate = 16000;
- voice->ta_lingware = "it-IT_ta.bin";
- voice->sg_lingware = "it-IT_cm0_sg.bin";
- voice->utpp_lingware = "it-IT_utpp.bin";
- voice->quality = TTS_NORMAL_QUALITY;
-
- // Load properties
- properties_["rate"] = base::IntToString(PICO_DEF_RATE);
- properties_["pitch"] = base::IntToString(PICO_DEF_PITCH);
- properties_["volume"] = base::IntToString(PICO_DEF_VOL);
- }
-
- return TTS_SUCCESS;
-}
-
-} // namespace speech_synthesis
diff --git a/pico/pico_tts_engine.cc b/pico/pico_tts_engine.cc
deleted file mode 100644
index f5b7304..0000000
--- a/pico/pico_tts_engine.cc
+++ /dev/null
@@ -1,389 +0,0 @@
-// 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.
-//
-// Pico specific implementation of the TtsEngine interface defined in
-// tts_engine.h.
-
-#include "pico/pico_tts_engine.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-
-#include "base/string_number_conversions.h"
-
-#include "log.h"
-
-#define FAILERR(X) \
- if (PICO_OK != (X)) { \
- LOG(ERROR) << "Fail line " << __LINE__; \
- return TTS_FAILURE; \
- } \
- else
-
-using std::string;
-
-namespace speech_synthesis {
-
-const char* PROP_RATE = "rate";
-const char* PROP_PITCH = "pitch";
-const char* PROP_VOLUME = "volume";
-
-const int PICO_MEM_SIZE = 2500000;
-const pico_Char * PICO_VOICE_NAME =
- reinterpret_cast<const pico_Char *>("PicoVoice");
-
-PicoTtsEngine::PicoTtsEngine(const std::string& base_path)
- : base_path_(base_path),
- mem_area_(NULL),
- system_(NULL),
- engine_(NULL),
- ta_resource_(NULL),
- sg_resource_(NULL),
- receiver_(NULL) {
-}
-
-PicoTtsEngine::~PicoTtsEngine() {
- Shutdown();
-}
-
-// Unloads the Pico engine and any loaded Pico resources, but does not
-// shut down.
-void PicoTtsEngine::CleanResources(void) {
- if (engine_) {
- pico_disposeEngine(system_, &engine_);
- pico_releaseVoiceDefinition(system_, PICO_VOICE_NAME);
- engine_ = NULL;
- }
- if (ta_resource_) {
- pico_unloadResource(system_, &ta_resource_);
- ta_resource_ = NULL;
- }
- if (sg_resource_) {
- pico_unloadResource(system_, &sg_resource_);
- sg_resource_ = NULL;
- }
-
- current_voice_index_ = -1;
-}
-
-// Initializes the engine for the specified voice.
-tts_result PicoTtsEngine::InitVoice(int voice_index) {
- if (voice_index < 0 || voice_index >= GetVoiceCount()) {
- LOG(INFO) << "Voice index out of range: " << voice_index;
- return TTS_FAILURE;
- }
- const PicoTtsVoice * voice = &voices_[voice_index];
-
- pico_Char ta_resource_name[PICO_MAX_RESOURCE_NAME_SIZE];
- pico_Char sg_resource_name[PICO_MAX_RESOURCE_NAME_SIZE];
-
- string tafile = base_path_ + voice->ta_lingware;
- string sgfile = base_path_ + voice->sg_lingware;
- const pico_Char *ta_filename =
- reinterpret_cast<const pico_Char *>(tafile.c_str());
- const pico_Char *sg_filename =
- reinterpret_cast<const pico_Char *>(sgfile.c_str());
-
- FAILERR(pico_loadResource(system_, ta_filename, &ta_resource_));
- FAILERR(pico_loadResource(system_, sg_filename, &sg_resource_));
- FAILERR(pico_getResourceName(system_, ta_resource_,
- reinterpret_cast<char *>(ta_resource_name)));
- FAILERR(pico_getResourceName(system_, sg_resource_,
- reinterpret_cast<char *>(sg_resource_name)));
- FAILERR(pico_createVoiceDefinition(system_, PICO_VOICE_NAME));
- FAILERR(pico_addResourceToVoiceDefinition(
- system_, PICO_VOICE_NAME, ta_resource_name));
- FAILERR(pico_addResourceToVoiceDefinition(
- system_, PICO_VOICE_NAME, sg_resource_name));
- pico_newEngine(system_, PICO_VOICE_NAME, &engine_);
- current_voice_index_ = voice_index;
-
- return TTS_SUCCESS;
-}
-
-// Initialize TTS engine.
-tts_result PicoTtsEngine::Init() {
- LOG(INFO) << "Start.";
- LoadVoices(base_path_ + "tts_support.xml");
- mem_area_ = malloc(PICO_MEM_SIZE);
- if (!mem_area_) {
- LOG(ERROR) << "Failed to allocate memory for Pico system";
- return TTS_FAILURE;
- }
-
- FAILERR(pico_initialize(mem_area_, PICO_MEM_SIZE, &system_));
- // Set the first language in the data file as the default.
- FAILERR(InitVoice(0));
- LOG(INFO) << "Init done.";
- return TTS_SUCCESS;
-}
-
-// Shuts down the TTS engine, cleans up resources.
-tts_result PicoTtsEngine::Shutdown() {
- CleanResources();
- if (system_) {
- pico_terminate(&system_);
- system_ = NULL;
- }
- if (mem_area_) {
- free(mem_area_);
- mem_area_ = NULL;
- }
- return TTS_SUCCESS;
-}
-
-tts_result PicoTtsEngine::Stop() {
- // TODO(fergus): use PICO_RESET_SOFT here instead?
- pico_resetEngine(engine_, PICO_RESET_FULL);
- return TTS_SUCCESS;
-}
-
-int PicoTtsEngine::GetVoiceCount() {
- return static_cast<int>(voices_.size());
-}
-
-const TtsVoice* PicoTtsEngine::GetVoiceInfo(int voice_index) {
- if (voice_index >= 0 && voice_index < GetVoiceCount()) {
- return &voices_[voice_index];
- } else {
- return NULL;
- }
-}
-
-tts_result PicoTtsEngine::SetVoice(int voice_index) {
- if (current_voice_index_ != voice_index) {
- CleanResources();
- return InitVoice(voice_index);
- } else {
- return TTS_SUCCESS;
- }
-}
-
-void PicoTtsEngine::SetReceiver(TtsDataReceiver* receiver) {
- receiver_ = receiver;
-}
-
-// Sets the property for the engine.
-tts_result PicoTtsEngine::SetProperty(const char *property, const char *value) {
- if (properties_.count(property) > 0) {
- properties_[property] = value;
- return TTS_SUCCESS;
- } else {
- return TTS_PROPERTY_UNSUPPORTED;
- }
-}
-
-tts_result PicoTtsEngine::SetProperty(const char *property, float value) {
- SetProperty(property, base::IntToString(value).c_str());
- return TTS_SUCCESS;
-}
-
-tts_result PicoTtsEngine::SetRate(float rate) {
- if (rate < 0 || rate > 5) {
- return TTS_VALUE_INVALID;
- }
- rate = rate < 0.2 ? 0.2 : rate;
- return SetProperty(PROP_RATE, rate * 100);
-}
-
-tts_result PicoTtsEngine::SetPitch(float pitch) {
- if (pitch < 0 || pitch > 2) {
- return TTS_VALUE_INVALID;
- }
- pitch = pitch < 0.5 ? 0.5 : pitch;
- return SetProperty(PROP_PITCH, pitch * 100);
-}
-
-tts_result PicoTtsEngine::SetVolume(float volume) {
- if (volume < 0 || volume > 5) {
- return TTS_VALUE_INVALID;
- }
- return SetProperty(PROP_VOLUME, volume * 100);
-}
-
-tts_result PicoTtsEngine::GetProperty(const char *property,
- const char **value) {
- std::map<string, string>::const_iterator iter =
- properties_.find(property);
- if (iter != properties_.end()) {
- if (value != NULL) {
- (*value) = iter->second.c_str();
- }
- return TTS_SUCCESS;
- }
- return TTS_PROPERTY_UNSUPPORTED;
-}
-
-int PicoTtsEngine::GetSampleRate() {
- return voices_[current_voice_index_].sample_rate;
-}
-
-tts_result PicoTtsEngine::SynthesizeText(const char* text,
- int16_t* audio_buffer,
- int audio_buffer_size,
- int* out_total_samples) {
- if (out_total_samples != NULL) {
- *out_total_samples = 0;
- }
-
- string synth_text = "";
- AppendProperties(text, &synth_text);
-
- int text_pos = 0;
- const pico_Char* text_ptr =
- reinterpret_cast<const pico_Char*>(synth_text.c_str());
- int text_buffer_len = synth_text.size() + 1;
- while (text_pos < text_buffer_len) {
- pico_Int16 text_bytes_consumed = 0;
- if (PICO_OK != pico_putTextUtf8(
- engine_, text_ptr, text_buffer_len - text_pos,
- &text_bytes_consumed)) {
- return TTS_FAILURE;
- }
-
- int out_samples;
- tts_result result = GetAudioFromTts(
- audio_buffer, audio_buffer_size, &out_samples);
- if (out_total_samples != NULL) {
- *out_total_samples += out_samples;
- }
-
- if (result != TTS_SUCCESS) {
- return result;
- }
-
- text_pos += text_bytes_consumed;
- text_ptr += text_bytes_consumed;
- }
- return TTS_SUCCESS;
-}
-
-// This method appends the SSML tags for the supported properties if their
-// values are different from the default values.
-void PicoTtsEngine::AppendProperties(const char *text, string *synth_text) {
- int rate_level_ = floor(atof(properties_[PROP_RATE].c_str()));
- int pitch_level_ = floor(atof(properties_[PROP_PITCH].c_str()));
- int volume_level_ = floor(atof(properties_[PROP_VOLUME].c_str()));
-
- if (rate_level_ < PICO_MIN_RATE || rate_level_ > PICO_MAX_RATE) {
- LOG(WARNING) << "Rate is outside the allowed range.";
- }
- if (pitch_level_ < PICO_MIN_PITCH || pitch_level_ > PICO_MAX_PITCH) {
- LOG(WARNING) << "Pitch is outside the allowed range.";
- }
- if (volume_level_ < PICO_MIN_VOL || volume_level_ > PICO_MAX_VOL) {
- LOG(WARNING) << "Volume is outside the allowed range.";
- }
-
- *synth_text = "";
-
- // Append opening tags
- if (rate_level_ != PICO_DEF_RATE) {
- *synth_text += "<speed level='" + properties_[PROP_RATE] + "'>";
- }
- if (pitch_level_ != PICO_DEF_PITCH) {
- *synth_text += "<pitch level='" + properties_[PROP_PITCH] + "'>";
- }
- if (volume_level_ != PICO_DEF_VOL) {
- *synth_text += "<volume level='" + properties_[PROP_VOLUME] + "'>";
- }
- // Append text
- *synth_text += text;
- // Append closing tags in the reverse order
- if (volume_level_ != PICO_DEF_VOL) {
- *synth_text += "</volume>";
- }
- if (pitch_level_ != PICO_DEF_PITCH) {
- *synth_text += "</pitch>";
- }
- if (rate_level_ != PICO_DEF_RATE) {
- *synth_text += "</speed>";
- }
-}
-
-// max_iterations_without_apparent_progress is a hack to prevent infinite loops.
-// This needs to be more than 200 to pass simple tests such as hello world.
-// TODO(fergus): we should fix the underlying bug <http://b/2501315> in the
-// //third_party/pico sources, and then delete all the code relating to
-// max_iterations_without_apparent_progress.
-int PicoTtsEngine::max_iterations_without_apparent_progress = 10000;
-
-tts_result PicoTtsEngine::GetAudioFromTts(int16_t* audio_buffer,
- int audio_buffer_size,
- int* out_total_samples) {
- int total_samples_output = 0;
- int status;
- tts_callback_status callback_status = TTS_CALLBACK_CONTINUE;
- pico_Int16 data_type = PICO_DATA_PCM_16BIT;
- uint32_t sample_rate = voices_[current_voice_index_].sample_rate;
- int iterations_without_apparent_progress = 0;
- while (1) {
- pico_Int16 bytes_received = 0;
- data_type = 0;
- int8_t* buffer_ptr = reinterpret_cast<int8_t *>(audio_buffer);
- pico_Int16 buffer_size_bytes = audio_buffer_size * sizeof(pico_Int16);
-
- status = pico_getData(engine_, buffer_ptr, buffer_size_bytes,
- &bytes_received, &data_type);
-
- if (status != PICO_STEP_ERROR && bytes_received > 0) {
- if (data_type != PICO_DATA_PCM_16BIT) {
- break;
- }
-
- int samples_output = bytes_received / sizeof(const pico_Int16);
- total_samples_output += samples_output;
-
- // make the callback here...note that it's important to call this
- // method even if no data was received.
- if (receiver_) {
- callback_status =
- receiver_->Receive(sample_rate, 1, audio_buffer,
- samples_output, TTS_SYNTH_PENDING);
- if (callback_status != TTS_CALLBACK_CONTINUE) {
- break;
- }
- }
- }
- if (status != PICO_STEP_BUSY) {
- break;
- }
- if (bytes_received == 0) {
- iterations_without_apparent_progress++;
- if (iterations_without_apparent_progress >
- max_iterations_without_apparent_progress) {
- break;
- }
- } else {
- iterations_without_apparent_progress = 0;
- }
- };
-
- if (out_total_samples != NULL) {
- *out_total_samples = total_samples_output;
- }
-
- if (status == PICO_STEP_ERROR ||
- callback_status == TTS_CALLBACK_ERROR ||
- data_type != PICO_DATA_PCM_16BIT ||
- iterations_without_apparent_progress >
- max_iterations_without_apparent_progress) {
- return TTS_FAILURE;
- }
-
- if (callback_status != TTS_CALLBACK_HALT) {
- // Send a zero-length packet to tell the destination receiver that
- // we're done.
- callback_status = receiver_->Receive(sample_rate, 1, NULL, 0,
- TTS_SYNTH_DONE);
- if (callback_status == TTS_CALLBACK_ERROR) {
- return TTS_FAILURE;
- }
- }
-
- return TTS_SUCCESS;
-}
-
-} // namespace speech_synthesis
diff --git a/pico/pico_tts_engine.h b/pico/pico_tts_engine.h
deleted file mode 100644
index b2eadec..0000000
--- a/pico/pico_tts_engine.h
+++ /dev/null
@@ -1,109 +0,0 @@
-// 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_
diff --git a/resampler.cc b/resampler.cc
deleted file mode 100644
index 521c606..0000000
--- a/resampler.cc
+++ /dev/null
@@ -1,97 +0,0 @@
-// 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.
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "log.h"
-#include "resampler.h"
-#include "libresample/libresample.h"
-
-namespace speech_synthesis {
-
-Resampler::Resampler(TtsDataReceiver *destination,
- int source_rate,
- int dest_rate,
- int buffer_size)
- : destination_(destination),
- source_rate_(source_rate),
- dest_rate_(dest_rate),
- buffer_size_(buffer_size),
- resample_handle_(NULL),
- in_floats_(buffer_size),
- out_floats_(buffer_size),
- out_int16s_(buffer_size) {
- const int high_quality = 0;
- factor_ = dest_rate_ * 1.0 / source_rate_;
- resample_handle_ = resample_open(high_quality, factor_, factor_);
-}
-
-Resampler::~Resampler() {
- resample_close(resample_handle_);
-}
-
-tts_callback_status Resampler::Receive(int rate,
- int num_channels,
- const int16_t* data,
- int num_samples,
- tts_synth_status synth_status) {
- if (num_samples > buffer_size_) {
- LOG(ERROR) << "Got " << num_samples << " samples, buffer size is " <<
- buffer_size_ << "\n";
- exit(-1);
- }
-
- if (rate != source_rate_) {
- LOG(ERROR) << "Got input rate of " << rate << " expected " <<
- source_rate_ << "\n";
- exit(-1);
- }
-
- for (int i = 0; i < num_samples; i++) {
- in_floats_[i] = data[i];
- }
-
- int last_flag = (synth_status == TTS_SYNTH_DONE? 1 : 0);
-
- int input_index = 0;
- while (input_index < num_samples) {
- int in_buffer_used;
- int out_samples = resample_process(resample_handle_,
- factor_,
- &in_floats_[input_index],
- num_samples - input_index,
- last_flag,
- &in_buffer_used,
- &out_floats_[0],
- buffer_size_);
- input_index += in_buffer_used;
-
- for (int i = 0; i < out_samples; i++) {
- int value = static_cast<int>(out_floats_[i]);
- if (value > 32767)
- value = 32767;
- if (value < -32768)
- value = -32768;
- out_int16s_[i] = static_cast<int16_t>(value);
- }
-
- tts_synth_status status;
- if (synth_status == TTS_SYNTH_DONE && input_index == num_samples) {
- status = TTS_SYNTH_DONE;
- } else {
- status = TTS_SYNTH_PENDING;
- }
-
- tts_callback_status callback_status = destination_->Receive(
- dest_rate_, 1, &out_int16s_[0], out_samples, status);
- if (callback_status != TTS_CALLBACK_CONTINUE) {
- return callback_status;
- }
- }
-
- return TTS_CALLBACK_CONTINUE;
-}
-
-} // namespace speech_synthesis
diff --git a/resampler.h b/resampler.h
deleted file mode 100644
index ef6d17b..0000000
--- a/resampler.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// 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.
-//
-// Implementation of TtsDataReceiver that resamples the audio to a
-// different sample rate and then passes the resampled audio through
-// to another callback.
-
-#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_RESAMPLER_H_
-#define SPEECH_CLIENT_SYNTHESIS_SERVICE_RESAMPLER_H_
-
-#include <stdint.h>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-
-#include "tts_receiver.h"
-
-namespace speech_synthesis {
-
-class Resampler : public TtsDataReceiver {
- public:
- // Resamples the audio passed to this object's Receive method and passes
- // the resampled audio through to the destination.
- Resampler(TtsDataReceiver *destination,
- int source_rate,
- int dest_rate,
- int buffer_size);
-
- virtual ~Resampler();
-
- // TtsDataReceiver override.
- virtual tts_callback_status Receive(int rate,
- int num_channels,
- const int16_t* data,
- int num_samples,
- tts_synth_status status) OVERRIDE;
-
- int source_rate() { return source_rate_; }
-
- int dest_rate() { return dest_rate_; }
-
- private:
- TtsDataReceiver* destination_;
- int source_rate_;
- int dest_rate_;
- double factor_;
- int buffer_size_;
- void* resample_handle_;
- std::vector<float> in_floats_;
- std::vector<float> out_floats_;
- std::vector<int16_t> out_int16s_;
-
- DISALLOW_COPY_AND_ASSIGN(Resampler);
-};
-} // namespace speech_synthesis
-
-#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_RESAMPLER_H_
diff --git a/ringbuffer.h b/ringbuffer.h
deleted file mode 100644
index 9111060..0000000
--- a/ringbuffer.h
+++ /dev/null
@@ -1,220 +0,0 @@
-// 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.
-//
-// Templatized, thread-safe RingBuffer. Acts like a FIFO, but using a
-// fixed-size buffer that wraps around and optimized for operations that
-// read or write many elements at a time. Commonly used to buffer audio
-// samples that need to be passed from one thread to another.
-//
-// Supports a flag "finished" so the writing thread can notify the reading
-// thread that there's no more data.
-//
-// The implementation is all contained within this .h file because
-// it's templatized.
-
-#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_RINGBUFFER_H_
-#define SPEECH_CLIENT_SYNTHESIS_SERVICE_RINGBUFFER_H_
-
-#include "threading.h"
-
-namespace speech_synthesis {
-
-template<typename T> class RingBuffer {
- public:
- // Construct a RingBuffer using a given Threading object (used for
- // locking - may not be NULL) of a given capacity (cannot be increased
- // later).
- explicit RingBuffer(int capacity);
-
- // Destructor.
- ~RingBuffer();
-
- //
- // Methods for either thread
- //
-
- int GetCapacity() { return buffer_.size(); }
-
- //
- // Methods for the writer thread
- //
-
- // Reset to the initial state: the ring buffer is empty and marked as
- // unfinished.
- void Reset();
-
- // Get the number of items of type T that are available to be written.
- // This will be a number between 0 and capacity, inclusive.
- int WriteAvail();
-
- // Write *len* elements to the end of the ring buffer. Returns true on
- // success. If all *len* elements cannot be written without blocking,
- // returns false and writes nothing.
- bool Write(const T* data, int len);
-
- // Mark the buffer as finished. Future write operations will fail.
- // Read operations will succeed until the buffer is empty, but
- // IsFinished() will return true immediately.
- void MarkFinished();
-
- //
- // Methods for the reader thread
- //
-
- // Get the number of items of type T that are available to be read.
- // This will be a number between 0 and capacity, inclusive.
- int ReadAvail();
-
- // Read *len* elements from the front of the ring buffer. Returns true on
- // success. If all *len* elements cannot be read without blocking,
- // returns false and reads nothing.
- bool Read(T* data, int len);
-
- // Returns true if the buffer has been marked as finished by a call to
- // MarkFinished, whether the buffer is empty or not.
- bool IsFinished();
-
- private:
- scoped_ptr<Mutex> mutex_;
- std::vector<T> buffer_;
- bool finished_;
- volatile int read_pos_;
- volatile int write_pos_;
-
- DISALLOW_COPY_AND_ASSIGN(RingBuffer);
-};
-
-//
-// Implementation notes:
-//
-// We use a simple mutex to protect all of the fields.
-//
-// A special value of -1 is used for read_pos_ to indicate that the buffer
-// is empty, otherwise there would be no way to distinguish between an empty
-// buffer and a full buffer when read_pos_ == write_pos_.
-//
-
-template<typename T> RingBuffer<T>::RingBuffer(int capacity)
- : mutex_(Mutex::Create()),
- buffer_(capacity),
- finished_(false),
- read_pos_(0),
- write_pos_(0) {
- Reset();
-}
-
-template<typename T> RingBuffer<T>::~RingBuffer() {
-}
-
-template<typename T> void RingBuffer<T>::Reset() {
- mutex_->Lock();
- finished_ = false;
- read_pos_ = -1;
- write_pos_ = 0;
- mutex_->Unlock();
-};
-
-template<typename T> int RingBuffer<T>::WriteAvail() {
- int avail = GetCapacity();
- mutex_->Lock();
- if (read_pos_ != -1) {
- avail = read_pos_ - write_pos_;
- }
- mutex_->Unlock();
- if (avail < 0) {
- avail += GetCapacity();
- }
- return avail;
-}
-
-template<typename T> bool RingBuffer<T>::Write(const T* data, int len) {
- mutex_->Lock();
- if (finished_) {
- mutex_->Unlock();
- return false;
- }
- int avail = GetCapacity();
- if (read_pos_ != -1) {
- avail = read_pos_ - write_pos_;
- }
- if (avail < 0) {
- avail += GetCapacity();
- }
- if (len > avail) {
- mutex_->Unlock();
- return false;
- }
-
- if (read_pos_ == -1) {
- read_pos_ = write_pos_;
- }
- for (int i = 0; i < len; i++) {
- buffer_[write_pos_] = data[i];
- write_pos_ = (write_pos_ + 1) % GetCapacity();
- }
- mutex_->Unlock();
-
- return true;
-}
-
-template<typename T> void RingBuffer<T>::MarkFinished() {
- mutex_->Lock();
- finished_ = true;
- mutex_->Unlock();
-}
-
-template<typename T> int RingBuffer<T>::ReadAvail() {
- mutex_->Lock();
- if (read_pos_ == -1) {
- mutex_->Unlock();
- return 0;
- }
- int avail = write_pos_ - read_pos_;
- mutex_->Unlock();
- if (avail <= 0) {
- avail += GetCapacity();
- }
- return avail;
-}
-
-template<typename T> bool RingBuffer<T>::Read(T* data, int len) {
- mutex_->Lock();
- int avail;
- if (read_pos_ == -1) {
- avail = 0;
- } else {
- avail = write_pos_ - read_pos_;
- if (avail <= 0) {
- avail += GetCapacity();
- }
- }
- if (len > avail) {
- mutex_->Unlock();
- return false;
- }
-
- for (int i = 0; i < len; i++) {
- data[i] = buffer_[read_pos_];
- read_pos_ = (read_pos_ + 1) % GetCapacity();
- }
-
- if (read_pos_ == write_pos_) {
- read_pos_ = -1;
- }
-
- mutex_->Unlock();
-
- return true;
-}
-
-template<typename T> bool RingBuffer<T>::IsFinished() {
- mutex_->Lock();
- bool is_finished = finished_;
- mutex_->Unlock();
- return is_finished;
-}
-
-} // namespace speech_synthesis
-
-#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE
diff --git a/speech_synthesizer.xml b/speech_synthesizer.xml
deleted file mode 100644
index bc355df..0000000
--- a/speech_synthesizer.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- 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.
-
- dbus-binding-tool -mode=glib-server -prefix=speech_synthesis speech_synthesis.xml
- > bindings/server.h
--->
-<node name="/org/chromium/">
- <interface name="org.chromium.SpeechSynthesizerInterface">
- <annotation name="org.freedesktop.DBus.GLib.CSymbol"
- value="speech_synthesizer"/>
- <method name="Speak">
- <arg type="s" name="text" direction="in" />
- <arg type="s" name="properties" direction="in" />
- </method>
- <method name="Stop">
- </method>
- <method name="IsSpeaking">
- <arg type="b" name="done" direction="out" />
- </method>
- <method name="Shutdown">
- </method>
- </interface>
-</node>
diff --git a/speech_synthesizer_main.cc b/speech_synthesizer_main.cc
deleted file mode 100644
index a582c2d..0000000
--- a/speech_synthesizer_main.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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.
-
-#include <iostream>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <base/basictypes.h>
-#include <base/command_line.h>
-#include <chromeos/dbus/dbus.h>
-#include <chromeos/glib/object.h>
-#include <chromeos/syslog_logging.h>
-
-#include "base/logging.h"
-#include "speech_synthesizer_service.h"
-
-// Starts the speech synthesis DBus service.
-namespace speech_synthesis {
-
-static const char kLogFile[] = "log-file";
-
-} // namespace speech_synthesis
-
-int main(int argc, char* argv[]) {
- CommandLine::Init(argc, argv);
- CommandLine *cl = CommandLine::ForCurrentProcess();
- const std::string log_file =
- cl->GetSwitchValueASCII(speech_synthesis::kLogFile);
- if (log_file.empty()) {
- // Log goes to syslog unless --log-file option is provided
- chromeos::InitLog(chromeos::kLogToSyslog | chromeos::kLogToStderr);
- } else {
- logging::InitLogging(log_file.c_str(),
- logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
- logging::DONT_LOCK_LOG_FILE,
- logging::APPEND_TO_OLD_LOG_FILE,
- logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS
- );
- }
- LOG(INFO) << "Starting speech_synthesizer service.";
- ::g_type_init();
- speech_synthesis::SpeechSynthesizerService service;
- if (!service.Initialize()) {
- LOG(ERROR) << "Failed to initialize.";
- return -1;
- }
- if (!service.Register(chromeos::dbus::GetSystemBusConnection())) {
- LOG(ERROR) << "Failed to register";
- return -1;
- }
- if (!service.Run()) {
- LOG(ERROR) << "Failed to run";
- return -1;
- }
- LOG(INFO) << "Finished speech_synthesizer service.";
- return 0;
-}
diff --git a/speech_synthesizer_service.cc b/speech_synthesizer_service.cc
deleted file mode 100644
index e561024..0000000
--- a/speech_synthesizer_service.cc
+++ /dev/null
@@ -1,218 +0,0 @@
-// 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.
-
-#include <iostream>
-#include <base/basictypes.h>
-#include <base/command_line.h>
-#include <chromeos/dbus/dbus.h>
-#include <chromeos/dbus/service_constants.h>
-#include <chromeos/glib/object.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include "base/logging.h"
-#include "interface.h"
-
-// Forcibly namespace the dbus-bindings generated server bindings instead of
-// modifying the files afterward.
-namespace speech_synthesis { // NOLINT
-namespace gobject { // NOLINT
-#include "bindings/server.h"
-} // namespace gobject
-} // namespace speech_Synthesis
-
-namespace speech_synthesis {
-
-SpeechSynthesizerService::SpeechSynthesizerService()
- : speech_synthesizer_(NULL),
- main_loop_(g_main_loop_new(NULL, FALSE)) {
-}
-
-SpeechSynthesizerService::~SpeechSynthesizerService() {
- if (speech_synthesizer_)
- g_object_unref(speech_synthesizer_);
- g_main_loop_unref(main_loop_);
-}
-
-bool SpeechSynthesizerService::Initialize() {
- // Install the type-info for the service with dbus.
- dbus_g_object_type_install_info(
- gobject::speech_synthesizer_get_type(),
- &gobject::dbus_glib_speech_synthesizer_object_info);
- return Reset();
-}
-
-bool SpeechSynthesizerService::Reset() {
- if (speech_synthesizer_)
- g_object_unref(speech_synthesizer_);
- speech_synthesizer_ = reinterpret_cast<gobject::SpeechSynthesizer*>(
- g_object_new(gobject::speech_synthesizer_get_type(), NULL));
-
- // Allow references to this instance.
- speech_synthesizer_->service = this;
-
- if (main_loop_) {
- ::g_main_loop_unref(main_loop_);
- }
- main_loop_ = g_main_loop_new(NULL, false);
- if (!main_loop_) {
- LOG(ERROR) << "Failed to create main loop";
- return false;
- }
- return true;
-}
-
-// A utility function to send a signal to the browser.
-void SendSignal(const char* signal_name) {
- chromeos::dbus::Proxy proxy(chromeos::dbus::GetSystemBusConnection(),
- "/",
- chromium::kChromiumInterface);
- DBusMessage* signal = ::dbus_message_new_signal(
- "/",
- chromium::kChromiumInterface,
- signal_name);
- DCHECK(signal);
- ::dbus_g_proxy_send(proxy.gproxy(), signal, NULL);
- ::dbus_message_unref(signal);
-}
-
-bool SpeechSynthesizerService::Run() {
- if (!main_loop_) {
- LOG(ERROR) << "You must have a main loop to call Run.";
- return false;
- }
-
- LOG(INFO) << "Running speech_synthesizer main_loop.";
- scoped_ptr<AudioOutput> audio_output(AudioOutput::Create());
- scoped_ptr<TtsEngine> engine(new PicoTtsEngine("/usr/share/tts/pico/"));
- ttsService_.reset(new TtsService(engine.get(), audio_output.get()));
- utterance_options_.reset(new UtteranceOptions());
-
- // Polling for idle shutdown.
- const int kTimeoutInterval = 10000; // milliseconds
- UpdateLastCallTime();
- g_timeout_add(kTimeoutInterval, OnTimeout, this);
-
- if (ttsService_->StartService()) {
- SendSignal(chromium::kTTSReadySignal);
- g_main_loop_run(main_loop_);
- } else {
- SendSignal(chromium::kTTSFailedSignal);
- return false;
- }
- ttsService_->StopService();
- return true;
-}
-
-gboolean SpeechSynthesizerService::AddProperties(gchar *properties) {
- if (properties == NULL) {
- return false;
- }
- string props(properties);
- if (props.compare("") == 0) {
- return true;
- }
- string token = "";
- while(1) {
- unsigned int sep = props.find(";");
- if (sep == string::npos) {
- token = props;
- } else {
- token = props.substr(0, sep);
- props = props.substr(sep + 1);
- }
- if (token.empty() || token.compare("") == 0) {
- break;
- }
- int eq = token.find("=");
- string key = token.substr(0, eq);
- string value = token.substr(eq + 1);
-
- if (key.compare("rate") == 0) {
- utterance_options_->rate = atof(value.c_str());
- } else if (key.compare("pitch") == 0) {
- utterance_options_->pitch = atof(value.c_str());
- } else if (key.compare("volume") == 0) {
- utterance_options_->volume = atof(value.c_str());
- } else if (key.compare("name") == 0) {
- utterance_options_->voice_options.name = value;
- } else if (key.compare("language") == 0) {
- utterance_options_->voice_options.language = value;
- } else if (key.compare("sample_rate") == 0) {
- utterance_options_->voice_options.sample_rate = atoi(value.c_str());
- } else if (key.compare("quality") == 0) {
- utterance_options_->voice_options.quality =
- (tts_quality) atoi(value.c_str());
- } else if (key.compare("region") == 0) {
- utterance_options_->voice_options.region = value;
- } else if (key.compare("gender") == 0) {
- utterance_options_->voice_options.gender =
- (tts_gender) atoi(value.c_str());
- } else if (key.compare("age") == 0) {
- utterance_options_->voice_options.age = atoi(value.c_str());
- } else if (key.compare("enqueue") == 0) {
- utterance_options_->enqueue = atoi(value.c_str()) == 1;
- } else if (key.compare("interruptible") == 0) {
- utterance_options_->interruptible = atoi(value.c_str()) == 1;
- }
- if (sep == string::npos) {
- break;
- }
- }
- return true;
-}
-
-void SpeechSynthesizerService::UpdateLastCallTime() {
- time_last_call_ = base::Time::Now();
-}
-
-void SpeechSynthesizerService::ShutdownIfIdle() {
- const int kShutdownTimeout = 60000;
- const base::Time shutdown_time =
- time_last_call_ + base::TimeDelta::FromMilliseconds(kShutdownTimeout);
- if (base::Time::Now() >= shutdown_time &&
- ttsService_->GetStatus() == TTS_IDLE)
- g_main_loop_quit(main_loop());
-}
-
-// static
-gboolean SpeechSynthesizerService::OnTimeout(gpointer user_data) {
- static_cast<SpeechSynthesizerService*>(user_data)->ShutdownIfIdle();
- // TRUE means this method will be called again, repeatedly.
- return TRUE;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// SpeechSynthesizerService commands
-
-gboolean SpeechSynthesizerService::Speak(gchar *text,
- gchar *properties,
- GError **error) {
- UpdateLastCallTime();
- AddProperties(properties);
- ttsService_->Speak(text, *utterance_options_);
- utterance_options_->enqueue = false;
- utterance_options_->interruptible = true;
- return true;
-}
-
-gboolean SpeechSynthesizerService::Stop(GError **error) {
- UpdateLastCallTime();
- ttsService_->Stop();
- return true;
-}
-
-gboolean SpeechSynthesizerService::IsSpeaking(
- gboolean* OUT_isSpeaking_requested,
- GError **error) {
- UpdateLastCallTime();
- *OUT_isSpeaking_requested = (ttsService_->GetStatus() == TTS_BUSY);
- return true;
-}
-
-gboolean SpeechSynthesizerService::Shutdown(GError **error) {
- g_main_loop_quit(main_loop());
- return true;
-}
-
-} // namespace speech_synthesis
diff --git a/speech_synthesizer_service.h b/speech_synthesizer_service.h
deleted file mode 100644
index bec9f39..0000000
--- a/speech_synthesizer_service.h
+++ /dev/null
@@ -1,91 +0,0 @@
-// 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.
-
-#ifndef SPEECH_SYNTHESIS_SPEECH_SYNTHESIZER_SERVICE_H_
-#define SPEECH_SYNTHESIS_SPEECH_SYNTHESIZER_SERVICE_H_
-
-#include "base/memory/scoped_ptr.h"
-#include "base/time.h"
-
-#include <chromeos/dbus/abstract_dbus_service.h>
-#include <chromeos/dbus/dbus.h>
-#include <chromeos/dbus/service_constants.h>
-
-#include "pico/pico_tts_engine.h"
-#include "threading.h"
-#include "tts_engine.h"
-#include "tts_service.h"
-
-namespace speech_synthesis {
-namespace gobject {
-struct SpeechSynthesizer;
-} // namespace gobject
-
-// Provides a wrapper for exporting SpeechSynthesizerInterface to
-// D-Bus and entering the glib run loop.
-//
-// ::g_type_init() must be called before this class is used.
-class SpeechSynthesizerService : public chromeos::dbus::AbstractDbusService {
- public:
- SpeechSynthesizerService();
- virtual ~SpeechSynthesizerService();
-
- ////////////////////////////////////////////////////////////////////////////
- // Implementing chromeos::dbus::AbstractDbusService
- virtual bool Initialize() OVERRIDE;
- virtual bool Reset() OVERRIDE;
-
- virtual bool Run()OVERRIDE;
-
- virtual const char* service_name() const OVERRIDE {
- return kSpeechSynthesizerServiceName;
- }
- virtual const char* service_path() const OVERRIDE {
- return kSpeechSynthesizerServicePath;
- }
- virtual const char* service_interface() const OVERRIDE {
- return kSpeechSynthesizerInterface;
- }
- virtual GObject* service_object() const OVERRIDE{
- return G_OBJECT(speech_synthesizer_);
- }
-
- // Interface function prototypes which wrap service.
- gboolean Speak(gchar *text,
- gchar *properties,
- GError **error);
- gboolean Stop(GError **error);
- gboolean IsSpeaking(gboolean *OUT_isSpeaking_requested,
- GError **error);
- gboolean Shutdown(GError **error);
-
- protected:
- // AbstractDbusService override.
- virtual GMainLoop* main_loop() OVERRIDE { return main_loop_; }
-
- private:
- scoped_ptr<TtsService> ttsService_;
- scoped_ptr<AudioOutput> audio_output_;
- scoped_ptr<UtteranceOptions> utterance_options_;
-
- gobject::SpeechSynthesizer* speech_synthesizer_;
- GMainLoop* main_loop_;
-
- // The time when the last dbus method call was made.
- base::Time time_last_call_;
-
- gboolean AddProperties(gchar *properties);
-
- // Update |time_last_call_| to delay idle shutdown.
- void UpdateLastCallTime();
- // Shutdown the service if dbus method call has not been made for long time.
- void ShutdownIfIdle();
- // Handler method to be used by g_timeout_add.
- static gboolean OnTimeout(gpointer user_data);
-
- DISALLOW_COPY_AND_ASSIGN(SpeechSynthesizerService);
-};
-
-} // namespace speech_synthesis
-#endif // SPEECH_SYNTHESIS_SPEECH_SYNTHESIZER_SERVICE_H_
diff --git a/threading.h b/threading.h
deleted file mode 100644
index 67b6c3e..0000000
--- a/threading.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// 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.
-//
-// Abstract interfaces for threading classes that need to be implemented
-// for each platform.
-
-#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_THREADING_H_
-#define SPEECH_CLIENT_SYNTHESIS_SERVICE_THREADING_H_
-
-namespace speech_synthesis {
-
-// An interface for a runnable class.
-// TODO(chaitanyag): Implement this using chromeos's threading library from
-// third_party/chrome/base
-class Runnable {
- public:
- virtual ~Runnable() { }
-
- virtual void Run() = 0;
-};
-
-// A simple mutex. Only one thread can hold the lock at a time.
-class Mutex {
- public:
- virtual ~Mutex() { }
-
- virtual void Lock() = 0;
- virtual void Unlock() = 0;
-
- // Creates an instance of Mutex.
- static Mutex* Create();
-};
-
-// A condition variable, used so that Thread B can wait until Thread A has
-// signalled it to continue. Thread B locks a mutex and then checks to see
-// if the variable it's looking for is ready. If not, it calls Wait,
-// passing it the mutex. Meanwhile, when Thread A finishes the work it's
-// doing, it locks the mutex, updates the variable, and then calls
-// Signal, which instantly wakes up Thread B as soon as Thread A has
-// released its lock.
-class CondVar {
- public:
- virtual ~CondVar() { }
-
- // The mutex MUST be locked before calling this method, and unlocked after.
- virtual void Wait(Mutex* mutex) = 0;
-
- // The mutex MUST be locked before calling this method, and unlocked after.
- // Will exit after the specified number of milliseconds have passed,
- // regardless of the status of the condition variable.
- virtual void WaitWithTimeout(Mutex* mutex, int timeout_ms) = 0;
-
- // The mutex MUST be locked before calling this method, and unlocked after.
- virtual void Signal() = 0;
-
- // Creates an instance of CondVar.
- static CondVar* Create();
-};
-
-// A joinable thread.
-class Thread {
- public:
- virtual ~Thread() { }
-
- // Block until this thread has finished. Deletes this object upon return.
- virtual void Join() = 0;
-
- // Starts a thread and runs action->Run() on it.
- // Returns the started thread.
- static Thread* StartJoinableThread(Runnable *action);
-};
-
-} // namespace speech_synthesis
-
-#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_THREADING_H_
diff --git a/tts_engine.cc b/tts_engine.cc
deleted file mode 100644
index b0a8115..0000000
--- a/tts_engine.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-// 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.
-//
-// Implementation of cross-engine TtsEngine code.
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <map>
-#include <vector>
-
-#include "tts_engine.h"
-
-using std::map;
-using std::vector;
-
-namespace speech_synthesis {
-
-int TtsEngine::GetVoiceIndex(const TtsVoice& voice_options) {
- int count = GetVoiceCount();
- for (int i = 0; i < count; i++) {
- const TtsVoice* voice = GetVoiceInfo(i);
- if (TtsEngine::VoiceMatches(*voice, voice_options)) {
- return i;
- }
- }
- return -1;
-}
-
-bool TtsEngine::VoiceMatches(const TtsVoice& voice, const TtsVoice& pattern) {
- return (pattern.name.empty()
- || strcasecmp(voice.name.c_str(), pattern.name.c_str()) == 0)
- && (pattern.language.empty()
- || strcasecmp(voice.language.c_str(),
- pattern.language.c_str()) == 0)
- && (pattern.sample_rate == 0
- || voice.sample_rate == pattern.sample_rate)
- && (pattern.quality == TTS_UNSPECIFIED_QUALITY
- || voice.quality == pattern.quality)
- && (pattern.region.empty()
- || strcasecmp(voice.region.c_str(), pattern.region.c_str()) == 0)
- && (pattern.gender == TTS_UNSPECIFIED_GENDER
- || voice.gender == pattern.gender)
- && (pattern.age == 0
- || voice.age == pattern.age);
-}
-
-tts_result TtsEngine::SetVoiceByLanguage(const string& language_code) {
- int count = GetVoiceCount();
- for (int i = 0; i < count; i++) {
- if (0 == strcasecmp(GetVoiceInfo(i)->language.c_str(),
- language_code.c_str())) {
- return SetVoice(i);
- }
- }
- return TTS_FAILURE;
-}
-
-} // namespace speech_synthesis
diff --git a/tts_engine.h b/tts_engine.h
deleted file mode 100644
index 9eda415..0000000
--- a/tts_engine.h
+++ /dev/null
@@ -1,171 +0,0 @@
-// 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.
-//
-// This header defines the interface to access Text-To-Speech functionality
-// in shared libraries that implement speech synthesis and the management
-// of resources associated with the synthesis.
-// An example of the implementation of this interface can be found in
-// pico/tts_engine.cc
-
-#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_TTS_ENGINE_H_
-#define SPEECH_CLIENT_SYNTHESIS_SERVICE_TTS_ENGINE_H_
-
-#include <string>
-
-#include "tts_receiver.h"
-
-using std::string;
-
-namespace speech_synthesis {
-
-enum tts_result {
- TTS_SUCCESS = 0,
- TTS_FAILURE = -1,
- TTS_FEATURE_UNSUPPORTED = -2,
- TTS_VALUE_INVALID = -3,
- TTS_PROPERTY_UNSUPPORTED = -4,
- TTS_MISSING_RESOURCES = -5
-};
-
-enum tts_gender {
- TTS_UNSPECIFIED_GENDER = 0,
- TTS_MALE = 1,
- TTS_FEMALE = 2
-};
-
-enum tts_quality {
- TTS_UNSPECIFIED_QUALITY = 0,
- TTS_EXPERIMENTAL_QUALITY = 1,
- TTS_LOW_QUALITY = 2,
- TTS_NORMAL_QUALITY = 3,
- TTS_HIGH_QUALITY = 4
-};
-
-struct TtsVoice {
- public:
- // Required
- string name;
- string language;
- int sample_rate;
- tts_quality quality;
-
- // Optional
- string region;
- tts_gender gender;
- int age;
-
- TtsVoice()
- : name(),
- language(),
- sample_rate(0),
- quality(TTS_UNSPECIFIED_QUALITY),
- region(),
- gender(TTS_UNSPECIFIED_GENDER),
- age(0) {
- }
-};
-
-class TtsEngine {
- public:
- virtual ~TtsEngine() {}
-
- // Initialize the TTS engine and returns whether initialization succeeded.
- // @return TTS_SUCCESS, or TTS_FAILURE
- virtual tts_result Init() = 0;
-
- // Shut down the TTS engine and releases all associated resources.
- // @return TTS_SUCCESS, or TTS_FAILURE
- virtual tts_result Shutdown() = 0;
-
- // Interrupt synthesis and flushes any synthesized data that hasn't been
- // output yet. This will block until callbacks underway are completed.
- // @return TTS_SUCCESS, or TTS_FAILURE
- virtual tts_result Stop() = 0;
-
- // Return the number of loaded voices
- virtual int GetVoiceCount() = 0;
-
- // Return information about the ith voice
- virtual const TtsVoice* GetVoiceInfo(int voice_index) = 0;
-
- // Returns true iff the specified voice matches the pattern given in
- // voice_options. Default values in voice_options are treated as wildcards.
- static bool VoiceMatches(const TtsVoice& voice,
- const TtsVoice& voice_options);
-
- // Return the voice index for the first voice matching the specified
- // voice options, or -1 if there are no matching voices.
- int GetVoiceIndex(const TtsVoice& voice_options);
-
- // Switch to the voice with the given index.
- // @return TTS_SUCCESS or TTS_FAILURE
- virtual tts_result SetVoice(int voice_index) = 0;
-
- // Switch to the first voice in the given language code.
- // @return TTS_SUCCESS or TTS_FAILURE
- tts_result SetVoiceByLanguage(const string& language_code);
-
- // Switch to the first voice with matching properties.
- // @return TTS_SUCCESS or TTS_FAILURE
- tts_result SetVoiceByProperties(const TtsVoice& voice_options) {
- return SetVoice(GetVoiceIndex(voice_options));
- }
-
- // Set the object that will receive completed audio samples
- virtual void SetReceiver(TtsDataReceiver* receiver) = 0;
-
- // Set a property for the the TTS engine
- // @param property pointer to the property name
- // @param value pointer to the new property value, null-terminated utf-8
- // @return TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS, or
- // TTS_FAILURE, or TTS_VALUE_INVALID
- virtual tts_result SetProperty(const char *property, const char *value) = 0;
-
- // Set the speaking rate/speed.
- // @param rate the speaking rate in the range of 0 to 1. Default is 0.2
- // @return TTS_SUCCESS, or TTS_FAILURE, or TTS_VALUE_INVALID
- virtual tts_result SetRate(float rate) = 0;
-
- // Set the speaking pitch.
- // @param pitch the speaking pitch in the range of 0 to 1. Default is 0.5
- // @return TTS_SUCCESS, or TTS_FAILURE, or TTS_VALUE_INVALID
- virtual tts_result SetPitch(float pitch) = 0;
-
- // Set the speaking volume.
- // @param volume the speaking volume in the range of 0 to 1. Default is 0.2
- // @return TTS_SUCCESS, or TTS_FAILURE, or TTS_VALUE_INVALID
- virtual tts_result SetVolume(float volume) = 0;
-
- // Retrieve a property from the TTS engine
- // @param property pointer to the property name
- // @param[out] out_value will return a const pointer to the
- // retrieved value, or null if it doesn't exist
- // @return TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS
- virtual tts_result GetProperty(const char *property, const char **value) = 0;
-
- // Get the sample rate of the currently selected voice
- // @return the sample rate in Hz
- virtual int GetSampleRate() = 0;
-
- // Synthesize the text.
- // As the synthesis is performed, the engine invokes the callback to notify
- // the TTS framework that it has filled the given buffer, and indicates how
- // many bytes it wrote. The callback is called repeatedly until the engine
- // has generated all the audio data corresponding to the text.
- // Text is coded in UTF-8 and supports SSML.
- //
- // @param text null-terminated UTF-8 text to synthesize
- // @param audio_buffer buffer to write output audio samples
- // @param audio_sample_count number of samples in the audio buffer
- // @param out_total_samples receives total number of samples output
- // @return TTS_SUCCESS or TTS_FAILURE
- virtual tts_result SynthesizeText(const char *text,
- int16_t* audio_buffer,
- int audio_sample_count,
- int* out_total_samples) = 0;
-};
-
-} // namespace speech_synthesis
-
-#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_TTS_ENGINE_H_
diff --git a/tts_receiver.h b/tts_receiver.h
deleted file mode 100644
index 208dd64..0000000
--- a/tts_receiver.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// 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_
-
diff --git a/tts_service.cc b/tts_service.cc
deleted file mode 100644
index 7010afd..0000000
--- a/tts_service.cc
+++ /dev/null
@@ -1,308 +0,0 @@
-// 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.
-
-#include "tts_service.h"
-
-#include "log.h"
-#include "resampler.h"
-#include "ringbuffer.h"
-#include "tts_engine.h"
-
-namespace speech_synthesis {
-
-UtteranceOptions::UtteranceOptions()
- : rate(1),
- pitch(1),
- volume(1),
- enqueue(false),
- interruptible(true) {
-}
-
-TtsService::TtsService(TtsEngine *engine, AudioOutput *audio_output)
- : engine_(engine),
- audio_output_(audio_output),
- current_utterance_(NULL),
- mutex_(Mutex::Create()),
- cond_var_(CondVar::Create()),
- service_running_(false),
- utterance_running_(false),
- current_utterance_interruptible_(true) {
-}
-
-TtsService::~TtsService() {
-}
-
-bool TtsService::StartService() {
- if (!audio_output_->Init(this)) {
- LOG(ERROR) << "TTS Service unable to open audio output.";
- return false;
- }
- ring_buffer_.reset(
- new RingBuffer<int16_t>(audio_output_->GetTotalBufferSize()));
- audio_buffer_.resize(audio_output_->GetChunkSize());
- if (engine_->Init() != TTS_SUCCESS) {
- return false;
- }
- LOG(INFO) << "StartService";
- audio_output_->StartAudio();
- service_running_ = true;
- thread_.reset(Thread::StartJoinableThread(this));
- return true;
-}
-
-void TtsService::StopService() {
- Stop();
- if (!service_running_) {
- return;
- }
- LOG(INFO) << "Stopping audio.";
- audio_output_->StopAudio();
-
- LOG(INFO) << "Stopping main service.";
- mutex_->Lock();
- service_running_ = false;
- cond_var_->Signal();
- mutex_->Unlock();
-
- LOG(INFO) << "Joining main thread.";
- thread_->Join();
- LOG(INFO) << "Joined";
-}
-
-void TtsService::Speak(const std::string& text,
- const UtteranceOptions& options) {
- if (!service_running_) {
- return;
- }
- Utterance *utterance = new Utterance;
- utterance->text = text;
- if ((utterance->voice_index =
- engine_->GetVoiceIndex(options.voice_options)) == -1) {
- utterance->voice_index = 0;
- }
- utterance->options = options;
-
- mutex_->Lock();
- if (!utterance->options.enqueue) {
- // Remove from the back until a non-interruptible utterance is found.
- // This means that the an utterance being non-interruptible gives a
- // cascading effect on the utterances that are queued before the
- // non-interruptible utterance. It can be enforced at a higher level
- // that if interruptiple == false, then enqueue = false.
- while (!utterances_.empty() &&
- utterances_.back()->options.interruptible) {
- delete utterances_.back();
- utterances_.pop_back();
- }
- if (utterances_.empty() && current_utterance_interruptible_) {
- ring_buffer_->Reset();
- utterance_running_ = false;
- }
- }
- utterances_.push_back(utterance);
- cond_var_->Signal();
- mutex_->Unlock();
-}
-
-void TtsService::Stop() {
- if (!service_running_) {
- return;
- }
- mutex_->Lock();
- ring_buffer_->Reset();
- while (!utterances_.empty()) {
- delete utterances_.front();
- utterances_.pop_front();
- }
- utterance_running_ = false;
- cond_var_->Signal();
- mutex_->Unlock();
-}
-
-tts_status TtsService::GetStatus() {
- if (!service_running_) {
- return TTS_ERROR;
- }
- tts_status status;
- mutex_->Lock();
- if (utterances_.empty() && !utterance_running_)
- status = TTS_IDLE;
- else
- status = TTS_BUSY;
- mutex_->Unlock();
- return status;
-}
-
-void TtsService::WaitUntilFinished() {
- if (!service_running_) {
- return;
- }
- mutex_->Lock();
- while (!utterances_.empty() || utterance_running_) {
- cond_var_->Wait(mutex_.get());
- }
- mutex_->Unlock();
-}
-
-void TtsService::Run() {
- if (!service_running_) {
- return;
- }
- LOG(INFO) << "Running background thread";
- for (;;) {
- mutex_->Lock();
- // If there are no utterances and there's no signal to stop,
- // wait on our condition variable, which will allow this thread to
- // sleep with no CPU usage and wake up immediately when there's
- // work for us to do.
- if (utterances_.empty() && service_running_ == true) {
- cond_var_->Wait(mutex_.get());
- }
-
- if (service_running_ == false) {
- LOG(INFO) << "Exiting background thread";
- while (!utterances_.empty()) {
- delete utterances_.front();
- utterances_.pop_front();
- }
- mutex_->Unlock();
- return;
- }
-
- if (current_utterance_ == NULL && !utterances_.empty()) {
- current_utterance_ = utterances_.front();
- current_utterance_interruptible_ =
- current_utterance_->options.interruptible;
- utterances_.pop_front();
- }
-
- utterance_running_ = true;
-
- mutex_->Unlock();
-
- if (!current_utterance_) {
- continue;
- }
-
- engine_->SetRate(current_utterance_->options.rate);
- engine_->SetPitch(current_utterance_->options.pitch);
- engine_->SetVolume(current_utterance_->options.volume);
-
- // Synthesize the current utterance. The TTS engine will call our
- // callback method, Receive, repeatedly while it performs synthesis.
- // During that callback, we check if Stop was called and can cause
- // this method to exit prematurely. Otherwise this method won't exit
- // until this utterance is done synthesizing, and then current_utterance_
- // will be set to NULL.
- int samples_output = 0;
- engine_->SetVoice(current_utterance_->voice_index);
-
- scoped_ptr<Resampler> resampler;
- if (audio_output_->GetSampleRate() != engine_->GetSampleRate()) {
- resampler.reset(new Resampler(this,
- engine_->GetSampleRate(),
- audio_output_->GetSampleRate(),
- audio_buffer_.size()));
- engine_->SetReceiver(resampler.get());
- } else {
- engine_->SetReceiver(this);
- }
-
- // Save the utterance text because current_utterance_ is deleted
- // by the Done() callback before the call to SynthesizeText exits.
- string utterance_text = current_utterance_->text;
-
- engine_->SynthesizeText(
- utterance_text.c_str(),
- &audio_buffer_[0],
- audio_buffer_.size(),
- &samples_output);
-
- // TODO(chaitanyag): Make the completion callback here.
- VLOG(3) << "Done: " << utterance_text.c_str();
-
- mutex_->Lock();
- if (utterance_running_ == false) {
- // The utterance was interrupted
- engine_->Stop();
- }
- utterance_running_ = false;
- cond_var_->Signal();
- mutex_->Unlock();
-
- delete current_utterance_;
- current_utterance_ = NULL;
- }
-}
-
-tts_callback_status TtsService::Receive(int rate,
- int num_channels,
- const int16_t* data,
- int num_samples,
- tts_synth_status status) {
- if (status == TTS_SYNTH_DONE) {
- current_utterance_ = NULL;
- }
-
- // Check if we need to exit prematurely
- mutex_->Lock();
- if (service_running_ == false || utterance_running_ == false) {
- mutex_->Unlock();
- return TTS_CALLBACK_HALT;
- }
- mutex_->Unlock();
-
- // If there's no audio data, just return success
- if (num_samples == 0) {
- return TTS_CALLBACK_CONTINUE;
- }
-
- // If the ring buffer is full, compute the amount of time we expect
- // it to take for that many audio samples to be output, and sleep for
- // that long.
- while (ring_buffer_->WriteAvail() < num_samples) {
- int ms_to_sleep = num_samples * 1000 / rate;
- mutex_->Lock();
- cond_var_->WaitWithTimeout(mutex_.get(), ms_to_sleep);
- if (service_running_ == false || utterance_running_ == false) {
- mutex_->Unlock();
- return TTS_CALLBACK_HALT;
- }
- mutex_->Unlock();
- }
-
- bool success = ring_buffer_->Write(data, num_samples);
- if (!success) {
- LOG(INFO) << "Unable to write to ring buffer";
- exit(0);
- }
-
- if (status == TTS_SYNTH_DONE) {
- ring_buffer_->MarkFinished();
- }
-
- return TTS_CALLBACK_CONTINUE;
-}
-
-bool TtsService::FillAudioBuffer(int16_t* samples, int size) {
- int avail = ring_buffer_->ReadAvail();
-
- // If the ring buffer is finished, play until the end. Otherwise,
- // only play if we have a full buffer.
- int copy_len;
- if (ring_buffer_->IsFinished()) {
- copy_len = avail < size? avail : size;
- } else {
- copy_len = avail >= size? size : 0;
- }
-
- ring_buffer_->Read(samples, copy_len);
- for (int i = copy_len; i < size; i++) {
- samples[i] = 0;
- }
-
- return !ring_buffer_->IsFinished();
-}
-
-} // namespace speech_synthesis
diff --git a/tts_service.h b/tts_service.h
deleted file mode 100644
index af8604f..0000000
--- a/tts_service.h
+++ /dev/null
@@ -1,143 +0,0 @@
-// 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.
-//
-// This header defines the interface to access a Text-To-Speech service
-// that manages background threads and presents a real-time, nonblocking
-// interface.
-
-#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_TTS_SERVICE_H_
-#define SPEECH_CLIENT_SYNTHESIS_SERVICE_TTS_SERVICE_H_
-
-#include <stdint.h>
-
-#include <list>
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-
-#include "audio_output.h"
-#include "threading.h"
-#include "tts_engine.h"
-#include "tts_receiver.h"
-
-namespace speech_synthesis {
-
-enum tts_status {
- TTS_IDLE = 0,
- TTS_BUSY = 1,
- TTS_ERROR = 2,
-};
-
-template<typename T> class RingBuffer;
-class TtsEngine;
-
-// Add more such as rate, pitch etc. in the future.
-struct UtteranceOptions {
- public:
- TtsVoice voice_options;
- // Default is 1. Use higher or lower values to increase or decrease the
- // speaking rate. Map default to ~100 words/min if possible. Speech
- // engines may or may not support this mapping.
- float rate;
- // Default is 1. Use higher or lower values to increase or decrease the
- // speaking pitch. Map default to 200 Hz if possible. Speech
- // engines may or may not support this exact mapping.
- float pitch;
- // Default is 1. Use higher or lower values to increase or decrease the
- // speaking volume.
- float volume;
- // Whether to enqueue this utterance or flush the existing queue.
- bool enqueue;
- // Whether this utterance is interruptible.
- bool interruptible;
-
- UtteranceOptions();
-};
-
-struct Utterance {
- public:
- std::string text;
- int voice_index;
- UtteranceOptions options;
-};
-
-class TtsService
- : public AudioProvider,
- public Runnable,
- public TtsDataReceiver {
- public:
- TtsService(TtsEngine *engine, AudioOutput *audio_output);
-
- virtual ~TtsService();
-
- //
- // External interface
- //
-
- // Start the background service
- bool StartService();
-
- // Stop the background service.
- void StopService();
-
- // Queue up this text to be spoken and return immediately. The
- // UtteranceOptions contains other settings such as language name, voice,
- // pitch, rate etc. Currently language name specified as:
- // <language>-<locale> is supported. Example: en-US, fr-FR, etc.
- void Speak(const std::string& text, const UtteranceOptions& options);
-
- // Interrupts the current utterance and discards other utterances
- // in the queue.
- void Stop();
-
- // Determine if the service is busy or speaking.
- tts_status GetStatus();
-
- // Block until all queued utterances are done speaking.
- void WaitUntilFinished();
-
- //
- // Internal implementation
- //
-
- // Implementation of AudioProvider, called by the audio output thread.
- bool FillAudioBuffer(int16_t* samples, int size);
-
- // Implementation of Runnable, for our background thread.
- virtual void Run() OVERRIDE;
-
- // Implementation of TtsDataReceiver, where the TtsEngine calls us
- // with the generated audio data.
- tts_callback_status Receive(int rate,
- int num_channels,
- const int16_t* data,
- int num_samples,
- tts_synth_status status);
-
- private:
- TtsEngine *engine_;
- AudioOutput *audio_output_;
- scoped_ptr<RingBuffer<int16_t> > ring_buffer_;
- scoped_ptr<Thread> thread_;
- Utterance *current_utterance_;
- std::vector<int16_t> audio_buffer_;
-
- // A mutex and condition variable
- scoped_ptr<Mutex> mutex_;
- scoped_ptr<CondVar> cond_var_;
-
- // Variables that are protected by the mutex and signaled by the
- // condition variable.
- std::list<Utterance*> utterances_;
- bool service_running_;
- bool utterance_running_;
- bool current_utterance_interruptible_;
-
- DISALLOW_COPY_AND_ASSIGN(TtsService);
-};
-} // namespace speech_synthesis
-
-#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_TTS_SERVICE_H_