#include "chrome/browser/accessibility/live_caption/live_caption_speech_recognition_host.h"
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/callback_forward.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/accessibility/caption_bubble_context_browser.h"
#include "chrome/browser/accessibility/live_caption/live_caption_controller_factory.h"
#include "chrome/browser/accessibility/live_translate_controller_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "components/live_caption/greedy_text_stabilizer.h"
#include "components/live_caption/live_caption_controller.h"
#include "components/live_caption/live_translate_controller.h"
#include "components/live_caption/pref_names.h"
#include "components/live_caption/translation_util.h"
#include "components/live_caption/views/caption_bubble_model.h"
#include "components/prefs/pref_service.h"
#include "components/soda/soda_installer.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "media/base/media_switches.h"
#include "media/mojo/mojom/speech_recognition_result.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/icu/source/common/unicode/brkiter.h"
#include "third_party/icu/source/common/unicode/unistr.h"
#include "third_party/icu/source/common/unicode/uscript.h"
#include "third_party/re2/src/re2/re2.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
static constexpr int kMinTokenFrequency = …;
static constexpr int kWaitKValue = …;
static constexpr int kLanguageIdentificationEventCountThreshold = …;
std::string RemoveLastKWords(const std::string& input) { … }
bool IsLanguageInstallable(const std::string& language_code) { … }
}
namespace captions {
void LiveCaptionSpeechRecognitionHost::Create(
content::RenderFrameHost* frame_host,
mojo::PendingReceiver<media::mojom::SpeechRecognitionRecognizerClient>
receiver) { … }
LiveCaptionSpeechRecognitionHost::LiveCaptionSpeechRecognitionHost(
content::RenderFrameHost& frame_host,
mojo::PendingReceiver<media::mojom::SpeechRecognitionRecognizerClient>
receiver)
: … { … }
LiveCaptionSpeechRecognitionHost::~LiveCaptionSpeechRecognitionHost() { … }
void LiveCaptionSpeechRecognitionHost::OnSpeechRecognitionRecognitionEvent(
const media::SpeechRecognitionResult& result,
OnSpeechRecognitionRecognitionEventCallback reply) { … }
void LiveCaptionSpeechRecognitionHost::OnLanguageIdentificationEvent(
media::mojom::LanguageIdentificationEventPtr event) { … }
void LiveCaptionSpeechRecognitionHost::OnSpeechRecognitionError() { … }
void LiveCaptionSpeechRecognitionHost::OnSpeechRecognitionStopped() { … }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS)
void LiveCaptionSpeechRecognitionHost::MediaEffectivelyFullscreenChanged(
bool is_fullscreen) {
LiveCaptionController* live_caption_controller = GetLiveCaptionController();
if (live_caption_controller)
live_caption_controller->OnToggleFullscreen(context_.get());
}
#endif
void LiveCaptionSpeechRecognitionHost::OnTranslationCallback(
const std::string& cached_translation,
const std::string& original_transcription,
const std::string& source_language,
const std::string& target_language,
bool is_final,
const std::string& result) { … }
content::WebContents* LiveCaptionSpeechRecognitionHost::GetWebContents() { … }
LiveCaptionController*
LiveCaptionSpeechRecognitionHost::GetLiveCaptionController() { … }
LiveTranslateController*
LiveCaptionSpeechRecognitionHost::GetLiveTranslateController() { … }
std::string LiveCaptionSpeechRecognitionHost::GetTextForDispatch(
const std::string& input_text,
bool is_final) { … }
}