Index: content/renderer/tts_dispatcher.cc |
diff --git a/content/renderer/tts_dispatcher.cc b/content/renderer/tts_dispatcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..65a1e289baa2c483978646e99c6ae323881459df |
--- /dev/null |
+++ b/content/renderer/tts_dispatcher.cc |
@@ -0,0 +1,144 @@ |
+// Copyright (c) 2013 The Chromium 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 "content/renderer/tts_dispatcher.h" |
+ |
+#include "base/basictypes.h" |
+#include "base/utf_string_conversions.h" |
+#include "content/common/tts_messages.h" |
+#include "content/public/common/tts_utterance_request.h" |
+#include "content/renderer/render_view_impl.h" |
+#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
+#include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechSynthesisClient.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechSynthesisUtterance.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechSynthesisVoice.h" |
+ |
+using WebKit::WebSpeechSynthesisClient; |
+using WebKit::WebSpeechSynthesisUtterance; |
+using WebKit::WebSpeechSynthesisVoice; |
+using WebKit::WebString; |
+using WebKit::WebVector; |
+ |
+namespace content { |
+ |
+TtsDispatcher::TtsDispatcher(RenderViewImpl* render_view) |
+ : RenderViewObserver(render_view), |
+ synthesis_client_(NULL) { |
+} |
+ |
+TtsDispatcher::~TtsDispatcher() { |
+} |
+ |
+bool TtsDispatcher::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(TtsDispatcher, message) |
+ IPC_MESSAGE_HANDLER(TtsMsg_SetVoiceList, OnSetVoiceList) |
+ IPC_MESSAGE_HANDLER(TtsMsg_DidStartSpeaking, OnDidStartSpeaking) |
+ IPC_MESSAGE_HANDLER(TtsMsg_DidFinishSpeaking, OnDidFinishSpeaking) |
+ IPC_MESSAGE_HANDLER(TtsMsg_DidPauseSpeaking, OnDidPauseSpeaking) |
+ IPC_MESSAGE_HANDLER(TtsMsg_DidResumeSpeaking, OnDidResumeSpeaking) |
+ IPC_MESSAGE_HANDLER(TtsMsg_WordBoundary, OnWordBoundary) |
+ IPC_MESSAGE_HANDLER(TtsMsg_SentenceBoundary, OnSentenceBoundary) |
+ IPC_MESSAGE_HANDLER(TtsMsg_MarkerEvent, OnMarkerEvent) |
+ IPC_MESSAGE_HANDLER(TtsMsg_WasInterrupted, OnWasInterrupted) |
+ IPC_MESSAGE_HANDLER(TtsMsg_WasCancelled, OnWasCancelled) |
+ IPC_MESSAGE_HANDLER(TtsMsg_SpeakingErrorOccurred, OnSpeakingErrorOccurred) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void TtsDispatcher::setClient(WebSpeechSynthesisClient* client) { |
+ synthesis_client_ = client; |
+} |
+ |
+void TtsDispatcher::initializeVoiceList() { |
+ Send(new TtsHostMsg_InitializeVoiceList(routing_id())); |
+} |
+ |
+void TtsDispatcher::speak(const WebSpeechSynthesisUtterance& web_utterance) { |
+ TtsUtteranceRequest utterance; |
+ utterance.id = web_utterance.id(); |
+ utterance.text = web_utterance.text().utf8(); |
+ utterance.lang = web_utterance.lang().utf8(); |
+ utterance.voice = web_utterance.voice().utf8(); |
+ utterance.volume = web_utterance.volume(); |
+ utterance.rate = web_utterance.rate(); |
+ utterance.pitch = web_utterance.pitch(); |
+ Send(new TtsHostMsg_Speak(routing_id(), utterance)); |
+} |
+ |
+void TtsDispatcher::pause() { |
+ Send(new TtsHostMsg_Pause()); |
+} |
+ |
+void TtsDispatcher::resume() { |
+ Send(new TtsHostMsg_Resume()); |
+} |
+ |
+void TtsDispatcher::cancel() { |
+ Send(new TtsHostMsg_Cancel()); |
+} |
+ |
+void TtsDispatcher::OnSetVoiceList( |
+ const std::vector<content::TtsVoice>& voices) { |
+ WebVector<WebSpeechSynthesisVoice> out_voices(voices.size()); |
+ for (size_t i = 0; i < voices.size(); i++) { |
tommi (sloooow) - chröme
2013/03/07 13:04:46
++i
dmazzoni
2013/03/19 17:30:22
Done.
|
+ out_voices[i] = WebSpeechSynthesisVoice(); |
+ out_voices[i].assign(WebString::fromUTF8(voices[i].voice_uri), |
+ WebString::fromUTF8(voices[i].name), |
+ WebString::fromUTF8(voices[i].lang), |
+ voices[i].local_service, |
+ voices[i].is_default); |
+ } |
+ synthesis_client_->setVoiceList(out_voices); |
+} |
+ |
+void TtsDispatcher::OnDidStartSpeaking(int utterance_id) { |
+ synthesis_client_->didStartSpeaking(utterance_id); |
+} |
+ |
+void TtsDispatcher::OnDidFinishSpeaking(int utterance_id) { |
+ synthesis_client_->didFinishSpeaking(utterance_id); |
+} |
+ |
+void TtsDispatcher::OnDidPauseSpeaking(int utterance_id) { |
+ synthesis_client_->didPauseSpeaking(utterance_id); |
+} |
+ |
+void TtsDispatcher::OnDidResumeSpeaking(int utterance_id) { |
+ synthesis_client_->didResumeSpeaking(utterance_id); |
+} |
+ |
+void TtsDispatcher::OnWordBoundary(int utterance_id, int char_index) { |
+ synthesis_client_->wordBoundaryEventOccurred(utterance_id, char_index); |
+} |
+ |
+void TtsDispatcher::OnSentenceBoundary(int utterance_id, int char_index) { |
+ synthesis_client_->sentenceBoundaryEventOccurred(utterance_id, char_index); |
+} |
+ |
+void TtsDispatcher::OnMarkerEvent(int utterance_id, int char_index) { |
+ // Not supported yet. |
+} |
+ |
+void TtsDispatcher::OnWasInterrupted(int utterance_id) { |
+ // The web speech API doesn't support "interrupted". |
+ synthesis_client_->didFinishSpeaking(utterance_id); |
+} |
+ |
+void TtsDispatcher::OnWasCancelled(int utterance_id) { |
+ // The web speech API doesn't support "cancelled". |
+ synthesis_client_->didFinishSpeaking(utterance_id); |
+} |
+ |
+void TtsDispatcher::OnSpeakingErrorOccurred(int utterance_id, |
+ const std::string& error_message) { |
+ // The web speech API doesn't support an error message.x |
+ synthesis_client_->speakingErrorOccurred(utterance_id); |
+} |
+ |
+ |
+} // namespace content |