-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsoda_recognizer_impl.h
88 lines (69 loc) · 2.91 KB
/
soda_recognizer_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ML_SODA_RECOGNIZER_IMPL_H_
#define ML_SODA_RECOGNIZER_IMPL_H_
#include <string>
#include <vector>
#include <base/callback_forward.h>
#include <base/macros.h>
#include <mojo/public/cpp/bindings/pending_receiver.h>
#include <mojo/public/cpp/bindings/pending_remote.h>
#include <mojo/public/cpp/bindings/receiver.h>
#include <mojo/public/cpp/bindings/shared_remote.h>
#include "ml/mojom/soda.mojom.h"
namespace ml {
// Defined in ml/soda.h . Can't include in header due to fake implementation not
// being able to include that file.
class SodaLibrary;
// The implementation of SodaSpeechRecognizer.
class SodaRecognizerImpl
: public chromeos::machine_learning::mojom::SodaRecognizer {
public:
// Constructs a SodaRecognizerImpl; and set disconnect handler so
// that the SodaRecognizerImpl will be deleted when the mojom
// connection is destroyed.
// Returns whether the object is create successfully.
static bool Create(
chromeos::machine_learning::mojom::SodaConfigPtr spec,
mojo::PendingRemote<chromeos::machine_learning::mojom::SodaClient>
soda_client,
mojo::PendingReceiver<chromeos::machine_learning::mojom::SodaRecognizer>
soda_recognizer);
// Called when mojom connection is destroyed.
~SodaRecognizerImpl();
// mojom::SodaRecognizer::AddAudio:
void AddAudio(const std::vector<uint8_t>& audio) override;
// mojom::SodaRecognizer::Stop:
void Stop() override;
// mojom::SodaRecognizer::Start:
void Start() override;
// mojom::SodaRecognizer::MarkDone:
void MarkDone() override;
// Used to send the event to the client. For the initial version, only accepts
// a string, which is in an unspecified format.
void OnSodaEvent(const std::string& soda_response);
private:
// Creates a SodaRecognizer and Binds to `receiver` inside so that
// Recognize can be called on the other side for a particular soda
// reconition query.
SodaRecognizerImpl(
chromeos::machine_learning::mojom::SodaConfigPtr spec,
mojo::PendingRemote<chromeos::machine_learning::mojom::SodaClient>
soda_client,
mojo::PendingReceiver<chromeos::machine_learning::mojom::SodaRecognizer>
receiver);
SodaRecognizerImpl(const SodaRecognizerImpl&) = delete;
SodaRecognizerImpl& operator=(const SodaRecognizerImpl&) = delete;
bool successfully_loaded_;
// Pointer handle to the internal implementation of SodaRecognizer inside
// the SodaLibrary.
void* recognizer_;
// Not owned: owned by a std::map in soda.h::GetInstanceAt.
SodaLibrary* soda_library_;
mojo::Receiver<chromeos::machine_learning::mojom::SodaRecognizer> receiver_;
mojo::SharedRemote<chromeos::machine_learning::mojom::SodaClient>
client_remote_;
};
} // namespace ml
#endif // ML_SODA_RECOGNIZER_IMPL_H_