libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
transcriptionengine.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
13#include <promeki/namespace.h>
14#include <promeki/audioformat.h>
17#include <promeki/error.h>
18#include <promeki/function.h>
19#include <promeki/list.h>
21#include <promeki/result.h>
22#include <promeki/string.h>
23#include <promeki/transcript.h>
24#include <promeki/uniqueptr.h>
25
26PROMEKI_NAMESPACE_BEGIN
27
28class Frame;
29class MediaConfig;
30
115class TranscriptionEngine {
116 public:
118 using UPtr = UniquePtr<TranscriptionEngine>;
119
121 using Factory = Function<UPtr()>;
122
134 struct BackendRecord {
136 String name;
137
139 String description;
140
151 int weight = BackendWeight::Vendored;
152
166 List<int> supportedInputs;
167
179 List<int> supportedModes;
180
192 Factory factory;
193 };
194
196 virtual ~TranscriptionEngine();
197
199 const String &name() const { return _name; }
200
209 void configure(const MediaConfig &config);
210
223 virtual Error submitFrame(const Frame &frame) = 0;
224
236 virtual Frame receiveFrame() = 0;
237
248 virtual Error flush() = 0;
249
258 virtual Error reset() = 0;
259
261 Error lastError() const { return _lastError; }
262
264 const String &lastErrorMessage() const { return _lastErrorMessage; }
265
266 // ---- Backend registry ----
267
276 static Error registerBackend(BackendRecord record);
277
284 static List<BackendRecord> registeredBackends();
285
290 static Result<BackendRecord> lookupBackend(const String &name);
291
304 static Result<UPtr> create(const String &name, const MediaConfig *config = nullptr);
305
306 // ---- Frame-shaped helpers (public so backends can use them) ----
307
319 static PcmAudioPayload::Ptr selectInputPayload(const Frame &frame, int streamIndex = -1);
320
346 static Frame buildOutputFrame(const Frame &source, const Transcript &transcript);
347
375 static TimeStamp wordTimestamp(const PcmAudioPayload &payload, size_t sampleOffset);
376
377 protected:
378 TranscriptionEngine() = default;
379
381 void setName(String name) { _name = std::move(name); }
382
389 virtual void onConfigure(const MediaConfig &config);
390
397 const MediaConfig &config() const;
398
399 Error _lastError;
400 String _lastErrorMessage;
401
403 void setError(Error err, const String &msg = String());
404
406 void clearError();
407
408 private:
409 UniquePtr<MediaConfig> _stashedConfig;
410 String _name;
411};
412
413PROMEKI_NAMESPACE_END
414
415#endif // PROMEKI_ENABLE_PROAV