#include "chrome/services/speech/speech_recognition_recognizer_impl.h"
#include <algorithm>
#include <string>
#include <utility>
#include "base/containers/flat_map.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/services/speech/soda/proto/soda_api.pb.h"
#include "chrome/services/speech/soda/soda_client.h"
#include "components/soda/constants.h"
#include "google_apis/google_api_keys.h"
#include "media/base/audio_buffer.h"
#include "media/base/audio_sample_types.h"
#include "media/base/audio_timestamp_helper.h"
#include "media/base/limits.h"
#include "media/base/media_switches.h"
#include "media/mojo/common/media_type_converters.h"
#include "media/mojo/mojom/audio_data.mojom.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace speech {
constexpr char kInvalidAudioDataError[] = …;
const char
SpeechRecognitionRecognizerImpl::kCaptionBubbleVisibleHistogramName[] = …;
const char
SpeechRecognitionRecognizerImpl::kCaptionBubbleHiddenHistogramName[] = …;
constexpr char kLiveCaptionLanguageCountHistogramName[] = …;
namespace {
void OnSodaResponse(const char* serialized_proto,
int length,
void* callback_handle) { … }
speech::soda::chrome::ExtendedSodaConfigMsg::RecognitionMode
GetSodaSpeechRecognitionMode(
media::mojom::SpeechRecognitionMode recognition_mode) { … }
}
SpeechRecognitionRecognizerImpl::~SpeechRecognitionRecognizerImpl() { … }
void SpeechRecognitionRecognizerImpl::OnLanguagePackInstalled(
base::flat_map<std::string, base::FilePath> config_paths) { … }
void SpeechRecognitionRecognizerImpl::Create(
mojo::PendingReceiver<media::mojom::SpeechRecognitionRecognizer> receiver,
mojo::PendingRemote<media::mojom::SpeechRecognitionRecognizerClient> remote,
media::mojom::SpeechRecognitionOptionsPtr options,
const base::FilePath& binary_path,
const base::flat_map<std::string, base::FilePath>& config_paths,
const std::string& primary_language_name,
const bool mask_offensive_words,
base::WeakPtr<SpeechRecognitionServiceImpl> speech_recognition_service) { … }
bool SpeechRecognitionRecognizerImpl::IsMultichannelSupported() { … }
void SpeechRecognitionRecognizerImpl::OnRecognitionEvent(
media::SpeechRecognitionResult event) { … }
void SpeechRecognitionRecognizerImpl::
OnSpeechRecognitionRecognitionEventCallback(bool success) { … }
void SpeechRecognitionRecognizerImpl::OnLanguageIdentificationEvent(
const std::string& language,
const media::mojom::ConfidenceLevel confidence_level,
const media::mojom::AsrSwitchResult asr_switch_result) { … }
void SpeechRecognitionRecognizerImpl::OnRecognitionStoppedCallback() { … }
SpeechRecognitionRecognizerImpl::SpeechRecognitionRecognizerImpl(
mojo::PendingRemote<media::mojom::SpeechRecognitionRecognizerClient> remote,
media::mojom::SpeechRecognitionOptionsPtr options,
const base::FilePath& binary_path,
const base::flat_map<std::string, base::FilePath>& config_paths,
const std::string& primary_language_name,
const bool mask_offensive_words,
base::WeakPtr<SpeechRecognitionServiceImpl> speech_recognition_service)
: … { … }
void SpeechRecognitionRecognizerImpl::OnClientHostDisconnected() { … }
void SpeechRecognitionRecognizerImpl::SendAudioToSpeechRecognitionService(
media::mojom::AudioDataS16Ptr buffer) { … }
void SpeechRecognitionRecognizerImpl::OnSpeechRecognitionError() { … }
void SpeechRecognitionRecognizerImpl::MarkDone() { … }
void SpeechRecognitionRecognizerImpl::AddAudio(
media::mojom::AudioDataS16Ptr buffer) { … }
void SpeechRecognitionRecognizerImpl::OnAudioCaptureEnd() { … }
void SpeechRecognitionRecognizerImpl::OnAudioCaptureError() { … }
void SpeechRecognitionRecognizerImpl::
SendAudioToSpeechRecognitionServiceInternal(
media::mojom::AudioDataS16Ptr buffer) { … }
void SpeechRecognitionRecognizerImpl::OnLanguageChanged(
const std::string& language) { … }
void SpeechRecognitionRecognizerImpl::OnMaskOffensiveWordsChanged(
bool mask_offensive_words) { … }
void SpeechRecognitionRecognizerImpl::ResetSodaWithNewLanguage(
std::string language_name,
std::pair<base::FilePath, bool> config_and_exists) { … }
void SpeechRecognitionRecognizerImpl::RecordDuration() { … }
void SpeechRecognitionRecognizerImpl::ResetSoda() { … }
}