blob: b78ef1ad5479c3f115b18b58347d9fa743e9ca4c [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/weak_ptr.h"
#include "build/branding_buildflags.h"
#include "chrome/services/soda/buildflags.h"
#include "media/mojo/mojom/soda_service.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace soda {
class SodaClient;
class SodaRecognizerImpl : public media::mojom::SodaRecognizer {
using OnRecognitionEventCallback =
base::RepeatingCallback<void(const std::string& result)>;
~SodaRecognizerImpl() override;
static void Create(
mojo::PendingReceiver<media::mojom::SodaRecognizer> receiver,
mojo::PendingRemote<media::mojom::SodaRecognizerClient> remote);
OnRecognitionEventCallback recognition_event_callback() const {
return recognition_event_callback_;
explicit SodaRecognizerImpl(
mojo::PendingRemote<media::mojom::SodaRecognizerClient> remote);
// Convert the audio buffer into the appropriate format and feed the raw audio
// into the SODA instance.
void SendAudioToSoda(media::mojom::AudioDataS16Ptr buffer) final;
// Return the transcribed audio from the recognition event back to the caller
// via the recognition event client.
void OnRecognitionEvent(const std::string& result);
// The remote endpoint for the mojo pipe used to return transcribed audio from
// the SODA service back to the renderer.
mojo::Remote<media::mojom::SodaRecognizerClient> client_remote_;
std::unique_ptr<SodaClient> soda_client_;
// The callback that is eventually executed on a speech recognition event
// which passes the transcribed audio back to the caller via the SODA
// recognition event client remote.
OnRecognitionEventCallback recognition_event_callback_;
base::WeakPtrFactory<SodaRecognizerImpl> weak_factory_{this};
} // namespace soda