OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/tts_dispatcher.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/utf_string_conversions.h" | |
9 #include "content/common/tts_messages.h" | |
10 #include "content/public/common/tts_utterance_request.h" | |
11 #include "content/renderer/render_view_impl.h" | |
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | |
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechSynthesisCli ent.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechSynthesisUtt erance.h" | |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechSynthesisVoi ce.h" | |
17 | |
18 using WebKit::WebSpeechSynthesisClient; | |
19 using WebKit::WebSpeechSynthesisUtterance; | |
20 using WebKit::WebSpeechSynthesisVoice; | |
21 using WebKit::WebString; | |
22 using WebKit::WebVector; | |
23 | |
24 namespace content { | |
25 | |
26 TtsDispatcher::TtsDispatcher(RenderViewImpl* render_view) | |
27 : RenderViewObserver(render_view), | |
28 synthesis_client_(NULL) { | |
29 } | |
30 | |
31 TtsDispatcher::~TtsDispatcher() { | |
32 } | |
33 | |
34 bool TtsDispatcher::OnMessageReceived(const IPC::Message& message) { | |
35 bool handled = true; | |
36 IPC_BEGIN_MESSAGE_MAP(TtsDispatcher, message) | |
37 IPC_MESSAGE_HANDLER(TtsMsg_SetVoiceList, OnSetVoiceList) | |
38 IPC_MESSAGE_HANDLER(TtsMsg_DidStartSpeaking, OnDidStartSpeaking) | |
39 IPC_MESSAGE_HANDLER(TtsMsg_DidFinishSpeaking, OnDidFinishSpeaking) | |
40 IPC_MESSAGE_HANDLER(TtsMsg_DidPauseSpeaking, OnDidPauseSpeaking) | |
41 IPC_MESSAGE_HANDLER(TtsMsg_DidResumeSpeaking, OnDidResumeSpeaking) | |
42 IPC_MESSAGE_HANDLER(TtsMsg_WordBoundary, OnWordBoundary) | |
43 IPC_MESSAGE_HANDLER(TtsMsg_SentenceBoundary, OnSentenceBoundary) | |
44 IPC_MESSAGE_HANDLER(TtsMsg_MarkerEvent, OnMarkerEvent) | |
45 IPC_MESSAGE_HANDLER(TtsMsg_WasInterrupted, OnWasInterrupted) | |
46 IPC_MESSAGE_HANDLER(TtsMsg_WasCancelled, OnWasCancelled) | |
47 IPC_MESSAGE_HANDLER(TtsMsg_SpeakingErrorOccurred, OnSpeakingErrorOccurred) | |
48 IPC_MESSAGE_UNHANDLED(handled = false) | |
49 IPC_END_MESSAGE_MAP() | |
50 return handled; | |
51 } | |
52 | |
53 void TtsDispatcher::setClient(WebSpeechSynthesisClient* client) { | |
54 synthesis_client_ = client; | |
55 } | |
56 | |
57 void TtsDispatcher::initializeVoiceList() { | |
58 Send(new TtsHostMsg_InitializeVoiceList(routing_id())); | |
59 } | |
60 | |
61 void TtsDispatcher::speak(const WebSpeechSynthesisUtterance& web_utterance) { | |
62 TtsUtteranceRequest utterance; | |
63 utterance.id = web_utterance.id(); | |
64 utterance.text = web_utterance.text().utf8(); | |
65 utterance.lang = web_utterance.lang().utf8(); | |
66 utterance.voice = web_utterance.voice().utf8(); | |
67 utterance.volume = web_utterance.volume(); | |
68 utterance.rate = web_utterance.rate(); | |
69 utterance.pitch = web_utterance.pitch(); | |
70 Send(new TtsHostMsg_Speak(routing_id(), utterance)); | |
71 } | |
72 | |
73 void TtsDispatcher::pause() { | |
74 Send(new TtsHostMsg_Pause()); | |
75 } | |
76 | |
77 void TtsDispatcher::resume() { | |
78 Send(new TtsHostMsg_Resume()); | |
79 } | |
80 | |
81 void TtsDispatcher::cancel() { | |
82 Send(new TtsHostMsg_Cancel()); | |
83 } | |
84 | |
85 void TtsDispatcher::OnSetVoiceList( | |
86 const std::vector<content::TtsVoice>& voices) { | |
87 WebVector<WebSpeechSynthesisVoice> out_voices(voices.size()); | |
88 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.
| |
89 out_voices[i] = WebSpeechSynthesisVoice(); | |
90 out_voices[i].assign(WebString::fromUTF8(voices[i].voice_uri), | |
91 WebString::fromUTF8(voices[i].name), | |
92 WebString::fromUTF8(voices[i].lang), | |
93 voices[i].local_service, | |
94 voices[i].is_default); | |
95 } | |
96 synthesis_client_->setVoiceList(out_voices); | |
97 } | |
98 | |
99 void TtsDispatcher::OnDidStartSpeaking(int utterance_id) { | |
100 synthesis_client_->didStartSpeaking(utterance_id); | |
101 } | |
102 | |
103 void TtsDispatcher::OnDidFinishSpeaking(int utterance_id) { | |
104 synthesis_client_->didFinishSpeaking(utterance_id); | |
105 } | |
106 | |
107 void TtsDispatcher::OnDidPauseSpeaking(int utterance_id) { | |
108 synthesis_client_->didPauseSpeaking(utterance_id); | |
109 } | |
110 | |
111 void TtsDispatcher::OnDidResumeSpeaking(int utterance_id) { | |
112 synthesis_client_->didResumeSpeaking(utterance_id); | |
113 } | |
114 | |
115 void TtsDispatcher::OnWordBoundary(int utterance_id, int char_index) { | |
116 synthesis_client_->wordBoundaryEventOccurred(utterance_id, char_index); | |
117 } | |
118 | |
119 void TtsDispatcher::OnSentenceBoundary(int utterance_id, int char_index) { | |
120 synthesis_client_->sentenceBoundaryEventOccurred(utterance_id, char_index); | |
121 } | |
122 | |
123 void TtsDispatcher::OnMarkerEvent(int utterance_id, int char_index) { | |
124 // Not supported yet. | |
125 } | |
126 | |
127 void TtsDispatcher::OnWasInterrupted(int utterance_id) { | |
128 // The web speech API doesn't support "interrupted". | |
129 synthesis_client_->didFinishSpeaking(utterance_id); | |
130 } | |
131 | |
132 void TtsDispatcher::OnWasCancelled(int utterance_id) { | |
133 // The web speech API doesn't support "cancelled". | |
134 synthesis_client_->didFinishSpeaking(utterance_id); | |
135 } | |
136 | |
137 void TtsDispatcher::OnSpeakingErrorOccurred(int utterance_id, | |
138 const std::string& error_message) { | |
139 // The web speech API doesn't support an error message.x | |
140 synthesis_client_->speakingErrorOccurred(utterance_id); | |
141 } | |
142 | |
143 | |
144 } // namespace content | |
OLD | NEW |