KTextAddons

voskspeechtotextdevice.h
1/*
2 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "config-vosk-plugin.h"
10#include "libvoskspeechtotext_export.h"
11#include <QIODevice>
12
13#if HAVE_VOSK_API_SUPPORT
14class VoskModel;
15class VoskRecognizer;
16#endif
17
18class LIBVOSKSPEECHTOTEXT_EXPORT VoskSpeechToTextDevice : public QIODevice
19{
20 Q_OBJECT
21public:
22 struct LIBVOSKSPEECHTOTEXT_EXPORT VoskSpeechToTextDeviceInfo {
23 // TODO add language and co
24 QString modelDir;
25 QString formattedLang;
26 int sampleRate = 0;
27 };
28
29 explicit VoskSpeechToTextDevice(QObject *parent = nullptr);
30 ~VoskSpeechToTextDevice() override;
31
32 void clear();
33 [[nodiscard]] bool initialize(VoskSpeechToTextDeviceInfo &&info);
34
35 [[nodiscard]] bool available() const;
36
37 [[nodiscard]] bool isAsking() const;
38
39 void setAsking(bool asking);
40
42 void result(const QString &str);
43 void askingChanged();
44 void doneListening();
45 void falsePositiveWakeWord();
46 void wakeWordDetected();
47
48protected:
49 qint64 readData(char *data, qint64 maxlen) override;
50 qint64 writeData(const char *data, qint64 len) override;
51
52private:
53 LIBVOSKSPEECHTOTEXT_NO_EXPORT void parseText(const char *json);
54 LIBVOSKSPEECHTOTEXT_NO_EXPORT void parsePartial(const char *json);
55 QString mWakeWord;
56 bool mIsAsking = false;
57 bool mIsListiningBecauseOfWakeWord = false;
58#if HAVE_VOSK_API_SUPPORT
59 VoskModel *mModel = nullptr;
60 VoskRecognizer *mRecognizer = nullptr;
61#endif
62};
63Q_DECLARE_TYPEINFO(VoskSpeechToTextDevice::VoskSpeechToTextDeviceInfo, Q_MOVABLE_TYPE);
64LIBVOSKSPEECHTOTEXT_EXPORT QDebug operator<<(QDebug d, const VoskSpeechToTextDevice::VoskSpeechToTextDeviceInfo &t);
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
KCRASH_EXPORT void initialize()
KGuiItem clear()
virtual qint64 readData(char *data, qint64 maxSize)=0
virtual qint64 writeData(const char *data, qint64 maxSize)=0
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:29:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.