File indexing completed on 2024-12-22 04:28:22

0001 /*
0002   SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #pragma once
0007 #include "libvoskspeechtotext_export.h"
0008 #include "voskdownloadlanguagejob.h"
0009 #include "voskspeechtotextinfo.h"
0010 #include <QObject>
0011 
0012 class LIBVOSKSPEECHTOTEXT_EXPORT ManagerModelVoskSpeechToText : public QObject
0013 {
0014     Q_OBJECT
0015 public:
0016     struct ProgressInfo {
0017         QString languageName;
0018         qint64 bytesReceived = -1;
0019         qint64 bytesTotal = -1;
0020     };
0021     explicit ManagerModelVoskSpeechToText(QObject *parent = nullptr);
0022     ~ManagerModelVoskSpeechToText() override;
0023 
0024     static ManagerModelVoskSpeechToText *self();
0025 
0026     void downloadListModels();
0027 
0028     [[nodiscard]] QVector<VoskSpeechToTextInfo> speechToTextInfos() const;
0029     void setSpeechToTextInfos(const QVector<VoskSpeechToTextInfo> &newTranslators);
0030 
0031     void loadModelList(const QString &fileName);
0032 
0033     void downloadLanguage(const VoskDownloadLanguageJob::DownloadLanguageInfo &info);
0034     [[nodiscard]] bool needDownloadModelList() const;
0035 Q_SIGNALS:
0036     void errorText(const QString &str);
0037     void progress(const ManagerModelVoskSpeechToText::ProgressInfo &info);
0038     void extractDone();
0039     void downLoadModelListDone();
0040 
0041 private:
0042     LIBVOSKSPEECHTOTEXT_NO_EXPORT void parseListModel(const QJsonArray &arrays);
0043     QVector<VoskSpeechToTextInfo> mSpeechToTextInfos;
0044 };
0045 Q_DECLARE_TYPEINFO(ManagerModelVoskSpeechToText::ProgressInfo, Q_MOVABLE_TYPE);