-
Notifications
You must be signed in to change notification settings - Fork 33
/
speechinput.h
executable file
·75 lines (57 loc) · 1.52 KB
/
speechinput.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Based on Qt Example
* PCM2WAV is not mine, I found it in Google and modified it.
*/
#ifndef SPEECHINPUT
#define SPEECHINPUT
#include <QPixmap>
#include <QWidget>
#include <QObject>
#include <QPushButton>
#include <QByteArray>
//#include <Phonon/AudioOutput>
#include <QtMultimedia>
#include <QIODevice>
#include <QFile>
class WavPcmFile : public QFile {
public:
WavPcmFile(const QString & name, const QAudioFormat & format, QObject *parent = 0);
bool open();
void close();
private:
void writeHeader();
bool hasSupportedFormat();
QAudioFormat format;
};
class AudioInfo : public QIODevice
{
Q_OBJECT
public:
AudioInfo(const QAudioFormat &format, QObject *parent, const QString &filename = "./data/tmp/speechInput.wav");
~AudioInfo();
void start();
void stop();
qreal level() const { return m_level; }
qint64 readData(char *data, qint64 maxlen);
qint64 writeData(const char *data, qint64 len);
private:
const QAudioFormat m_format;
quint16 m_maxAmplitude;
qreal m_level; // 0.0 <= m_level <= 1.0
WavPcmFile * m_file;
signals:
void update();
};
class RenderArea : public QPushButton
{
Q_OBJECT
public:
RenderArea(QWidget *parent = 0);
void setLevel(qreal value);
protected:
void paintEvent(QPaintEvent *event);
private:
qreal m_level;
QPixmap m_pixmap;
};
#endif