ttsclient.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef TTSCLIENT_H
  2. #define TTSCLIENT_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <QStringList>
  6. #include <QWebSocket>
  7. #include <QJsonObject>
  8. class TTSClient : public QObject
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit TTSClient(QObject* parent = nullptr);
  13. ~TTSClient();
  14. void connectToServer(const QString& host, quint16 port);
  15. void disconnectFromServer();
  16. void synthesize(const QString& text, const QString& refAudio = QString(), int chunkIndex = -1);
  17. void requestVoices();
  18. bool isConnected() const;
  19. Q_SIGNALS:
  20. void connected();
  21. void disconnected();
  22. void connectionError(const QString& error);
  23. void audioReceived(const QByteArray& audioData, int sampleRate, int chunkIndex, bool isFirst, bool isLast);
  24. void voicesReceived(const QStringList& voices);
  25. void synthesisFinished(int chunkIndex);
  26. void modelInfoReceived(const QJsonObject& info);
  27. private Q_SLOTS:
  28. void onConnected();
  29. void onDisconnected();
  30. void onTextMessageReceived(const QString& message);
  31. void onError(QAbstractSocket::SocketError error);
  32. private:
  33. QWebSocket* m_webSocket;
  34. bool m_isConnected;
  35. };
  36. #endif