Commit 1f571012 authored by Katie D's avatar Katie D Committed by Commit Bot

Disable TTS preview play button while playback is in progress.

Bug: 910082
Change-Id: Ic3469bf58361ceafd39cc39bfc84450caa801dbb
Reviewed-on: https://chromium-review.googlesource.com/c/1356232Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Commit-Queue: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612833}
parent 6f1309ef
...@@ -89,7 +89,8 @@ ...@@ -89,7 +89,8 @@
<div class="settings-box continuation"> <div class="settings-box continuation">
<cr-input id="previewInput" label="$i18n{textToSpeechPreviewInputLabel}" <cr-input id="previewInput" label="$i18n{textToSpeechPreviewInputLabel}"
value="$i18n{textToSpeechPreviewInput}"> value="$i18n{textToSpeechPreviewInput}">
<paper-button on-click="onPreviewTtsClick_" disabled="[[!hasVoices]]" <paper-button on-click="onPreviewTtsClick_"
disabled="[[!enablePreviewButton_(allVoices, isPreviewing_)]]"
slot="suffix"> slot="suffix">
$i18n{textToSpeechPreviewPlay} $i18n{textToSpeechPreviewPlay}
</paper-button> </paper-button>
......
...@@ -49,6 +49,15 @@ Polymer({ ...@@ -49,6 +49,15 @@ Polymer({
notify: true, notify: true,
}, },
/**
* Whether preview is currently speaking.
* @private
*/
isPreviewing_: {
type: Boolean,
value: false,
},
/** Whether any voices are loaded. */ /** Whether any voices are loaded. */
hasVoices: { hasVoices: {
type: Boolean, type: Boolean,
...@@ -69,6 +78,8 @@ Polymer({ ...@@ -69,6 +78,8 @@ Polymer({
chrome.send('getAllTtsVoiceData'); chrome.send('getAllTtsVoiceData');
this.addWebUIListener( this.addWebUIListener(
'tts-extensions-updated', this.populateExtensionList_.bind(this)); 'tts-extensions-updated', this.populateExtensionList_.bind(this));
this.addWebUIListener(
'tts-preview-state-changed', this.onTtsPreviewStateChanged_.bind(this));
chrome.send('getTtsExtensions'); chrome.send('getTtsExtensions');
}, },
...@@ -137,6 +148,17 @@ Polymer({ ...@@ -137,6 +148,17 @@ Polymer({
return voices.length > 0; return voices.length > 0;
}, },
/**
* Returns true if voices are loaded and preview is not currently speaking.
* @param {!Array<TtsHandlerVoice>} voices
* @param {boolean} isPreviewing
* @return {boolean}
* @private
*/
enablePreviewButton_: function(voices, isPreviewing) {
return this.hasVoices_(voices) && !isPreviewing;
},
/** /**
* Populates the list of languages and voices for the UI to use in display. * Populates the list of languages and voices for the UI to use in display.
* @param {Array<TtsHandlerVoice>} voices * @param {Array<TtsHandlerVoice>} voices
...@@ -208,6 +230,16 @@ Polymer({ ...@@ -208,6 +230,16 @@ Polymer({
this.extensions = extensions; this.extensions = extensions;
}, },
/**
* Called when the TTS voice preview state changes between speaking and not
* speaking.
* @param {boolean} isSpeaking
* @private
*/
onTtsPreviewStateChanged_: function(isSpeaking) {
this.isPreviewing_ = isSpeaking;
},
/** /**
* A function used for sorting languages alphabetically. * A function used for sorting languages alphabetically.
* @param {Object} first A languageToVoices array item. * @param {Object} first A languageToVoices array item.
......
...@@ -108,6 +108,18 @@ void TtsHandler::OnVoicesChanged() { ...@@ -108,6 +108,18 @@ void TtsHandler::OnVoicesChanged() {
HandleGetTtsExtensions(nullptr); HandleGetTtsExtensions(nullptr);
} }
void TtsHandler::OnTtsEvent(content::Utterance* utterance,
content::TtsEventType event_type,
int char_index,
const std::string& error_message) {
if (event_type == content::TTS_EVENT_END ||
event_type == content::TTS_EVENT_INTERRUPTED ||
event_type == content::TTS_EVENT_ERROR) {
base::Value result(false /* preview stopped */);
FireWebUIListener("tts-preview-state-changed", result);
}
}
void TtsHandler::HandlePreviewTtsVoice(const base::ListValue* args) { void TtsHandler::HandlePreviewTtsVoice(const base::ListValue* args) {
DCHECK_EQ(2U, args->GetSize()); DCHECK_EQ(2U, args->GetSize());
std::string text; std::string text;
...@@ -131,8 +143,11 @@ void TtsHandler::HandlePreviewTtsVoice(const base::ListValue* args) { ...@@ -131,8 +143,11 @@ void TtsHandler::HandlePreviewTtsVoice(const base::ListValue* args) {
utterance->set_voice_name(name); utterance->set_voice_name(name);
utterance->set_extension_id(extension_id); utterance->set_extension_id(extension_id);
utterance->set_src_url(GURL("chrome://settings/manageAccessibility/tts")); utterance->set_src_url(GURL("chrome://settings/manageAccessibility/tts"));
utterance->set_event_delegate(nullptr); utterance->set_event_delegate(this);
content::TtsController::GetInstance()->Stop(); content::TtsController::GetInstance()->Stop();
base::Value result(true /* preview started */);
FireWebUIListener("tts-preview-state-changed", result);
content::TtsController::GetInstance()->SpeakOrEnqueue(utterance); content::TtsController::GetInstance()->SpeakOrEnqueue(utterance);
} }
...@@ -159,6 +174,7 @@ void TtsHandler::OnJavascriptAllowed() { ...@@ -159,6 +174,7 @@ void TtsHandler::OnJavascriptAllowed() {
void TtsHandler::OnJavascriptDisallowed() { void TtsHandler::OnJavascriptDisallowed() {
content::TtsController::GetInstance()->RemoveVoicesChangedDelegate(this); content::TtsController::GetInstance()->RemoveVoicesChangedDelegate(this);
content::TtsController::GetInstance()->RemoveUtteranceEventDelegate(this);
} }
int TtsHandler::GetVoiceLangMatchScore(const content::VoiceData* voice, int TtsHandler::GetVoiceLangMatchScore(const content::VoiceData* voice,
......
...@@ -15,7 +15,8 @@ namespace settings { ...@@ -15,7 +15,8 @@ namespace settings {
// Chrome "/manageAccessibility/tts/*" settings page UI handler. // Chrome "/manageAccessibility/tts/*" settings page UI handler.
class TtsHandler : public SettingsPageUIHandler, class TtsHandler : public SettingsPageUIHandler,
public content::VoicesChangedDelegate { public content::VoicesChangedDelegate,
public content::UtteranceEventDelegate {
public: public:
TtsHandler(); TtsHandler();
~TtsHandler() override; ~TtsHandler() override;
...@@ -32,6 +33,12 @@ class TtsHandler : public SettingsPageUIHandler, ...@@ -32,6 +33,12 @@ class TtsHandler : public SettingsPageUIHandler,
// VoicesChangedDelegate implementation. // VoicesChangedDelegate implementation.
void OnVoicesChanged() override; void OnVoicesChanged() override;
// UtteranceEventDelegate implementation.
void OnTtsEvent(content::Utterance* utterance,
content::TtsEventType event_type,
int char_index,
const std::string& error_message) override;
private: private:
void WakeTtsEngine(const base::ListValue* args); void WakeTtsEngine(const base::ListValue* args);
void OnTtsEngineAwake(bool success); void OnTtsEngineAwake(bool success);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment