blob: 2a6fc13d85109229ca2cceb804c0982f1b0c26af [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.
#include <unistd.h>
#include <chromeos/dbus/dbus.h>
#include <chromeos/dbus/service_constants.h>
#include <chromeos/glib/object.h>
#include "bindings/client.h"
#include "marshal.h" // NOLINT
#include "tts_extern.h"
namespace chromeos {
bool Speak(const char* text) {
g_type_init();
chromeos::dbus::BusConnection bus = chromeos::dbus::GetSystemBusConnection();
chromeos::dbus::Proxy tts_proxy(bus,
speech_synthesis::kSpeechSynthesizerServiceName,
speech_synthesis::kSpeechSynthesizerServicePath,
speech_synthesis::kSpeechSynthesizerInterface);
DCHECK(tts_proxy.gproxy()) << "Failed to acquire proxy";
if (!::org_chromium_SpeechSynthesizerInterface_speak(
tts_proxy.gproxy(), text, NULL)) {
return false;
}
return true;
}
bool Stop() {
g_type_init();
chromeos::dbus::BusConnection bus = chromeos::dbus::GetSystemBusConnection();
chromeos::dbus::Proxy tts_proxy(bus,
speech_synthesis::kSpeechSynthesizerServiceName,
speech_synthesis::kSpeechSynthesizerServicePath,
speech_synthesis::kSpeechSynthesizerInterface);
DCHECK(tts_proxy.gproxy()) << "Failed to acquire proxy";
if (!::org_chromium_SpeechSynthesizerInterface_stop(
tts_proxy.gproxy(), NULL)) {
return false;
}
return true;
}
bool IsSpeaking() {
g_type_init();
chromeos::dbus::BusConnection bus = chromeos::dbus::GetSystemBusConnection();
chromeos::dbus::Proxy tts_proxy(bus,
speech_synthesis::kSpeechSynthesizerServiceName,
speech_synthesis::kSpeechSynthesizerServicePath,
speech_synthesis::kSpeechSynthesizerInterface);
DCHECK(tts_proxy.gproxy()) << "Failed to acquire proxy";
gboolean done;
return ::org_chromium_SpeechSynthesizerInterface_is_speaking(
tts_proxy.gproxy(), &done, NULL);
}
extern "C"
bool ChromeOSSpeak(const char* text) {
return Speak(text);
}
extern "C"
bool ChromeOSStop() {
return Stop();
}
extern "C"
bool ChromeOSIsSpeaking() {
return IsSpeaking();
}
extern "C"
void ChromeOSWaitUntilFinished() {
while (IsSpeaking()) {
usleep(100000); // Wait for 100 ms = 100000 us
}
}
} // namespace chromeos