speechthread.cpp 680 B

1234567891011121314151617181920212223242526272829303132
  1. #include "speechthread.h"
  2. //#include <QtDebug>
  3. SpeechThread::SpeechThread(QObject *parent) : QObject(parent)
  4. {
  5. SpeechList.clear();
  6. tts = new QTextToSpeech(this);
  7. tts->setVolume(1.0);
  8. timer = new QTimer(this);
  9. connect(timer,&QTimer::timeout,this,&SpeechThread::timeout);
  10. }
  11. void SpeechThread::append(QString speech)
  12. {
  13. SpeechList.append(speech);
  14. }
  15. void SpeechThread::start()
  16. {
  17. timer->start(1500);
  18. }
  19. void SpeechThread::timeout()
  20. {
  21. if(SpeechList.length()>0){
  22. if(tts->state()==QTextToSpeech::Ready){
  23. tts->say(SpeechList.first());
  24. // qDebug()<<SpeechList.first();
  25. SpeechList.removeFirst();
  26. }
  27. }
  28. }