diff --git a/browser/speedreader/speedreader_tab_helper.cc b/browser/speedreader/speedreader_tab_helper.cc index dbb9b3dd33ac..042bd6bf0bd9 100644 --- a/browser/speedreader/speedreader_tab_helper.cc +++ b/browser/speedreader/speedreader_tab_helper.cc @@ -52,6 +52,11 @@ namespace speedreader { std::u16string GetSpeedreaderData( std::initializer_list> resources) { std::u16string result = u"speedreaderData = {"; + + if (kSpeedreaderTTS.Get()) { + result += u"ttsEnabled: true,"; + } + for (const auto& r : resources) { auto text = brave_l10n::GetLocalizedResourceUTF16String(r.second); // Make sure that the text doesn't contain js injection diff --git a/browser/ui/webui/speedreader/speedreader_toolbar_ui.cc b/browser/ui/webui/speedreader/speedreader_toolbar_ui.cc index 853c2f1faeff..25d66a15848f 100644 --- a/browser/ui/webui/speedreader/speedreader_toolbar_ui.cc +++ b/browser/ui/webui/speedreader/speedreader_toolbar_ui.cc @@ -12,6 +12,7 @@ #include "brave/components/constants/webui_url_constants.h" #include "brave/components/l10n/common/localization_util.h" #include "brave/components/speedreader/common/constants.h" +#include "brave/components/speedreader/common/features.h" #include "brave/components/speedreader/resources/panel/grit/brave_speedreader_toolbar_generated_map.h" #include "build/build_config.h" #include "chrome/browser/profiles/profile.h" @@ -52,6 +53,9 @@ SpeedreaderToolbarUI::SpeedreaderToolbarUI(content::WebUI* web_ui, #else source->AddBoolean("aiChatFeatureEnabled", false); #endif + source->AddBoolean("ttsEnabled", + speedreader::features::IsSpeedreaderEnabled() && + speedreader::kSpeedreaderTTS.Get()); } SpeedreaderToolbarUI::~SpeedreaderToolbarUI() = default; diff --git a/components/speedreader/common/features.cc b/components/speedreader/common/features.cc index 288598b875e0..1ba5ca98db23 100644 --- a/components/speedreader/common/features.cc +++ b/components/speedreader/common/features.cc @@ -18,4 +18,7 @@ BASE_FEATURE(kSpeedreaderFeature, const base::FeatureParam kSpeedreaderMinOutLengthParam{ &kSpeedreaderFeature, "min_out_length", 1000}; +const base::FeatureParam kSpeedreaderTTS{&kSpeedreaderFeature, "tts", + false}; + } // namespace speedreader diff --git a/components/speedreader/common/features.h b/components/speedreader/common/features.h index c7b82e100c36..1e846ce9c365 100644 --- a/components/speedreader/common/features.h +++ b/components/speedreader/common/features.h @@ -12,6 +12,7 @@ namespace speedreader { BASE_DECLARE_FEATURE(kSpeedreaderFeature); extern const base::FeatureParam kSpeedreaderMinOutLengthParam; +extern const base ::FeatureParam kSpeedreaderTTS; } // namespace speedreader #endif // BRAVE_COMPONENTS_SPEEDREADER_COMMON_FEATURES_H_ diff --git a/components/speedreader/resources/panel/components/lists/index.tsx b/components/speedreader/resources/panel/components/lists/index.tsx index 7dff99703235..183d27cb4693 100644 --- a/components/speedreader/resources/panel/components/lists/index.tsx +++ b/components/speedreader/resources/panel/components/lists/index.tsx @@ -36,6 +36,7 @@ const mainButtonsOptions = [ id: 'tts', type: MainButtonType.TextToSpeech, iconName: 'headphones', + hidden: !loadTimeData.getBoolean('ttsEnabled'), title: getLocale('braveReaderModeTextToSpeech') }, { diff --git a/components/speedreader/resources/speedreader-desktop.js b/components/speedreader/resources/speedreader-desktop.js index b2964640439b..1bbc62694b79 100644 --- a/components/speedreader/resources/speedreader-desktop.js +++ b/components/speedreader/resources/speedreader-desktop.js @@ -9,6 +9,14 @@ const readTimeDivId = 'da24e4ef-db57-4b9f-9fa5-548924fc9c32' const metaDataDivId = '3bafd2b4-a87d-4471-8134-7a9cca092000' const contentDivId = '7c08a417-bf02-4241-a55e-ad5b8dc88f69' +const defaultSpeedreaderData = { + showOriginalLinkText: 'View original', + playButtonTitle: 'Play/Pause', + averageWordsPerMinute: 265, + minutesText: 'min. read', + ttsEnabled: false, +} + const $ = (id) => { return document.getElementById(id) } @@ -41,13 +49,6 @@ const calculateReadtime = () => { readTimeDiv.innerText = minutes + ' ' + speedreaderData.minutesText } -const defaultSpeedreaderData = { - showOriginalLinkText: 'View original', - playButtonTitle: 'Play/Pause', - averageWordsPerMinute: 265, - minutesText: 'min. read', -} - const getTextContent = (element) => { if (!element) { return null @@ -60,7 +61,7 @@ const getTextContent = (element) => { } const initTextToSpeak = () => { - if (navigator.userAgentData.mobile) { + if (navigator.userAgentData.mobile || !speedreaderData.ttsEnabled) { return }