Advertisement
dlangu0393

[GoogleSpeechAPI]AudioInput - speechInput.h

Jan 24th, 2012
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Based on Qt Example
  3.  * PCM2WAV is not mine, I found it in Google and modified it.
  4.  */
  5.  
  6. #ifndef SPEECHINPUT
  7. #define SPEECHINPUT
  8.  
  9. #include <QPixmap>
  10. #include <QWidget>
  11. #include <QObject>
  12. #include <QPushButton>
  13. #include <QByteArray>
  14. #include <QAudioInput>
  15. #include <QIODevice>
  16. #include <QFile>
  17.  
  18. class WavPcmFile : public QFile {
  19. public:
  20.     WavPcmFile(const QString & name, const QAudioFormat & format, QObject *parent = 0);
  21.     bool open();
  22.     void close();
  23.  
  24. private:
  25.     void writeHeader();
  26.     bool hasSupportedFormat();
  27.     QAudioFormat format;
  28. };
  29.  
  30. class AudioInfo : public QIODevice
  31. {
  32.     Q_OBJECT
  33. public:
  34.     AudioInfo(const QAudioFormat &format, QObject *parent, const QString &filename = "./data/tmp/speechInput.wav");
  35.     ~AudioInfo();
  36.  
  37.     void start();
  38.     void stop();
  39.  
  40.     qreal level() const { return m_level; }
  41.  
  42.     qint64 readData(char *data, qint64 maxlen);
  43.     qint64 writeData(const char *data, qint64 len);
  44.  
  45. private:
  46.     const QAudioFormat m_format;
  47.     quint16 m_maxAmplitude;
  48.     qreal m_level; // 0.0 <= m_level <= 1.0
  49.  
  50.     WavPcmFile * m_file;
  51.  
  52. signals:
  53.     void update();
  54. };
  55.  
  56.  
  57. class RenderArea : public QWidget
  58. {
  59.     Q_OBJECT
  60.  
  61. public:
  62.     RenderArea(QWidget *parent = 0);
  63.  
  64.     void setLevel(qreal value);
  65.  
  66. protected:
  67.     void paintEvent(QPaintEvent *event);
  68.  
  69. private:
  70.     qreal m_level;
  71.     QPixmap m_pixmap;
  72. };
  73.  
  74. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement