| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <math.h> | 5 #include <math.h> |
| 6 #include <sapi.h> | 6 #include <sapi.h> |
| 7 #include <stdint.h> |
| 7 | 8 |
| 9 #include "base/macros.h" |
| 8 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 9 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | 13 #include "base/values.h" |
| 12 #include "base/win/scoped_comptr.h" | 14 #include "base/win/scoped_comptr.h" |
| 13 #include "chrome/browser/speech/tts_controller.h" | 15 #include "chrome/browser/speech/tts_controller.h" |
| 14 #include "chrome/browser/speech/tts_platform.h" | 16 #include "chrome/browser/speech/tts_platform.h" |
| 15 | 17 |
| 16 class TtsPlatformImplWin : public TtsPlatformImpl { | 18 class TtsPlatformImplWin : public TtsPlatformImpl { |
| 17 public: | 19 public: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return false; | 82 return false; |
| 81 | 83 |
| 82 // TODO(dmazzoni): support languages other than the default: crbug.com/88059 | 84 // TODO(dmazzoni): support languages other than the default: crbug.com/88059 |
| 83 | 85 |
| 84 if (params.rate >= 0.0) { | 86 if (params.rate >= 0.0) { |
| 85 // Map our multiplicative range of 0.1x to 10.0x onto Microsoft's | 87 // Map our multiplicative range of 0.1x to 10.0x onto Microsoft's |
| 86 // linear range of -10 to 10: | 88 // linear range of -10 to 10: |
| 87 // 0.1 -> -10 | 89 // 0.1 -> -10 |
| 88 // 1.0 -> 0 | 90 // 1.0 -> 0 |
| 89 // 10.0 -> 10 | 91 // 10.0 -> 10 |
| 90 speech_synthesizer_->SetRate(static_cast<int32>(10 * log10(params.rate))); | 92 speech_synthesizer_->SetRate(static_cast<int32_t>(10 * log10(params.rate))); |
| 91 } | 93 } |
| 92 | 94 |
| 93 if (params.pitch >= 0.0) { | 95 if (params.pitch >= 0.0) { |
| 94 // The TTS api allows a range of -10 to 10 for speech pitch. | 96 // The TTS api allows a range of -10 to 10 for speech pitch. |
| 95 // TODO(dtseng): cleanup if we ever use any other properties that | 97 // TODO(dtseng): cleanup if we ever use any other properties that |
| 96 // require xml. | 98 // require xml. |
| 97 std::wstring pitch_value = | 99 std::wstring pitch_value = |
| 98 base::IntToString16(static_cast<int>(params.pitch * 10 - 10)); | 100 base::IntToString16(static_cast<int>(params.pitch * 10 - 10)); |
| 99 prefix = L"<pitch absmiddle=\"" + pitch_value + L"\">"; | 101 prefix = L"<pitch absmiddle=\"" + pitch_value + L"\">"; |
| 100 suffix = L"</pitch>"; | 102 suffix = L"</pitch>"; |
| 101 } | 103 } |
| 102 | 104 |
| 103 if (params.volume >= 0.0) { | 105 if (params.volume >= 0.0) { |
| 104 // The TTS api allows a range of 0 to 100 for speech volume. | 106 // The TTS api allows a range of 0 to 100 for speech volume. |
| 105 speech_synthesizer_->SetVolume(static_cast<uint16>(params.volume * 100)); | 107 speech_synthesizer_->SetVolume(static_cast<uint16_t>(params.volume * 100)); |
| 106 } | 108 } |
| 107 | 109 |
| 108 // TODO(dmazzoni): convert SSML to SAPI xml. http://crbug.com/88072 | 110 // TODO(dmazzoni): convert SSML to SAPI xml. http://crbug.com/88072 |
| 109 | 111 |
| 110 utterance_ = base::UTF8ToWide(src_utterance); | 112 utterance_ = base::UTF8ToWide(src_utterance); |
| 111 utterance_id_ = utterance_id; | 113 utterance_id_ = utterance_id; |
| 112 char_position_ = 0; | 114 char_position_ = 0; |
| 113 std::wstring merged_utterance = prefix + utterance_ + suffix; | 115 std::wstring merged_utterance = prefix + utterance_ + suffix; |
| 114 prefix_len_ = prefix.size(); | 116 prefix_len_ = prefix.size(); |
| 115 | 117 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 TtsPlatformImplWin* TtsPlatformImplWin::GetInstance() { | 252 TtsPlatformImplWin* TtsPlatformImplWin::GetInstance() { |
| 251 return base::Singleton<TtsPlatformImplWin, | 253 return base::Singleton<TtsPlatformImplWin, |
| 252 base::LeakySingletonTraits<TtsPlatformImplWin>>::get(); | 254 base::LeakySingletonTraits<TtsPlatformImplWin>>::get(); |
| 253 } | 255 } |
| 254 | 256 |
| 255 // static | 257 // static |
| 256 void TtsPlatformImplWin::SpeechEventCallback( | 258 void TtsPlatformImplWin::SpeechEventCallback( |
| 257 WPARAM w_param, LPARAM l_param) { | 259 WPARAM w_param, LPARAM l_param) { |
| 258 GetInstance()->OnSpeechEvent(); | 260 GetInstance()->OnSpeechEvent(); |
| 259 } | 261 } |
| OLD | NEW |