Commit f857cc1f authored by Abigail Klein's avatar Abigail Klein Committed by Commit Bot

[Live Caption] Remove "Detecting speech..." message.

The UI showed a "Detecting speech..." message in the caption bubble as
soon as audio started playing to alert the user that Live Caption was
beginning to detect speech. This caused a bug in which the caption
bubble appeared when audio that does not contain speech began to play,
such as short pings. The team decided to remove the "Detecting
speech..." message from the UI as a result.

This CL removes the text from the UI and removes the
OnSpeechRecognitionReady message sent from the
ChromeSpeechRecognitionClient to the caption UI, which is no longer
necessary. It also introduces a new accessible label for the caption
bubble, which is necessary so that the bubble can set the AXNodeData
name when the bubble label does not contain any text.

Bug: 1055150, 1114232
Change-Id: I85fdab48a34176e67733f4540ec534c6e7e0109f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2368464Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Cr-Commit-Position: refs/heads/master@{#801097}
parent 086209a8
...@@ -9319,9 +9319,6 @@ Please help our engineers fix this problem. Tell us what happened right before y ...@@ -9319,9 +9319,6 @@ Please help our engineers fix this problem. Tell us what happened right before y
</message> </message>
<!-- Live caption. --> <!-- Live caption. -->
<message name="IDS_LIVE_CAPTION_BUBBLE_WAIT_TEXT" desc="Text displayed in the Live Caption bubble when it is waiting for captions from the speech service">
Detecting speech...
</message>
<message name="IDS_LIVE_CAPTION_BUBBLE_CLOSE" desc="Tooltip for the Live Caption close button"> <message name="IDS_LIVE_CAPTION_BUBBLE_CLOSE" desc="Tooltip for the Live Caption close button">
Turn off Live Caption for now Turn off Live Caption for now
</message> </message>
...@@ -9334,6 +9331,9 @@ Please help our engineers fix this problem. Tell us what happened right before y ...@@ -9334,6 +9331,9 @@ Please help our engineers fix this problem. Tell us what happened right before y
<message name="IDS_LIVE_CAPTION_BUBBLE_ERROR" desc="Error message for the Live Caption bubble when Live Captions are unavailable."> <message name="IDS_LIVE_CAPTION_BUBBLE_ERROR" desc="Error message for the Live Caption bubble when Live Captions are unavailable.">
Live Caption is not available right now Live Caption is not available right now
</message> </message>
<message name="IDS_LIVE_CAPTION_BUBBLE_ACCESSIBLE_NAME" desc="Label of the Live Caption bubble for accessibility.">
Live Caption
</message>
<!-- Caret browsing. --> <!-- Caret browsing. -->
<if expr="not chromeos"> <if expr="not chromeos">
......
5230947232906708b0262c0f093cbe3e7617b65e
\ No newline at end of file
879ad09cc2870b9ee0ebac0bfc2e31338adf2144
\ No newline at end of file
...@@ -182,15 +182,6 @@ void CaptionController::OnBrowserRemoved(Browser* browser) { ...@@ -182,15 +182,6 @@ void CaptionController::OnBrowserRemoved(Browser* browser) {
caption_bubble_controllers_.erase(browser); caption_bubble_controllers_.erase(browser);
} }
bool CaptionController::OnSpeechRecognitionReady(
content::WebContents* web_contents) {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (!browser || !caption_bubble_controllers_.count(browser))
return false;
return caption_bubble_controllers_[browser]->OnSpeechRecognitionReady(
web_contents);
}
bool CaptionController::DispatchTranscription( bool CaptionController::DispatchTranscription(
content::WebContents* web_contents, content::WebContents* web_contents,
const chrome::mojom::TranscriptionResultPtr& transcription_result) { const chrome::mojom::TranscriptionResultPtr& transcription_result) {
......
...@@ -64,12 +64,6 @@ class CaptionController : public BrowserListObserver, public KeyedService { ...@@ -64,12 +64,6 @@ class CaptionController : public BrowserListObserver, public KeyedService {
void Init(); void Init();
// Alerts the CaptionBubbleController that belongs to the appropriate browser
// that speech recognition is ready to start for the given web contents.
// Returns whether this message was routed successfully. Transcriptions will
// not proceed if this returns false.
bool OnSpeechRecognitionReady(content::WebContents* web_contents);
// Routes a transcription to the CaptionBubbleController that belongs to the // Routes a transcription to the CaptionBubbleController that belongs to the
// appropriate browser. Returns whether the transcription result was routed // appropriate browser. Returns whether the transcription result was routed
// successfully. Transcriptions will halt if this returns false. // successfully. Transcriptions will halt if this returns false.
......
...@@ -34,22 +34,6 @@ CaptionHostImpl::CaptionHostImpl(content::RenderFrameHost* frame_host) ...@@ -34,22 +34,6 @@ CaptionHostImpl::CaptionHostImpl(content::RenderFrameHost* frame_host)
CaptionHostImpl::~CaptionHostImpl() = default; CaptionHostImpl::~CaptionHostImpl() = default;
void CaptionHostImpl::OnSpeechRecognitionReady(
OnSpeechRecognitionReadyCallback reply) {
content::WebContents* web_contents = GetWebContents();
if (!web_contents) {
std::move(reply).Run(false);
return;
}
CaptionController* caption_controller = GetCaptionController(web_contents);
if (!caption_controller) {
std::move(reply).Run(false);
return;
}
std::move(reply).Run(
caption_controller->OnSpeechRecognitionReady(web_contents));
}
void CaptionHostImpl::OnTranscription( void CaptionHostImpl::OnTranscription(
chrome::mojom::TranscriptionResultPtr transcription_result, chrome::mojom::TranscriptionResultPtr transcription_result,
OnTranscriptionCallback reply) { OnTranscriptionCallback reply) {
......
...@@ -39,8 +39,6 @@ class CaptionHostImpl : public chrome::mojom::CaptionHost, ...@@ -39,8 +39,6 @@ class CaptionHostImpl : public chrome::mojom::CaptionHost,
mojo::PendingReceiver<chrome::mojom::CaptionHost> receiver); mojo::PendingReceiver<chrome::mojom::CaptionHost> receiver);
// chrome::mojom::CaptionHost: // chrome::mojom::CaptionHost:
void OnSpeechRecognitionReady(
OnSpeechRecognitionReadyCallback reply) override;
void OnTranscription( void OnTranscription(
chrome::mojom::TranscriptionResultPtr transcription_result, chrome::mojom::TranscriptionResultPtr transcription_result,
OnTranscriptionCallback reply) override; OnTranscriptionCallback reply) override;
......
...@@ -37,10 +37,6 @@ class CaptionBubbleController { ...@@ -37,10 +37,6 @@ class CaptionBubbleController {
static std::unique_ptr<CaptionBubbleController> Create(Browser* browser); static std::unique_ptr<CaptionBubbleController> Create(Browser* browser);
// Called when speech recognition is ready to start for the given web
// contents.
virtual bool OnSpeechRecognitionReady(content::WebContents* web_contents) = 0;
// Called when a transcription is received from the service. Returns whether // Called when a transcription is received from the service. Returns whether
// the transcription result was set on the caption bubble successfully. // the transcription result was set on the caption bubble successfully.
// Transcriptions will halt if this returns false. // Transcriptions will halt if this returns false.
......
...@@ -324,13 +324,6 @@ void CaptionBubble::Init() { ...@@ -324,13 +324,6 @@ void CaptionBubble::Init() {
// set the truncate_length to 0 to ensure that it never truncates. // set the truncate_length to 0 to ensure that it never truncates.
label->SetTruncateLength(0); label->SetTruncateLength(0);
auto wait_text = std::make_unique<views::Label>();
wait_text->SetEnabledColor(gfx::kGoogleGrey500);
wait_text->SetBackgroundColor(SK_ColorTRANSPARENT);
wait_text->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
wait_text->SetText(
l10n_util::GetStringUTF16(IDS_LIVE_CAPTION_BUBBLE_WAIT_TEXT));
auto error_text = std::make_unique<views::Label>(); auto error_text = std::make_unique<views::Label>();
error_text->SetEnabledColor(SK_ColorWHITE); error_text->SetEnabledColor(SK_ColorWHITE);
error_text->SetBackgroundColor(SK_ColorTRANSPARENT); error_text->SetBackgroundColor(SK_ColorTRANSPARENT);
...@@ -360,7 +353,6 @@ void CaptionBubble::Init() { ...@@ -360,7 +353,6 @@ void CaptionBubble::Init() {
auto close_button = BuildImageButton(vector_icons::kCloseRoundedIcon, auto close_button = BuildImageButton(vector_icons::kCloseRoundedIcon,
IDS_LIVE_CAPTION_BUBBLE_CLOSE); IDS_LIVE_CAPTION_BUBBLE_CLOSE);
wait_text_ = content_container->AddChildView(std::move(wait_text));
label_ = content_container->AddChildView(std::move(label)); label_ = content_container->AddChildView(std::move(label));
error_icon_ = error_message->AddChildView(std::move(error_icon)); error_icon_ = error_message->AddChildView(std::move(error_icon));
...@@ -470,14 +462,16 @@ void CaptionBubble::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -470,14 +462,16 @@ void CaptionBubble::GetAccessibleNodeData(ui::AXNodeData* node_data) {
if (model_ && model_->HasError()) { if (model_ && model_->HasError()) {
node_data->SetName(error_text_->GetText()); node_data->SetName(error_text_->GetText());
node_data->SetNameFrom(ax::mojom::NameFrom::kContents); node_data->SetNameFrom(ax::mojom::NameFrom::kContents);
} else if (label_->GetText().size()) { } else if (model_ && !model_->GetFullText().empty()) {
node_data->SetName(label_->GetText()); node_data->SetName(model_->GetFullText());
node_data->SetNameFrom(ax::mojom::NameFrom::kContents); node_data->SetNameFrom(ax::mojom::NameFrom::kContents);
} else { } else {
node_data->SetName(wait_text_->GetText()); node_data->SetName(
l10n_util::GetStringUTF16(IDS_LIVE_CAPTION_BUBBLE_ACCESSIBLE_NAME));
node_data->SetNameFrom(ax::mojom::NameFrom::kContents); node_data->SetNameFrom(ax::mojom::NameFrom::kContents);
} }
node_data->SetDescription(wait_text_->GetText()); node_data->SetDescription(
l10n_util::GetStringUTF16(IDS_LIVE_CAPTION_BUBBLE_ACCESSIBLE_NAME));
node_data->role = ax::mojom::Role::kCaption; node_data->role = ax::mojom::Role::kCaption;
} }
...@@ -526,7 +520,7 @@ void CaptionBubble::SetModel(CaptionBubbleModel* model) { ...@@ -526,7 +520,7 @@ void CaptionBubble::SetModel(CaptionBubbleModel* model) {
void CaptionBubble::OnTextChanged() { void CaptionBubble::OnTextChanged() {
DCHECK(model_); DCHECK(model_);
label_->SetText(base::UTF8ToUTF16(model_->GetFullText())); label_->SetText(base::UTF8ToUTF16(model_->GetFullText()));
UpdateBubbleAndWaitTextVisibility(); UpdateBubbleVisibility();
} }
void CaptionBubble::OnErrorChanged() { void CaptionBubble::OnErrorChanged() {
...@@ -539,19 +533,6 @@ void CaptionBubble::OnErrorChanged() { ...@@ -539,19 +533,6 @@ void CaptionBubble::OnErrorChanged() {
Redraw(); Redraw();
} }
void CaptionBubble::OnReadyChanged() {
DCHECK(model_);
// There is a bug in RenderText in which the label text must not be empty when
// it is displayed, or otherwise subsequent calculation of the number of lines
// (CaptionBubble::GetNumLinesInLabel) will be incorrect. The label text here
// is set to a space character.
// TODO(1055150): Fix the bug in RenderText and then remove this workaround.
if (model_->IsReady()) {
label_->SetText(base::ASCIIToUTF16("\u0020"));
UpdateBubbleAndWaitTextVisibility();
}
}
void CaptionBubble::OnIsExpandedChanged() { void CaptionBubble::OnIsExpandedChanged() {
expand_button_->SetVisible(!is_expanded_); expand_button_->SetVisible(!is_expanded_);
collapse_button_->SetVisible(is_expanded_); collapse_button_->SetVisible(is_expanded_);
...@@ -561,14 +542,6 @@ void CaptionBubble::OnIsExpandedChanged() { ...@@ -561,14 +542,6 @@ void CaptionBubble::OnIsExpandedChanged() {
Redraw(); Redraw();
} }
void CaptionBubble::UpdateBubbleAndWaitTextVisibility() {
// Show the wait text if there is room for it and no error.
wait_text_->SetVisible(model_ && !model_->HasError() &&
GetNumLinesInLabel() <
static_cast<size_t>(GetNumLinesVisible()));
UpdateBubbleVisibility();
}
void CaptionBubble::UpdateBubbleVisibility() { void CaptionBubble::UpdateBubbleVisibility() {
DCHECK(GetWidget()); DCHECK(GetWidget());
if (!model_) { if (!model_) {
...@@ -579,14 +552,14 @@ void CaptionBubble::UpdateBubbleVisibility() { ...@@ -579,14 +552,14 @@ void CaptionBubble::UpdateBubbleVisibility() {
// Hide the widget if there is no room for it or the model is closed. // Hide the widget if there is no room for it or the model is closed.
if (GetWidget()->IsVisible()) if (GetWidget()->IsVisible())
GetWidget()->Hide(); GetWidget()->Hide();
} else if (model_->IsReady() || model_->HasError()) { } else if (!model_->GetFullText().empty() || model_->HasError()) {
// Show the widget if it is ready to receive transcriptions or it has an // Show the widget if it has text or an error to display. Only show the
// error to display. Only show the widget if it isn't already visible. // widget if it isn't already visible. Always calling Widget::Show() will
// Always calling Widget::Show() will mean the widget gets focus each time. // mean the widget gets focus each time.
if (!GetWidget()->IsVisible()) if (!GetWidget()->IsVisible())
GetWidget()->Show(); GetWidget()->Show();
} else if (GetWidget()->IsVisible()) { } else if (GetWidget()->IsVisible()) {
// Not ready and no error. Hide it. // No text and no error. Hide it.
GetWidget()->Hide(); GetWidget()->Hide();
} }
} }
...@@ -630,11 +603,9 @@ void CaptionBubble::UpdateTextSize() { ...@@ -630,11 +603,9 @@ void CaptionBubble::UpdateTextSize() {
gfx::Font::FontStyle::NORMAL, kFontSizePx * textScaleFactor, gfx::Font::FontStyle::NORMAL, kFontSizePx * textScaleFactor,
gfx::Font::Weight::NORMAL); gfx::Font::Weight::NORMAL);
label_->SetFontList(font_list); label_->SetFontList(font_list);
wait_text_->SetFontList(font_list);
error_text_->SetFontList(font_list); error_text_->SetFontList(font_list);
label_->SetLineHeight(kLineHeightDip * textScaleFactor); label_->SetLineHeight(kLineHeightDip * textScaleFactor);
wait_text_->SetLineHeight(kLineHeightDip * textScaleFactor);
error_text_->SetLineHeight(kLineHeightDip * textScaleFactor); error_text_->SetLineHeight(kLineHeightDip * textScaleFactor);
error_icon_->SetImageSize(gfx::Size(kErrorImageSizeDip * textScaleFactor, error_icon_->SetImageSize(gfx::Size(kErrorImageSizeDip * textScaleFactor,
kErrorImageSizeDip * textScaleFactor)); kErrorImageSizeDip * textScaleFactor));
...@@ -646,12 +617,8 @@ void CaptionBubble::UpdateContentSize() { ...@@ -646,12 +617,8 @@ void CaptionBubble::UpdateContentSize() {
(model_ && model_->HasError()) (model_ && model_->HasError())
? kLineHeightDip * text_scale_factor ? kLineHeightDip * text_scale_factor
: kLineHeightDip * GetNumLinesVisible() * text_scale_factor; : kLineHeightDip * GetNumLinesVisible() * text_scale_factor;
// The wait text takes up 1 line.
int label_height = wait_text_->GetVisible()
? content_height - kLineHeightDip * text_scale_factor
: content_height;
label_->SetPreferredSize( label_->SetPreferredSize(
gfx::Size(kMaxWidthDip - kSidePaddingDip, label_height)); gfx::Size(kMaxWidthDip - kSidePaddingDip, content_height));
content_container_->SetPreferredSize(gfx::Size(kMaxWidthDip, content_height)); content_container_->SetPreferredSize(gfx::Size(kMaxWidthDip, content_height));
SetPreferredSize( SetPreferredSize(
gfx::Size(kMaxWidthDip, content_height + gfx::Size(kMaxWidthDip, content_height +
...@@ -660,7 +627,7 @@ void CaptionBubble::UpdateContentSize() { ...@@ -660,7 +627,7 @@ void CaptionBubble::UpdateContentSize() {
} }
void CaptionBubble::Redraw() { void CaptionBubble::Redraw() {
UpdateBubbleAndWaitTextVisibility(); UpdateBubbleVisibility();
UpdateContentSize(); UpdateContentSize();
SizeToContents(); SizeToContents();
} }
......
...@@ -105,16 +105,10 @@ class CaptionBubble : public views::BubbleDialogDelegateView, ...@@ -105,16 +105,10 @@ class CaptionBubble : public views::BubbleDialogDelegateView,
// the model has an error, otherwise displays the latest text. // the model has an error, otherwise displays the latest text.
void OnErrorChanged(); void OnErrorChanged();
// Called by the CaptionBubbleModel to notify this object that the model's
// on ready state has changed. Makes the caption bubble become visible and
// show the wait text.
void OnReadyChanged();
// Called when the caption bubble expanded state has changed. Changes the // Called when the caption bubble expanded state has changed. Changes the
// number of lines displayed. // number of lines displayed.
void OnIsExpandedChanged(); void OnIsExpandedChanged();
void UpdateBubbleAndWaitTextVisibility();
// The caption bubble manages its own visibility based on whether there's // The caption bubble manages its own visibility based on whether there's
// space for it to be shown, and if it has an error or text to display. // space for it to be shown, and if it has an error or text to display.
void UpdateBubbleVisibility(); void UpdateBubbleVisibility();
...@@ -129,7 +123,6 @@ class CaptionBubble : public views::BubbleDialogDelegateView, ...@@ -129,7 +123,6 @@ class CaptionBubble : public views::BubbleDialogDelegateView,
// Unowned. Owned by views hierarchy. // Unowned. Owned by views hierarchy.
views::Label* label_; views::Label* label_;
views::Label* wait_text_;
views::Label* error_text_; views::Label* error_text_;
views::ImageView* error_icon_; views::ImageView* error_icon_;
views::View* error_message_; views::View* error_message_;
......
...@@ -69,18 +69,6 @@ void CaptionBubbleControllerViews::OnCaptionBubbleDestroyed() { ...@@ -69,18 +69,6 @@ void CaptionBubbleControllerViews::OnCaptionBubbleDestroyed() {
browser_ = nullptr; browser_ = nullptr;
} }
bool CaptionBubbleControllerViews::OnSpeechRecognitionReady(
content::WebContents* web_contents) {
if (!caption_bubble_ || !caption_bubble_models_.count(web_contents) ||
caption_bubble_models_[web_contents]->IsClosed())
return false;
CaptionBubbleModel* caption_bubble_model =
caption_bubble_models_[web_contents].get();
caption_bubble_model->OnReady();
return true;
}
bool CaptionBubbleControllerViews::OnTranscription( bool CaptionBubbleControllerViews::OnTranscription(
const chrome::mojom::TranscriptionResultPtr& transcription_result, const chrome::mojom::TranscriptionResultPtr& transcription_result,
content::WebContents* web_contents) { content::WebContents* web_contents) {
......
...@@ -38,10 +38,6 @@ class CaptionBubbleControllerViews : public CaptionBubbleController, ...@@ -38,10 +38,6 @@ class CaptionBubbleControllerViews : public CaptionBubbleController,
CaptionBubbleControllerViews& operator=(const CaptionBubbleControllerViews&) = CaptionBubbleControllerViews& operator=(const CaptionBubbleControllerViews&) =
delete; delete;
// Called when speech recognition is ready to start for the given web
// contents.
bool OnSpeechRecognitionReady(content::WebContents* web_contents) override;
// Called when a transcription is received from the service. Returns whether // Called when a transcription is received from the service. Returns whether
// the transcription result was set on the caption bubble successfully. // the transcription result was set on the caption bubble successfully.
// Transcriptions will halt if this returns false. // Transcriptions will halt if this returns false.
......
...@@ -29,7 +29,6 @@ void CaptionBubbleModel::SetObserver(CaptionBubble* observer) { ...@@ -29,7 +29,6 @@ void CaptionBubbleModel::SetObserver(CaptionBubble* observer) {
return; return;
observer_ = observer; observer_ = observer;
if (observer_) { if (observer_) {
observer_->OnReadyChanged();
observer_->OnTextChanged(); observer_->OnTextChanged();
observer_->OnErrorChanged(); observer_->OnErrorChanged();
} }
...@@ -53,23 +52,9 @@ void CaptionBubbleModel::Close() { ...@@ -53,23 +52,9 @@ void CaptionBubbleModel::Close() {
final_text_.clear(); final_text_.clear();
partial_text_.clear(); partial_text_.clear();
is_closed_ = true; is_closed_ = true;
is_ready_ = false;
OnTextChanged(); OnTextChanged();
} }
void CaptionBubbleModel::OnReady() {
final_text_.clear();
partial_text_.clear();
is_ready_ = true;
// The label text must not be empty when it is displayed, so there is a
// special OnReadyChanged() function in the CaptionBubble that handles the
// on_ready state change.
// TODO(1055150): Fix the bug in RenderText and then change this to
// OnTextChanged().
if (observer_)
observer_->OnReadyChanged();
}
void CaptionBubbleModel::OnError() { void CaptionBubbleModel::OnError() {
has_error_ = true; has_error_ = true;
if (observer_) if (observer_)
...@@ -85,10 +70,8 @@ void CaptionBubbleModel::DidFinishNavigation( ...@@ -85,10 +70,8 @@ void CaptionBubbleModel::DidFinishNavigation(
final_text_.clear(); final_text_.clear();
partial_text_.clear(); partial_text_.clear();
is_closed_ = false; is_closed_ = false;
is_ready_ = false;
has_error_ = false; has_error_ = false;
if (observer_) { if (observer_) {
observer_->OnReadyChanged();
observer_->OnTextChanged(); observer_->OnTextChanged();
observer_->OnErrorChanged(); observer_->OnErrorChanged();
} }
......
...@@ -57,10 +57,7 @@ class CaptionBubbleModel : public content::WebContentsObserver { ...@@ -57,10 +57,7 @@ class CaptionBubbleModel : public content::WebContentsObserver {
// observer. // observer.
void Close(); void Close();
void OnReady();
bool IsClosed() const { return is_closed_; } bool IsClosed() const { return is_closed_; }
bool IsReady() const { return is_ready_; }
bool HasError() const { return has_error_; } bool HasError() const { return has_error_; }
std::string GetFullText() const { return final_text_ + partial_text_; } std::string GetFullText() const { return final_text_ + partial_text_; }
...@@ -79,9 +76,6 @@ class CaptionBubbleModel : public content::WebContentsObserver { ...@@ -79,9 +76,6 @@ class CaptionBubbleModel : public content::WebContentsObserver {
// Whether the bubble has been closed by the user. // Whether the bubble has been closed by the user.
bool is_closed_ = false; bool is_closed_ = false;
// Whether bubble is ready to receive transcriptions.
bool is_ready_ = false;
// Whether an error should be displayed one the bubble. // Whether an error should be displayed one the bubble.
bool has_error_ = false; bool has_error_ = false;
......
...@@ -397,11 +397,9 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, F6CyclesThroughCaptionBubbleToo) { ...@@ -397,11 +397,9 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, F6CyclesThroughCaptionBubbleToo) {
caption_controller->GetCaptionBubbleControllerForBrowser(browser())); caption_controller->GetCaptionBubbleControllerForBrowser(browser()));
EXPECT_FALSE(bubble_controller->GetFocusableCaptionBubble()); EXPECT_FALSE(bubble_controller->GetFocusableCaptionBubble());
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
caption_controller->OnSpeechRecognitionReady(contents);
caption_controller->DispatchTranscription( caption_controller->DispatchTranscription(
contents, chrome::mojom::TranscriptionResult::New("Hello, world", false)); browser()->tab_strip_model()->GetActiveWebContents(),
chrome::mojom::TranscriptionResult::New("Hello, world", false));
// Now the caption bubble exists but is not focused. // Now the caption bubble exists but is not focused.
views::View* bubble = bubble_controller->GetFocusableCaptionBubble(); views::View* bubble = bubble_controller->GetFocusableCaptionBubble();
EXPECT_TRUE(bubble); EXPECT_TRUE(bubble);
......
...@@ -7,9 +7,6 @@ module chrome.mojom; ...@@ -7,9 +7,6 @@ module chrome.mojom;
// Browser process interface exposed to the renderer for communication about // Browser process interface exposed to the renderer for communication about
// the Live Caption feature. // the Live Caption feature.
interface CaptionHost { interface CaptionHost {
// Called when speech recognition service is ready to send transcriptions.
OnSpeechRecognitionReady() => (bool success);
// Called when the speech recognition client receives a transcription from the // Called when the speech recognition client receives a transcription from the
// speech service. Returns whether the transcription result was received // speech service. Returns whether the transcription result was received
// successfully. Transcriptions will halt if this returns false. // successfully. Transcriptions will halt if this returns false.
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/renderer/media/chrome_speech_recognition_client.h" #include "chrome/renderer/media/chrome_speech_recognition_client.h"
#include <utility> #include <utility>
#include <vector>
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
...@@ -65,6 +64,7 @@ void ChromeSpeechRecognitionClient::OnRecognizerBound( ...@@ -65,6 +64,7 @@ void ChromeSpeechRecognitionClient::OnRecognizerBound(
bool is_multichannel_supported) { bool is_multichannel_supported) {
is_multichannel_supported_ = is_multichannel_supported; is_multichannel_supported_ = is_multichannel_supported;
is_recognizer_bound_ = true; is_recognizer_bound_ = true;
if (on_ready_callback_) if (on_ready_callback_)
std::move(on_ready_callback_).Run(); std::move(on_ready_callback_).Run();
} }
...@@ -118,11 +118,11 @@ void ChromeSpeechRecognitionClient::OnSpeechRecognitionRecognitionEvent( ...@@ -118,11 +118,11 @@ void ChromeSpeechRecognitionClient::OnSpeechRecognitionRecognitionEvent(
caption_host_->OnTranscription( caption_host_->OnTranscription(
chrome::mojom::TranscriptionResult::New(result->transcription, chrome::mojom::TranscriptionResult::New(result->transcription,
result->is_final), result->is_final),
base::BindOnce(&ChromeSpeechRecognitionClient::OnBrowserCallback, base::BindOnce(&ChromeSpeechRecognitionClient::OnTranscriptionCallback,
base::Unretained(this))); base::Unretained(this)));
} }
void ChromeSpeechRecognitionClient::OnBrowserCallback(bool success) { void ChromeSpeechRecognitionClient::OnTranscriptionCallback(bool success) {
is_browser_requesting_transcription_ = success; is_browser_requesting_transcription_ = success;
} }
...@@ -161,17 +161,6 @@ void ChromeSpeechRecognitionClient::SendAudioToSpeechRecognitionService( ...@@ -161,17 +161,6 @@ void ChromeSpeechRecognitionClient::SendAudioToSpeechRecognitionService(
if (IsSpeechRecognitionAvailable()) { if (IsSpeechRecognitionAvailable()) {
speech_recognition_recognizer_->SendAudioToSpeechRecognitionService( speech_recognition_recognizer_->SendAudioToSpeechRecognitionService(
std::move(audio_data)); std::move(audio_data));
// When the speech recognition client receives speech, it alerts the
// live caption host in the browser that it is ready so that the UI can
// display a message. This happens at the time of playing the video and not
// at the time of construction of this object.
if (!on_ready_message_sent_to_caption_host_) {
caption_host_->OnSpeechRecognitionReady(
base::BindOnce(&ChromeSpeechRecognitionClient::OnBrowserCallback,
base::Unretained(this)));
on_ready_message_sent_to_caption_host_ = true;
}
} }
} }
......
...@@ -65,8 +65,8 @@ class ChromeSpeechRecognitionClient ...@@ -65,8 +65,8 @@ class ChromeSpeechRecognitionClient
media::mojom::AudioDataS16Ptr ConvertToAudioDataS16( media::mojom::AudioDataS16Ptr ConvertToAudioDataS16(
scoped_refptr<media::AudioBuffer> buffer); scoped_refptr<media::AudioBuffer> buffer);
// Called as a response to sending a message to the browser. // Called as a response to sending a transcription to the browser.
void OnBrowserCallback(bool success); void OnTranscriptionCallback(bool success);
media::mojom::AudioDataS16Ptr ConvertToAudioDataS16( media::mojom::AudioDataS16Ptr ConvertToAudioDataS16(
std::unique_ptr<media::AudioBus> audio_bus, std::unique_ptr<media::AudioBus> audio_bus,
...@@ -116,9 +116,6 @@ class ChromeSpeechRecognitionClient ...@@ -116,9 +116,6 @@ class ChromeSpeechRecognitionClient
bool is_recognizer_bound_ = false; bool is_recognizer_bound_ = false;
// Whether or not the on ready message has been sent to the caption host.
bool on_ready_message_sent_to_caption_host_ = false;
// The temporary audio bus used to mix multichannel audio into a single // The temporary audio bus used to mix multichannel audio into a single
// channel. // channel.
std::unique_ptr<media::AudioBus> monaural_audio_bus_; std::unique_ptr<media::AudioBus> monaural_audio_bus_;
......
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