Skip to content

Commit

Permalink
Added ttsEnabled feature param.
Browse files Browse the repository at this point in the history
  • Loading branch information
boocmp committed Sep 15, 2023
1 parent 33b8e04 commit a3b89ea
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions browser/speedreader/speedreader_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ namespace speedreader {
std::u16string GetSpeedreaderData(
std::initializer_list<std::pair<base::StringPiece, int>> 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
Expand Down
4 changes: 4 additions & 0 deletions browser/ui/webui/speedreader/speedreader_toolbar_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions components/speedreader/common/features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ BASE_FEATURE(kSpeedreaderFeature,
const base::FeatureParam<int> kSpeedreaderMinOutLengthParam{
&kSpeedreaderFeature, "min_out_length", 1000};

const base::FeatureParam<bool> kSpeedreaderTTS{&kSpeedreaderFeature, "tts",
false};

} // namespace speedreader
1 change: 1 addition & 0 deletions components/speedreader/common/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace speedreader {
BASE_DECLARE_FEATURE(kSpeedreaderFeature);
extern const base::FeatureParam<int> kSpeedreaderMinOutLengthParam;
extern const base ::FeatureParam<bool> kSpeedreaderTTS;
} // namespace speedreader

#endif // BRAVE_COMPONENTS_SPEEDREADER_COMMON_FEATURES_H_
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const mainButtonsOptions = [
id: 'tts',
type: MainButtonType.TextToSpeech,
iconName: 'headphones',
hidden: !loadTimeData.getBoolean('ttsEnabled'),
title: getLocale('braveReaderModeTextToSpeech')
},
{
Expand Down
17 changes: 9 additions & 8 deletions components/speedreader/resources/speedreader-desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -60,7 +61,7 @@ const getTextContent = (element) => {
}

const initTextToSpeak = () => {
if (navigator.userAgentData.mobile) {
if (navigator.userAgentData.mobile || !speedreaderData.ttsEnabled) {
return
}

Expand Down

0 comments on commit a3b89ea

Please sign in to comment.