-
Notifications
You must be signed in to change notification settings - Fork 1
/
qgooglespeech.cpp
52 lines (37 loc) · 1.05 KB
/
qgooglespeech.cpp
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
#include "qgooglespeech.h"
QGoogleSpeech::QGoogleSpeech(QString language)
{
m_url = "http://translate.google.com/translate_tts?ie=UTF-8&tl=%1&q=%2";
m_language = language;
m_playlist = new QMediaPlaylist;
m_player = new QMediaPlayer;
QObject::connect(m_player, SIGNAL(error(QMediaPlayer::Error)),
this, SLOT(errorSlot()) );
QObject::connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)),
this, SLOT(errorSlot()) );
}
void QGoogleSpeech::setLanguage(QString language)
{
m_language = language;
}
void QGoogleSpeech::speech(QString text)
{
if (QMultimedia::Available == 0) {
QString i;
text.replace(" ","+");
m_playlist->addMedia(QUrl(m_url.arg(m_language).arg(text)));
m_player->setPlaylist(m_playlist);
m_player->play();
} else {
emit error();
}
}
void QGoogleSpeech::errorSlot()
{
emit error();
}
void QGoogleSpeech::state(QMediaPlayer::State state)
{
if (state == QMediaPlayer::StoppedState)
emit stopped();
}