speech_monitor.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright 2014 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 "chrome/browser/chromeos/accessibility/speech_monitor.h" 6 7namespace chromeos { 8 9namespace { 10const char kChromeVoxEnabledMessage[] = "chrome vox spoken feedback is ready"; 11} // anonymous namespace 12 13SpeechMonitor::SpeechMonitor() { 14 TtsController::GetInstance()->SetPlatformImpl(this); 15} 16 17SpeechMonitor::~SpeechMonitor() { 18 TtsController::GetInstance()->SetPlatformImpl(TtsPlatformImpl::GetInstance()); 19} 20 21std::string SpeechMonitor::GetNextUtterance() { 22 if (utterance_queue_.empty()) { 23 loop_runner_ = new content::MessageLoopRunner(); 24 loop_runner_->Run(); 25 loop_runner_ = NULL; 26 } 27 std::string result = utterance_queue_.front(); 28 utterance_queue_.pop_front(); 29 return result; 30} 31 32bool SpeechMonitor::SkipChromeVoxEnabledMessage() { 33 return GetNextUtterance() == kChromeVoxEnabledMessage; 34} 35 36bool SpeechMonitor::PlatformImplAvailable() { 37 return true; 38} 39 40bool SpeechMonitor::Speak( 41 int utterance_id, 42 const std::string& utterance, 43 const std::string& lang, 44 const VoiceData& voice, 45 const UtteranceContinuousParameters& params) { 46 TtsController::GetInstance()->OnTtsEvent( 47 utterance_id, 48 TTS_EVENT_END, 49 static_cast<int>(utterance.size()), 50 std::string()); 51 return true; 52} 53 54bool SpeechMonitor::StopSpeaking() { 55 return true; 56} 57 58bool SpeechMonitor::IsSpeaking() { 59 return false; 60} 61 62void SpeechMonitor::GetVoices(std::vector<VoiceData>* out_voices) { 63 out_voices->push_back(VoiceData()); 64 VoiceData& voice = out_voices->back(); 65 voice.native = true; 66 voice.name = "SpeechMonitor"; 67 voice.events.insert(TTS_EVENT_END); 68} 69 70std::string SpeechMonitor::error() { 71 return ""; 72} 73 74void SpeechMonitor::WillSpeakUtteranceWithVoice(const Utterance* utterance, 75 const VoiceData& voice_data) { 76 utterance_queue_.push_back(utterance->text()); 77 if (loop_runner_.get()) 78 loop_runner_->Quit(); 79} 80 81} // namespace chromeos 82