diff options
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/rbutilqt/tts.cpp | 494 | ||||
-rw-r--r-- | rbutil/rbutilqt/tts.h | 56 | ||||
-rw-r--r-- | rbutil/rbutilqt/ttsgui.cpp | 235 | ||||
-rw-r--r-- | rbutil/rbutilqt/ttsgui.h | 115 | ||||
-rw-r--r-- | rbutil/rbutilqt/voicefile.cpp | 110 | ||||
-rw-r--r-- | rbutil/rbutilqt/voicefile.h | 19 |
6 files changed, 517 insertions, 512 deletions
diff --git a/rbutil/rbutilqt/tts.cpp b/rbutil/rbutilqt/tts.cpp index 48555cc114..68f169e875 100644 --- a/rbutil/rbutilqt/tts.cpp +++ b/rbutil/rbutilqt/tts.cpp | |||
@@ -50,17 +50,17 @@ TTSBase* TTSBase::getTTS(QString ttsName) | |||
50 | if(ttsName == "sapi") | 50 | if(ttsName == "sapi") |
51 | { | 51 | { |
52 | tts = new TTSSapi(); | 52 | tts = new TTSSapi(); |
53 | ttsCache[ttsName] = tts; | 53 | ttsCache[ttsName] = tts; |
54 | return tts; | 54 | return tts; |
55 | } | 55 | } |
56 | else | 56 | else |
57 | #endif | 57 | #endif |
58 | #if defined(Q_OS_LINUX) | 58 | #if defined(Q_OS_LINUX) |
59 | if (ttsName == "festival") | 59 | if (ttsName == "festival") |
60 | { | 60 | { |
61 | tts = new TTSFestival(); | 61 | tts = new TTSFestival(); |
62 | ttsCache[ttsName] = tts; | 62 | ttsCache[ttsName] = tts; |
63 | return tts; | 63 | return tts; |
64 | } | 64 | } |
65 | else | 65 | else |
66 | #endif | 66 | #endif |
@@ -104,30 +104,30 @@ TTSBase::TTSBase(): QObject() | |||
104 | TTSExes::TTSExes(QString name) : TTSBase() | 104 | TTSExes::TTSExes(QString name) : TTSBase() |
105 | { | 105 | { |
106 | m_name = name; | 106 | m_name = name; |
107 | 107 | ||
108 | m_TemplateMap["espeak"] = "\"%exe\" %options -w \"%wavfile\" \"%text\""; | 108 | m_TemplateMap["espeak"] = "\"%exe\" %options -w \"%wavfile\" \"%text\""; |
109 | m_TemplateMap["flite"] = "\"%exe\" %options -o \"%wavfile\" -t \"%text\""; | 109 | m_TemplateMap["flite"] = "\"%exe\" %options -o \"%wavfile\" -t \"%text\""; |
110 | m_TemplateMap["swift"] = "\"%exe\" %options -o \"%wavfile\" \"%text\""; | 110 | m_TemplateMap["swift"] = "\"%exe\" %options -o \"%wavfile\" \"%text\""; |
111 | 111 | ||
112 | } | 112 | } |
113 | 113 | ||
114 | void TTSExes::setCfg(RbSettings* sett) | 114 | void TTSExes::setCfg(RbSettings* sett) |
115 | { | 115 | { |
116 | // call function of base class | 116 | // call function of base class |
117 | TTSBase::setCfg(sett); | 117 | TTSBase::setCfg(sett); |
118 | 118 | ||
119 | // if the config isnt OK, try to autodetect | 119 | // if the config isnt OK, try to autodetect |
120 | if(!configOk()) | 120 | if(!configOk()) |
121 | { | 121 | { |
122 | QString exepath; | 122 | QString exepath; |
123 | //try autodetect tts | 123 | //try autodetect tts |
124 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) | 124 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) |
125 | QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts); | 125 | QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts); |
126 | #elif defined(Q_OS_WIN) | 126 | #elif defined(Q_OS_WIN) |
127 | QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts); | 127 | QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts); |
128 | #endif | 128 | #endif |
129 | qDebug() << path; | 129 | qDebug() << path; |
130 | for(int i = 0; i < path.size(); i++) | 130 | for(int i = 0; i < path.size(); i++) |
131 | { | 131 | { |
132 | QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name; | 132 | QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name; |
133 | #if defined(Q_OS_WIN) | 133 | #if defined(Q_OS_WIN) |
@@ -145,14 +145,14 @@ void TTSExes::setCfg(RbSettings* sett) | |||
145 | settings->setTTSPath(m_name,exepath); | 145 | settings->setTTSPath(m_name,exepath); |
146 | settings->sync(); | 146 | settings->sync(); |
147 | } | 147 | } |
148 | 148 | ||
149 | } | 149 | } |
150 | 150 | ||
151 | bool TTSExes::start(QString *errStr) | 151 | bool TTSExes::start(QString *errStr) |
152 | { | 152 | { |
153 | m_TTSexec = settings->ttsPath(m_name); | 153 | m_TTSexec = settings->ttsPath(m_name); |
154 | m_TTSOpts = settings->ttsOptions(m_name); | 154 | m_TTSOpts = settings->ttsOptions(m_name); |
155 | 155 | ||
156 | m_TTSTemplate = m_TemplateMap.value(m_name); | 156 | m_TTSTemplate = m_TemplateMap.value(m_name); |
157 | 157 | ||
158 | QFileInfo tts(m_TTSexec); | 158 | QFileInfo tts(m_TTSexec); |
@@ -169,7 +169,7 @@ bool TTSExes::start(QString *errStr) | |||
169 | 169 | ||
170 | TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr) | 170 | TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr) |
171 | { | 171 | { |
172 | (void) errStr; | 172 | (void) errStr; |
173 | QString execstring = m_TTSTemplate; | 173 | QString execstring = m_TTSTemplate; |
174 | 174 | ||
175 | execstring.replace("%exe",m_TTSexec); | 175 | execstring.replace("%exe",m_TTSexec); |
@@ -187,7 +187,7 @@ void TTSExes::showCfg() | |||
187 | #ifndef CONSOLE | 187 | #ifndef CONSOLE |
188 | TTSExesGui gui; | 188 | TTSExesGui gui; |
189 | #else | 189 | #else |
190 | TTSExesGuiCli gui; | 190 | TTSExesGuiCli gui; |
191 | #endif | 191 | #endif |
192 | gui.setCfg(settings); | 192 | gui.setCfg(settings); |
193 | gui.showCfg(m_name); | 193 | gui.showCfg(m_name); |
@@ -196,10 +196,10 @@ void TTSExes::showCfg() | |||
196 | bool TTSExes::configOk() | 196 | bool TTSExes::configOk() |
197 | { | 197 | { |
198 | QString path = settings->ttsPath(m_name); | 198 | QString path = settings->ttsPath(m_name); |
199 | 199 | ||
200 | if (QFileInfo(path).exists()) | 200 | if (QFileInfo(path).exists()) |
201 | return true; | 201 | return true; |
202 | 202 | ||
203 | return false; | 203 | return false; |
204 | } | 204 | } |
205 | 205 | ||
@@ -215,24 +215,24 @@ TTSSapi::TTSSapi() : TTSBase() | |||
215 | 215 | ||
216 | 216 | ||
217 | bool TTSSapi::start(QString *errStr) | 217 | bool TTSSapi::start(QString *errStr) |
218 | { | 218 | { |
219 | 219 | ||
220 | m_TTSOpts = settings->ttsOptions("sapi"); | 220 | m_TTSOpts = settings->ttsOptions("sapi"); |
221 | m_TTSLanguage =settings->ttsLang("sapi"); | 221 | m_TTSLanguage =settings->ttsLang("sapi"); |
222 | m_TTSVoice=settings->ttsVoice("sapi"); | 222 | m_TTSVoice=settings->ttsVoice("sapi"); |
223 | m_TTSSpeed=QString("%1").arg(settings->ttsSpeed("sapi")); | 223 | m_TTSSpeed=QString("%1").arg(settings->ttsSpeed("sapi")); |
224 | m_sapi4 = settings->ttsUseSapi4(); | 224 | m_sapi4 = settings->ttsUseSapi4(); |
225 | 225 | ||
226 | QFile::remove(QDir::tempPath() +"/sapi_voice.vbs"); | 226 | QFile::remove(QDir::tempPath() +"/sapi_voice.vbs"); |
227 | QFile::copy(":/builtin/sapi_voice.vbs",QDir::tempPath() + "/sapi_voice.vbs"); | 227 | QFile::copy(":/builtin/sapi_voice.vbs",QDir::tempPath() + "/sapi_voice.vbs"); |
228 | m_TTSexec = QDir::tempPath() +"/sapi_voice.vbs"; | 228 | m_TTSexec = QDir::tempPath() +"/sapi_voice.vbs"; |
229 | 229 | ||
230 | QFileInfo tts(m_TTSexec); | 230 | QFileInfo tts(m_TTSexec); |
231 | if(!tts.exists()) | 231 | if(!tts.exists()) |
232 | { | 232 | { |
233 | *errStr = tr("Could not copy the Sapi-script"); | 233 | *errStr = tr("Could not copy the Sapi-script"); |
234 | return false; | 234 | return false; |
235 | } | 235 | } |
236 | // create the voice process | 236 | // create the voice process |
237 | QString execstring = m_TTSTemplate; | 237 | QString execstring = m_TTSTemplate; |
238 | execstring.replace("%exe",m_TTSexec); | 238 | execstring.replace("%exe",m_TTSexec); |
@@ -240,31 +240,31 @@ bool TTSSapi::start(QString *errStr) | |||
240 | execstring.replace("%lang",m_TTSLanguage); | 240 | execstring.replace("%lang",m_TTSLanguage); |
241 | execstring.replace("%voice",m_TTSVoice); | 241 | execstring.replace("%voice",m_TTSVoice); |
242 | execstring.replace("%speed",m_TTSSpeed); | 242 | execstring.replace("%speed",m_TTSSpeed); |
243 | 243 | ||
244 | if(m_sapi4) | 244 | if(m_sapi4) |
245 | execstring.append(" /sapi4 "); | 245 | execstring.append(" /sapi4 "); |
246 | 246 | ||
247 | qDebug() << "init" << execstring; | 247 | qDebug() << "init" << execstring; |
248 | voicescript = new QProcess(NULL); | 248 | voicescript = new QProcess(NULL); |
249 | //connect(voicescript,SIGNAL(readyReadStandardError()),this,SLOT(error())); | 249 | //connect(voicescript,SIGNAL(readyReadStandardError()),this,SLOT(error())); |
250 | 250 | ||
251 | voicescript->start(execstring); | 251 | voicescript->start(execstring); |
252 | if(!voicescript->waitForStarted()) | 252 | if(!voicescript->waitForStarted()) |
253 | { | 253 | { |
254 | *errStr = tr("Could not start the Sapi-script"); | 254 | *errStr = tr("Could not start the Sapi-script"); |
255 | return false; | 255 | return false; |
256 | } | 256 | } |
257 | 257 | ||
258 | if(!voicescript->waitForReadyRead(300)) | 258 | if(!voicescript->waitForReadyRead(300)) |
259 | { | 259 | { |
260 | *errStr = voicescript->readAllStandardError(); | 260 | *errStr = voicescript->readAllStandardError(); |
261 | if(*errStr != "") | 261 | if(*errStr != "") |
262 | return false; | 262 | return false; |
263 | } | 263 | } |
264 | 264 | ||
265 | voicestream = new QTextStream(voicescript); | 265 | voicestream = new QTextStream(voicescript); |
266 | voicestream->setCodec("UTF16-LE"); | 266 | voicestream->setCodec("UTF16-LE"); |
267 | 267 | ||
268 | return true; | 268 | return true; |
269 | } | 269 | } |
270 | 270 | ||
@@ -272,31 +272,31 @@ bool TTSSapi::start(QString *errStr) | |||
272 | QStringList TTSSapi::getVoiceList(QString language) | 272 | QStringList TTSSapi::getVoiceList(QString language) |
273 | { | 273 | { |
274 | QStringList result; | 274 | QStringList result; |
275 | 275 | ||
276 | QFile::copy(":/builtin/sapi_voice.vbs",QDir::tempPath() + "/sapi_voice.vbs"); | 276 | QFile::copy(":/builtin/sapi_voice.vbs",QDir::tempPath() + "/sapi_voice.vbs"); |
277 | m_TTSexec = QDir::tempPath() +"/sapi_voice.vbs"; | 277 | m_TTSexec = QDir::tempPath() +"/sapi_voice.vbs"; |
278 | 278 | ||
279 | QFileInfo tts(m_TTSexec); | 279 | QFileInfo tts(m_TTSexec); |
280 | if(!tts.exists()) | 280 | if(!tts.exists()) |
281 | return result; | 281 | return result; |
282 | 282 | ||
283 | // create the voice process | 283 | // create the voice process |
284 | QString execstring = "cscript //nologo \"%exe\" /language:%lang /listvoices"; | 284 | QString execstring = "cscript //nologo \"%exe\" /language:%lang /listvoices"; |
285 | execstring.replace("%exe",m_TTSexec); | 285 | execstring.replace("%exe",m_TTSexec); |
286 | execstring.replace("%lang",language); | 286 | execstring.replace("%lang",language); |
287 | 287 | ||
288 | if(settings->ttsUseSapi4()) | 288 | if(settings->ttsUseSapi4()) |
289 | execstring.append(" /sapi4 "); | 289 | execstring.append(" /sapi4 "); |
290 | 290 | ||
291 | qDebug() << "init" << execstring; | 291 | qDebug() << "init" << execstring; |
292 | voicescript = new QProcess(NULL); | 292 | voicescript = new QProcess(NULL); |
293 | voicescript->start(execstring); | 293 | voicescript->start(execstring); |
294 | qDebug() << "wait for started"; | 294 | qDebug() << "wait for started"; |
295 | if(!voicescript->waitForStarted()) | 295 | if(!voicescript->waitForStarted()) |
296 | return result; | 296 | return result; |
297 | voicescript->closeWriteChannel(); | 297 | voicescript->closeWriteChannel(); |
298 | voicescript->waitForReadyRead(); | 298 | voicescript->waitForReadyRead(); |
299 | 299 | ||
300 | QString dataRaw = voicescript->readAllStandardError().data(); | 300 | QString dataRaw = voicescript->readAllStandardError().data(); |
301 | result = dataRaw.split(",",QString::SkipEmptyParts); | 301 | result = dataRaw.split(",",QString::SkipEmptyParts); |
302 | result.sort(); | 302 | result.sort(); |
@@ -305,15 +305,16 @@ QStringList TTSSapi::getVoiceList(QString language) | |||
305 | { | 305 | { |
306 | result[i] = result.at(i).simplified(); | 306 | result[i] = result.at(i).simplified(); |
307 | } | 307 | } |
308 | 308 | ||
309 | 309 | ||
310 | delete voicescript; | 310 | delete voicescript; |
311 | QFile::setPermissions(QDir::tempPath() +"/sapi_voice.vbs",QFile::ReadOwner |QFile::WriteOwner|QFile::ExeOwner | 311 | QFile::setPermissions(QDir::tempPath() +"/sapi_voice.vbs", |
312 | |QFile::ReadUser| QFile::WriteUser| QFile::ExeUser | 312 | QFile::ReadOwner |QFile::WriteOwner |QFile::ExeOwner |
313 | |QFile::ReadGroup |QFile::WriteGroup |QFile::ExeGroup | 313 | |QFile::ReadUser |QFile::WriteUser |QFile::ExeUser |
314 | |QFile::ReadOther |QFile::WriteOther |QFile::ExeOther ); | 314 | |QFile::ReadGroup |QFile::WriteGroup |QFile::ExeGroup |
315 | |QFile::ReadOther |QFile::WriteOther |QFile::ExeOther); | ||
315 | QFile::remove(QDir::tempPath() +"/sapi_voice.vbs"); | 316 | QFile::remove(QDir::tempPath() +"/sapi_voice.vbs"); |
316 | 317 | ||
317 | return result; | 318 | return result; |
318 | } | 319 | } |
319 | 320 | ||
@@ -321,7 +322,7 @@ QStringList TTSSapi::getVoiceList(QString language) | |||
321 | 322 | ||
322 | TTSStatus TTSSapi::voice(QString text,QString wavfile, QString *errStr) | 323 | TTSStatus TTSSapi::voice(QString text,QString wavfile, QString *errStr) |
323 | { | 324 | { |
324 | (void) errStr; | 325 | (void) errStr; |
325 | QString query = "SPEAK\t"+wavfile+"\t"+text+"\r\n"; | 326 | QString query = "SPEAK\t"+wavfile+"\t"+text+"\r\n"; |
326 | qDebug() << "voicing" << query; | 327 | qDebug() << "voicing" << query; |
327 | *voicestream << query; | 328 | *voicestream << query; |
@@ -332,17 +333,18 @@ TTSStatus TTSSapi::voice(QString text,QString wavfile, QString *errStr) | |||
332 | } | 333 | } |
333 | 334 | ||
334 | bool TTSSapi::stop() | 335 | bool TTSSapi::stop() |
335 | { | 336 | { |
336 | 337 | ||
337 | *voicestream << "QUIT\r\n"; | 338 | *voicestream << "QUIT\r\n"; |
338 | voicestream->flush(); | 339 | voicestream->flush(); |
339 | voicescript->waitForFinished(); | 340 | voicescript->waitForFinished(); |
340 | delete voicestream; | 341 | delete voicestream; |
341 | delete voicescript; | 342 | delete voicescript; |
342 | QFile::setPermissions(QDir::tempPath() +"/sapi_voice.vbs",QFile::ReadOwner |QFile::WriteOwner|QFile::ExeOwner | 343 | QFile::setPermissions(QDir::tempPath() +"/sapi_voice.vbs", |
343 | |QFile::ReadUser| QFile::WriteUser| QFile::ExeUser | 344 | QFile::ReadOwner |QFile::WriteOwner |QFile::ExeOwner |
344 | |QFile::ReadGroup |QFile::WriteGroup |QFile::ExeGroup | 345 | |QFile::ReadUser |QFile::WriteUser |QFile::ExeUser |
345 | |QFile::ReadOther |QFile::WriteOther |QFile::ExeOther ); | 346 | |QFile::ReadGroup |QFile::WriteGroup |QFile::ExeGroup |
347 | |QFile::ReadOther |QFile::WriteOther |QFile::ExeOther); | ||
346 | QFile::remove(QDir::tempPath() +"/sapi_voice.vbs"); | 348 | QFile::remove(QDir::tempPath() +"/sapi_voice.vbs"); |
347 | return true; | 349 | return true; |
348 | } | 350 | } |
@@ -353,7 +355,7 @@ void TTSSapi::showCfg() | |||
353 | #ifndef CONSOLE | 355 | #ifndef CONSOLE |
354 | TTSSapiGui gui(this); | 356 | TTSSapiGui gui(this); |
355 | #else | 357 | #else |
356 | TTSSapiGuiCli gui(this); | 358 | TTSSapiGuiCli gui(this); |
357 | #endif | 359 | #endif |
358 | gui.setCfg(settings); | 360 | gui.setCfg(settings); |
359 | gui.showCfg(); | 361 | gui.showCfg(); |
@@ -370,104 +372,104 @@ bool TTSSapi::configOk() | |||
370 | **********************************************************************/ | 372 | **********************************************************************/ |
371 | TTSFestival::~TTSFestival() | 373 | TTSFestival::~TTSFestival() |
372 | { | 374 | { |
373 | stop(); | 375 | stop(); |
374 | } | 376 | } |
375 | 377 | ||
376 | void TTSFestival::startServer() | 378 | void TTSFestival::startServer() |
377 | { | 379 | { |
378 | if(!configOk()) | 380 | if(!configOk()) |
379 | return; | 381 | return; |
380 | 382 | ||
381 | QStringList paths = settings->ttsPath("festival").split(":"); | 383 | QStringList paths = settings->ttsPath("festival").split(":"); |
382 | 384 | ||
383 | serverProcess.start(QString("%1 --server").arg(paths[0])); | 385 | serverProcess.start(QString("%1 --server").arg(paths[0])); |
384 | serverProcess.waitForStarted(); | 386 | serverProcess.waitForStarted(); |
385 | 387 | ||
386 | queryServer("(getpid)"); | 388 | queryServer("(getpid)"); |
387 | if(serverProcess.state() == QProcess::Running) | 389 | if(serverProcess.state() == QProcess::Running) |
388 | qDebug() << "Festival is up and running"; | 390 | qDebug() << "Festival is up and running"; |
389 | else | 391 | else |
390 | qDebug() << "Festival failed to start"; | 392 | qDebug() << "Festival failed to start"; |
391 | } | 393 | } |
392 | 394 | ||
393 | void TTSFestival::ensureServerRunning() | 395 | void TTSFestival::ensureServerRunning() |
394 | { | 396 | { |
395 | if(serverProcess.state() != QProcess::Running) | 397 | if(serverProcess.state() != QProcess::Running) |
396 | { | 398 | { |
397 | // least common denominator for all the server startup code paths | 399 | // least common denominator for all the server startup code paths |
398 | QProgressDialog progressDialog(tr(""), tr(""), 0, 0); | 400 | QProgressDialog progressDialog(tr(""), tr(""), 0, 0); |
399 | progressDialog.setWindowTitle(tr("Starting festival")); | 401 | progressDialog.setWindowTitle(tr("Starting festival")); |
400 | progressDialog.setModal(true); | 402 | progressDialog.setModal(true); |
401 | progressDialog.setLabel(0); | 403 | progressDialog.setLabel(0); |
402 | progressDialog.setCancelButton(0); | 404 | progressDialog.setCancelButton(0); |
403 | progressDialog.show(); | 405 | progressDialog.show(); |
404 | 406 | ||
405 | QApplication::processEvents(); // actually show the dialog | 407 | QApplication::processEvents(); // actually show the dialog |
406 | 408 | ||
407 | startServer(); | 409 | startServer(); |
408 | } | 410 | } |
409 | } | 411 | } |
410 | 412 | ||
411 | bool TTSFestival::start(QString* errStr) | 413 | bool TTSFestival::start(QString* errStr) |
412 | { | 414 | { |
413 | (void) errStr; | 415 | (void) errStr; |
414 | ensureServerRunning(); | 416 | ensureServerRunning(); |
415 | if (!settings->ttsVoice("festival").isEmpty()) | 417 | if (!settings->ttsVoice("festival").isEmpty()) |
416 | queryServer(QString("(voice.select '%1)").arg(settings->ttsVoice("festival"))); | 418 | queryServer(QString("(voice.select '%1)").arg(settings->ttsVoice("festival"))); |
417 | 419 | ||
418 | return true; | 420 | return true; |
419 | } | 421 | } |
420 | 422 | ||
421 | bool TTSFestival::stop() | 423 | bool TTSFestival::stop() |
422 | { | 424 | { |
423 | serverProcess.terminate(); | 425 | serverProcess.terminate(); |
424 | serverProcess.kill(); | 426 | serverProcess.kill(); |
425 | 427 | ||
426 | return true; | 428 | return true; |
427 | } | 429 | } |
428 | 430 | ||
429 | TTSStatus TTSFestival::voice(QString text, QString wavfile, QString* errStr) | 431 | TTSStatus TTSFestival::voice(QString text, QString wavfile, QString* errStr) |
430 | { | 432 | { |
431 | qDebug() << text << "->" << wavfile; | 433 | qDebug() << text << "->" << wavfile; |
432 | 434 | ||
433 | QStringList paths = settings->ttsPath("festival").split(":"); | 435 | QStringList paths = settings->ttsPath("festival").split(":"); |
434 | QString cmd = QString("%1 --server localhost --otype riff --ttw --withlisp --output \"%2\" - ").arg(paths[1]).arg(wavfile); | 436 | QString cmd = QString("%1 --server localhost --otype riff --ttw --withlisp --output \"%2\" - ").arg(paths[1]).arg(wavfile); |
435 | qDebug() << cmd; | 437 | qDebug() << cmd; |
436 | 438 | ||
437 | QProcess clientProcess; | 439 | QProcess clientProcess; |
438 | clientProcess.start(cmd); | 440 | clientProcess.start(cmd); |
439 | clientProcess.write(QString("%1.\n").arg(text).toAscii()); | 441 | clientProcess.write(QString("%1.\n").arg(text).toAscii()); |
440 | clientProcess.waitForBytesWritten(); | 442 | clientProcess.waitForBytesWritten(); |
441 | clientProcess.closeWriteChannel(); | 443 | clientProcess.closeWriteChannel(); |
442 | clientProcess.waitForReadyRead(); | 444 | clientProcess.waitForReadyRead(); |
443 | QString response = clientProcess.readAll(); | 445 | QString response = clientProcess.readAll(); |
444 | response = response.trimmed(); | 446 | response = response.trimmed(); |
445 | if(!response.contains("Utterance")) | 447 | if(!response.contains("Utterance")) |
446 | { | 448 | { |
447 | qDebug() << "Could not voice string: " << response; | 449 | qDebug() << "Could not voice string: " << response; |
448 | *errStr = tr("engine could not voice string"); | 450 | *errStr = tr("engine could not voice string"); |
449 | return Warning; | 451 | return Warning; |
450 | /* do not stop the voicing process because of a single string | 452 | /* do not stop the voicing process because of a single string |
451 | TODO: needs proper settings */ | 453 | TODO: needs proper settings */ |
452 | } | 454 | } |
453 | clientProcess.closeReadChannel(QProcess::StandardError); | 455 | clientProcess.closeReadChannel(QProcess::StandardError); |
454 | clientProcess.closeReadChannel(QProcess::StandardOutput); | 456 | clientProcess.closeReadChannel(QProcess::StandardOutput); |
455 | clientProcess.terminate(); | 457 | clientProcess.terminate(); |
456 | clientProcess.kill(); | 458 | clientProcess.kill(); |
457 | 459 | ||
458 | return NoError; | 460 | return NoError; |
459 | } | 461 | } |
460 | 462 | ||
461 | bool TTSFestival::configOk() | 463 | bool TTSFestival::configOk() |
462 | { | 464 | { |
463 | QStringList paths = settings->ttsPath("festival").split(":"); | 465 | QStringList paths = settings->ttsPath("festival").split(":"); |
464 | if(paths.size() != 2) | 466 | if(paths.size() != 2) |
465 | return false; | 467 | return false; |
466 | bool ret = QFileInfo(paths[0]).isExecutable() && | 468 | bool ret = QFileInfo(paths[0]).isExecutable() && |
467 | QFileInfo(paths[1]).isExecutable(); | 469 | QFileInfo(paths[1]).isExecutable(); |
468 | if(settings->ttsVoice("festival").size() > 0 && voices.size() > 0) | 470 | if(settings->ttsVoice("festival").size() > 0 && voices.size() > 0) |
469 | ret = ret && (voices.indexOf(settings->ttsVoice("festival")) != -1); | 471 | ret = ret && (voices.indexOf(settings->ttsVoice("festival")) != -1); |
470 | return ret; | 472 | return ret; |
471 | } | 473 | } |
472 | 474 | ||
473 | void TTSFestival::showCfg() | 475 | void TTSFestival::showCfg() |
@@ -481,138 +483,138 @@ void TTSFestival::showCfg() | |||
481 | 483 | ||
482 | QStringList TTSFestival::getVoiceList() | 484 | QStringList TTSFestival::getVoiceList() |
483 | { | 485 | { |
484 | if(!configOk()) | 486 | if(!configOk()) |
485 | return QStringList(); | 487 | return QStringList(); |
486 | 488 | ||
487 | if(voices.size() > 0) | 489 | if(voices.size() > 0) |
488 | { | 490 | { |
489 | qDebug() << "Using voice cache"; | 491 | qDebug() << "Using voice cache"; |
490 | return voices; | 492 | return voices; |
491 | } | 493 | } |
492 | QString response = queryServer("(voice.list)"); | 494 | QString response = queryServer("(voice.list)"); |
493 | 495 | ||
494 | // get the 2nd line. It should be (<voice_name>, <voice_name>) | 496 | // get the 2nd line. It should be (<voice_name>, <voice_name>) |
495 | response = response.mid(response.indexOf('\n') + 1, -1); | 497 | response = response.mid(response.indexOf('\n') + 1, -1); |
496 | response = response.left(response.indexOf('\n')).trimmed(); | 498 | response = response.left(response.indexOf('\n')).trimmed(); |
497 | 499 | ||
498 | voices = response.mid(1, response.size()-2).split(' '); | 500 | voices = response.mid(1, response.size()-2).split(' '); |
499 | 501 | ||
500 | voices.sort(); | 502 | voices.sort(); |
501 | if (voices.size() == 1 && voices[0].size() == 0) | 503 | if (voices.size() == 1 && voices[0].size() == 0) |
502 | voices.removeAt(0); | 504 | voices.removeAt(0); |
503 | if (voices.size() > 0) | 505 | if (voices.size() > 0) |
504 | qDebug() << "Voices: " << voices; | 506 | qDebug() << "Voices: " << voices; |
505 | else | 507 | else |
506 | qDebug() << "No voices."; | 508 | qDebug() << "No voices."; |
507 | return voices; | 509 | return voices; |
508 | } | 510 | } |
509 | 511 | ||
510 | QString TTSFestival::getVoiceInfo(QString voice) | 512 | QString TTSFestival::getVoiceInfo(QString voice) |
511 | { | 513 | { |
512 | if(!configOk()) | 514 | if(!configOk()) |
513 | return ""; | 515 | return ""; |
514 | 516 | ||
515 | if(!getVoiceList().contains(voice)) | 517 | if(!getVoiceList().contains(voice)) |
516 | return ""; | 518 | return ""; |
517 | 519 | ||
518 | if(voiceDescriptions.contains(voice)) | 520 | if(voiceDescriptions.contains(voice)) |
519 | return voiceDescriptions[voice]; | 521 | return voiceDescriptions[voice]; |
520 | 522 | ||
521 | QString response = queryServer(QString("(voice.description '%1)").arg(voice), 3000); | 523 | QString response = queryServer(QString("(voice.description '%1)").arg(voice), 3000); |
522 | 524 | ||
523 | if (response == "") | 525 | if (response == "") |
524 | { | 526 | { |
525 | voiceDescriptions[voice]=tr("No description available"); | 527 | voiceDescriptions[voice]=tr("No description available"); |
526 | } | 528 | } |
527 | else | 529 | else |
528 | { | 530 | { |
529 | response = response.remove(QRegExp("(description \"*\")", Qt::CaseInsensitive, QRegExp::Wildcard)); | 531 | response = response.remove(QRegExp("(description \"*\")", Qt::CaseInsensitive, QRegExp::Wildcard)); |
530 | qDebug() << "voiceInfo w/o descr: " << response; | 532 | qDebug() << "voiceInfo w/o descr: " << response; |
531 | response = response.remove(')'); | 533 | response = response.remove(')'); |
532 | QStringList responseLines = response.split('(', QString::SkipEmptyParts); | 534 | QStringList responseLines = response.split('(', QString::SkipEmptyParts); |
533 | responseLines.removeAt(0); // the voice name itself | 535 | responseLines.removeAt(0); // the voice name itself |
534 | 536 | ||
535 | QString description; | 537 | QString description; |
536 | foreach(QString line, responseLines) | 538 | foreach(QString line, responseLines) |
537 | { | 539 | { |
538 | line = line.remove('('); | 540 | line = line.remove('('); |
539 | line = line.simplified(); | 541 | line = line.simplified(); |
540 | 542 | ||
541 | line[0] = line[0].toUpper(); // capitalize the key | 543 | line[0] = line[0].toUpper(); // capitalize the key |
542 | 544 | ||
543 | int firstSpace = line.indexOf(' '); | 545 | int firstSpace = line.indexOf(' '); |
544 | if (firstSpace > 0) | 546 | if (firstSpace > 0) |
545 | { | 547 | { |
546 | line = line.insert(firstSpace, ':'); // add a colon between the key and the value | 548 | line = line.insert(firstSpace, ':'); // add a colon between the key and the value |
547 | line[firstSpace+2] = line[firstSpace+2].toUpper(); // capitalize the value | 549 | line[firstSpace+2] = line[firstSpace+2].toUpper(); // capitalize the value |
548 | } | 550 | } |
549 | 551 | ||
550 | description += line + "\n"; | 552 | description += line + "\n"; |
551 | } | 553 | } |
552 | voiceDescriptions[voice] = description.trimmed(); | 554 | voiceDescriptions[voice] = description.trimmed(); |
553 | } | 555 | } |
554 | return voiceDescriptions[voice]; | 556 | return voiceDescriptions[voice]; |
555 | } | 557 | } |
556 | 558 | ||
557 | QString TTSFestival::queryServer(QString query, int timeout) | 559 | QString TTSFestival::queryServer(QString query, int timeout) |
558 | { | 560 | { |
559 | if(!configOk()) | 561 | if(!configOk()) |
560 | return ""; | 562 | return ""; |
561 | 563 | ||
562 | ensureServerRunning(); | 564 | ensureServerRunning(); |
563 | 565 | ||
564 | qDebug() << "queryServer with " << query; | 566 | qDebug() << "queryServer with " << query; |
565 | QString response; | 567 | QString response; |
566 | 568 | ||
567 | QDateTime endTime; | 569 | QDateTime endTime; |
568 | if(timeout > 0) | 570 | if(timeout > 0) |
569 | endTime = QDateTime::currentDateTime().addMSecs(timeout); | 571 | endTime = QDateTime::currentDateTime().addMSecs(timeout); |
570 | 572 | ||
571 | /* Festival is *extremely* unreliable. Although at this | 573 | /* Festival is *extremely* unreliable. Although at this |
572 | * point we are sure that SIOD is accepting commands, | 574 | * point we are sure that SIOD is accepting commands, |
573 | * we might end up with an empty response. Hence, the loop. | 575 | * we might end up with an empty response. Hence, the loop. |
574 | */ | 576 | */ |
575 | while(true) | 577 | while(true) |
576 | { | 578 | { |
577 | QApplication::processEvents(QEventLoop::AllEvents, 50); | 579 | QApplication::processEvents(QEventLoop::AllEvents, 50); |
578 | QTcpSocket socket; | 580 | QTcpSocket socket; |
579 | 581 | ||
580 | socket.connectToHost("localhost", 1314); | 582 | socket.connectToHost("localhost", 1314); |
581 | socket.waitForConnected(); | 583 | socket.waitForConnected(); |
582 | 584 | ||
583 | if(socket.state() == QAbstractSocket::ConnectedState) | 585 | if(socket.state() == QAbstractSocket::ConnectedState) |
584 | { | 586 | { |
585 | socket.write(QString("%1\n").arg(query).toAscii()); | 587 | socket.write(QString("%1\n").arg(query).toAscii()); |
586 | socket.waitForBytesWritten(); | 588 | socket.waitForBytesWritten(); |
587 | socket.waitForReadyRead(); | 589 | socket.waitForReadyRead(); |
588 | 590 | ||
589 | response = socket.readAll().trimmed(); | 591 | response = socket.readAll().trimmed(); |
590 | 592 | ||
591 | if (response != "LP" && response != "") | 593 | if (response != "LP" && response != "") |
592 | break; | 594 | break; |
593 | } | 595 | } |
594 | socket.abort(); | 596 | socket.abort(); |
595 | socket.disconnectFromHost(); | 597 | socket.disconnectFromHost(); |
596 | 598 | ||
597 | if(timeout > 0 && QDateTime::currentDateTime() >= endTime) | 599 | if(timeout > 0 && QDateTime::currentDateTime() >= endTime) |
598 | return ""; | 600 | return ""; |
599 | 601 | ||
600 | /* make sure we wait a little as we don't want to flood the server with requests */ | 602 | /* make sure we wait a little as we don't want to flood the server with requests */ |
601 | QDateTime tmpEndTime = QDateTime::currentDateTime().addMSecs(500); | 603 | QDateTime tmpEndTime = QDateTime::currentDateTime().addMSecs(500); |
602 | while(QDateTime::currentDateTime() < tmpEndTime) | 604 | while(QDateTime::currentDateTime() < tmpEndTime) |
603 | QApplication::processEvents(QEventLoop::AllEvents); | 605 | QApplication::processEvents(QEventLoop::AllEvents); |
604 | } | 606 | } |
605 | if(response == "nil") | 607 | if(response == "nil") |
606 | return ""; | 608 | return ""; |
607 | 609 | ||
608 | QStringList lines = response.split('\n'); | 610 | QStringList lines = response.split('\n'); |
609 | if(lines.size() > 2) | 611 | if(lines.size() > 2) |
610 | { | 612 | { |
611 | lines.removeFirst(); | 613 | lines.removeFirst(); |
612 | lines.removeLast(); | 614 | lines.removeLast(); |
613 | } | 615 | } |
614 | else | 616 | else |
615 | qDebug() << "Response too short: " << response; | 617 | qDebug() << "Response too short: " << response; |
616 | return lines.join("\n"); | 618 | return lines.join("\n"); |
617 | } | 619 | } |
618 | 620 | ||
diff --git a/rbutil/rbutilqt/tts.h b/rbutil/rbutilqt/tts.h index d225d46853..c9262b74c6 100644 --- a/rbutil/rbutilqt/tts.h +++ b/rbutil/rbutilqt/tts.h | |||
@@ -19,7 +19,7 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | 22 | ||
23 | #ifndef TTS_H | 23 | #ifndef TTS_H |
24 | #define TTS_H | 24 | #define TTS_H |
25 | 25 | ||
@@ -55,16 +55,16 @@ class TTSBase : public QObject | |||
55 | virtual bool configOk() { return false; } | 55 | virtual bool configOk() { return false; } |
56 | 56 | ||
57 | virtual void setCfg(RbSettings* sett) { settings = sett; } | 57 | virtual void setCfg(RbSettings* sett) { settings = sett; } |
58 | 58 | ||
59 | static TTSBase* getTTS(QString ttsname); | 59 | static TTSBase* getTTS(QString ttsname); |
60 | static QStringList getTTSList(); | 60 | static QStringList getTTSList(); |
61 | static QString getTTSName(QString tts); | 61 | static QString getTTSName(QString tts); |
62 | 62 | ||
63 | public slots: | 63 | public slots: |
64 | virtual void accept(void){} | 64 | virtual void accept(void){} |
65 | virtual void reject(void){} | 65 | virtual void reject(void){} |
66 | virtual void reset(void){} | 66 | virtual void reset(void){} |
67 | 67 | ||
68 | private: | 68 | private: |
69 | //inits the tts List | 69 | //inits the tts List |
70 | static void initTTSList(); | 70 | static void initTTSList(); |
@@ -77,7 +77,7 @@ class TTSBase : public QObject | |||
77 | 77 | ||
78 | class TTSSapi : public TTSBase | 78 | class TTSSapi : public TTSBase |
79 | { | 79 | { |
80 | Q_OBJECT | 80 | Q_OBJECT |
81 | public: | 81 | public: |
82 | TTSSapi(); | 82 | TTSSapi(); |
83 | virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); | 83 | virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); |
@@ -85,13 +85,13 @@ class TTSSapi : public TTSBase | |||
85 | virtual bool stop(); | 85 | virtual bool stop(); |
86 | virtual void showCfg(); | 86 | virtual void showCfg(); |
87 | virtual bool configOk(); | 87 | virtual bool configOk(); |
88 | 88 | ||
89 | QStringList getVoiceList(QString language); | 89 | QStringList getVoiceList(QString language); |
90 | private: | 90 | private: |
91 | QProcess* voicescript; | 91 | QProcess* voicescript; |
92 | QTextStream* voicestream; | 92 | QTextStream* voicestream; |
93 | QString defaultLanguage; | 93 | QString defaultLanguage; |
94 | 94 | ||
95 | QString m_TTSexec; | 95 | QString m_TTSexec; |
96 | QString m_TTSOpts; | 96 | QString m_TTSOpts; |
97 | QString m_TTSTemplate; | 97 | QString m_TTSTemplate; |
@@ -114,7 +114,7 @@ class TTSExes : public TTSBase | |||
114 | virtual bool configOk(); | 114 | virtual bool configOk(); |
115 | 115 | ||
116 | virtual void setCfg(RbSettings* sett); | 116 | virtual void setCfg(RbSettings* sett); |
117 | 117 | ||
118 | private: | 118 | private: |
119 | QString m_name; | 119 | QString m_name; |
120 | QString m_TTSexec; | 120 | QString m_TTSexec; |
@@ -125,24 +125,24 @@ class TTSExes : public TTSBase | |||
125 | 125 | ||
126 | class TTSFestival : public TTSBase | 126 | class TTSFestival : public TTSBase |
127 | { | 127 | { |
128 | Q_OBJECT | 128 | Q_OBJECT |
129 | public: | 129 | public: |
130 | ~TTSFestival(); | 130 | ~TTSFestival(); |
131 | virtual bool configOk(); | 131 | virtual bool configOk(); |
132 | virtual bool start(QString *errStr); | 132 | virtual bool start(QString *errStr); |
133 | virtual bool stop(); | 133 | virtual bool stop(); |
134 | virtual void showCfg(); | 134 | virtual void showCfg(); |
135 | virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); | 135 | virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); |
136 | 136 | ||
137 | QStringList getVoiceList(); | 137 | QStringList getVoiceList(); |
138 | QString getVoiceInfo(QString voice); | 138 | QString getVoiceInfo(QString voice); |
139 | private: | 139 | private: |
140 | inline void startServer(); | 140 | inline void startServer(); |
141 | inline void ensureServerRunning(); | 141 | inline void ensureServerRunning(); |
142 | QString queryServer(QString query, int timeout = -1); | 142 | QString queryServer(QString query, int timeout = -1); |
143 | QProcess serverProcess; | 143 | QProcess serverProcess; |
144 | QStringList voices; | 144 | QStringList voices; |
145 | QMap<QString, QString> voiceDescriptions; | 145 | QMap<QString, QString> voiceDescriptions; |
146 | }; | 146 | }; |
147 | 147 | ||
148 | #endif | 148 | #endif |
diff --git a/rbutil/rbutilqt/ttsgui.cpp b/rbutil/rbutilqt/ttsgui.cpp index 45dd3a86ef..cd4dab1fcf 100644 --- a/rbutil/rbutilqt/ttsgui.cpp +++ b/rbutil/rbutilqt/ttsgui.cpp | |||
@@ -16,13 +16,13 @@ | |||
16 | * KIND, either express or implied. | 16 | * KIND, either express or implied. |
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #include "ttsgui.h" | 20 | #include "ttsgui.h" |
21 | 21 | ||
22 | #include "rbsettings.h" | 22 | #include "rbsettings.h" |
23 | #include "tts.h" | 23 | #include "tts.h" |
24 | #include "browsedirtree.h" | 24 | #include "browsedirtree.h" |
25 | 25 | ||
26 | TTSSapiGui::TTSSapiGui(TTSSapi* sapi,QDialog* parent) : QDialog(parent) | 26 | TTSSapiGui::TTSSapiGui(TTSSapi* sapi,QDialog* parent) : QDialog(parent) |
27 | { | 27 | { |
28 | m_sapi= sapi; | 28 | m_sapi= sapi; |
@@ -31,46 +31,46 @@ TTSSapiGui::TTSSapiGui(TTSSapi* sapi,QDialog* parent) : QDialog(parent) | |||
31 | connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset())); | 31 | connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset())); |
32 | connect(ui.languagecombo,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateVoices(QString))); | 32 | connect(ui.languagecombo,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateVoices(QString))); |
33 | connect(ui.usesapi4,SIGNAL(stateChanged(int)),this,SLOT(useSapi4Changed(int))); | 33 | connect(ui.usesapi4,SIGNAL(stateChanged(int)),this,SLOT(useSapi4Changed(int))); |
34 | } | 34 | } |
35 | 35 | ||
36 | void TTSSapiGui::showCfg() | 36 | void TTSSapiGui::showCfg() |
37 | { | 37 | { |
38 | // try to get config from settings | 38 | // try to get config from settings |
39 | ui.ttsoptions->setText(settings->ttsOptions("sapi")); | 39 | ui.ttsoptions->setText(settings->ttsOptions("sapi")); |
40 | QString selLang = settings->ttsLang("sapi"); | 40 | QString selLang = settings->ttsLang("sapi"); |
41 | QString selVoice = settings->ttsVoice("sapi"); | 41 | QString selVoice = settings->ttsVoice("sapi"); |
42 | ui.speed->setValue(settings->ttsSpeed("sapi")); | 42 | ui.speed->setValue(settings->ttsSpeed("sapi")); |
43 | if(settings->ttsUseSapi4()) | 43 | if(settings->ttsUseSapi4()) |
44 | ui.usesapi4->setCheckState(Qt::Checked); | 44 | ui.usesapi4->setCheckState(Qt::Checked); |
45 | else | 45 | else |
46 | ui.usesapi4->setCheckState(Qt::Unchecked); | 46 | ui.usesapi4->setCheckState(Qt::Unchecked); |
47 | 47 | ||
48 | // fill in language combobox | 48 | // fill in language combobox |
49 | QStringList languages = settings->allLanguages(); | 49 | QStringList languages = settings->allLanguages(); |
50 | 50 | ||
51 | languages.sort(); | 51 | languages.sort(); |
52 | ui.languagecombo->clear(); | 52 | ui.languagecombo->clear(); |
53 | ui.languagecombo->addItems(languages); | 53 | ui.languagecombo->addItems(languages); |
54 | 54 | ||
55 | // set saved lang | 55 | // set saved lang |
56 | ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(selLang)); | 56 | ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(selLang)); |
57 | 57 | ||
58 | // fill in voice combobox | 58 | // fill in voice combobox |
59 | updateVoices(selLang); | 59 | updateVoices(selLang); |
60 | 60 | ||
61 | // set saved lang | 61 | // set saved lang |
62 | ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice)); | 62 | ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice)); |
63 | 63 | ||
64 | //show dialog | 64 | //show dialog |
65 | this->exec(); | 65 | this->exec(); |
66 | 66 | ||
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
70 | void TTSSapiGui::reset() | 70 | void TTSSapiGui::reset() |
71 | { | 71 | { |
72 | ui.ttsoptions->setText(""); | 72 | ui.ttsoptions->setText(""); |
73 | ui.languagecombo->setCurrentIndex(ui.languagecombo->findText("english")); | 73 | ui.languagecombo->setCurrentIndex(ui.languagecombo->findText("english")); |
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
@@ -101,7 +101,7 @@ void TTSSapiGui::updateVoices(QString language) | |||
101 | { | 101 | { |
102 | QStringList Voices = m_sapi->getVoiceList(language); | 102 | QStringList Voices = m_sapi->getVoiceList(language); |
103 | ui.voicecombo->clear(); | 103 | ui.voicecombo->clear(); |
104 | ui.voicecombo->addItems(Voices); | 104 | ui.voicecombo->addItems(Voices); |
105 | 105 | ||
106 | } | 106 | } |
107 | 107 | ||
@@ -114,7 +114,7 @@ void TTSSapiGui::useSapi4Changed(int) | |||
114 | // sync settings | 114 | // sync settings |
115 | settings->sync(); | 115 | settings->sync(); |
116 | updateVoices(ui.languagecombo->currentText()); | 116 | updateVoices(ui.languagecombo->currentText()); |
117 | 117 | ||
118 | } | 118 | } |
119 | 119 | ||
120 | TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent) | 120 | TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent) |
@@ -129,7 +129,7 @@ TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent) | |||
129 | void TTSExesGui::reset() | 129 | void TTSExesGui::reset() |
130 | { | 130 | { |
131 | ui.ttspath->setText(""); | 131 | ui.ttspath->setText(""); |
132 | ui.ttsoptions->setText(""); | 132 | ui.ttsoptions->setText(""); |
133 | } | 133 | } |
134 | 134 | ||
135 | void TTSExesGui::showCfg(QString name) | 135 | void TTSExesGui::showCfg(QString name) |
@@ -137,12 +137,12 @@ void TTSExesGui::showCfg(QString name) | |||
137 | m_name = name; | 137 | m_name = name; |
138 | // try to get config from settings | 138 | // try to get config from settings |
139 | QString exepath =settings->ttsPath(m_name); | 139 | QString exepath =settings->ttsPath(m_name); |
140 | ui.ttsoptions->setText(settings->ttsOptions(m_name)); | 140 | ui.ttsoptions->setText(settings->ttsOptions(m_name)); |
141 | ui.ttspath->setText(exepath); | 141 | ui.ttspath->setText(exepath); |
142 | 142 | ||
143 | //show dialog | 143 | //show dialog |
144 | this->exec(); | 144 | this->exec(); |
145 | 145 | ||
146 | } | 146 | } |
147 | 147 | ||
148 | void TTSExesGui::accept(void) | 148 | void TTSExesGui::accept(void) |
@@ -152,7 +152,7 @@ void TTSExesGui::accept(void) | |||
152 | settings->setTTSOptions(m_name,ui.ttsoptions->text()); | 152 | settings->setTTSOptions(m_name,ui.ttsoptions->text()); |
153 | // sync settings | 153 | // sync settings |
154 | settings->sync(); | 154 | settings->sync(); |
155 | 155 | ||
156 | this->done(0); | 156 | this->done(0); |
157 | } | 157 | } |
158 | 158 | ||
@@ -182,7 +182,7 @@ void TTSExesGui::browse() | |||
182 | } | 182 | } |
183 | 183 | ||
184 | TTSFestivalGui::TTSFestivalGui(TTSFestival* api, QDialog* parent) : | 184 | TTSFestivalGui::TTSFestivalGui(TTSFestival* api, QDialog* parent) : |
185 | QDialog(parent), festival(api) | 185 | QDialog(parent), festival(api) |
186 | { | 186 | { |
187 | ui.setupUi(this); | 187 | ui.setupUi(this); |
188 | this->setModal(true); | 188 | this->setModal(true); |
@@ -199,31 +199,31 @@ TTSFestivalGui::TTSFestivalGui(TTSFestival* api, QDialog* parent) : | |||
199 | 199 | ||
200 | void TTSFestivalGui::showCfg() | 200 | void TTSFestivalGui::showCfg() |
201 | { | 201 | { |
202 | qDebug() << "show\tpaths: " << settings->ttsPath("festival") << "\n" | 202 | qDebug() << "show\tpaths: " << settings->ttsPath("festival") << "\n" |
203 | << "\tvoice: " << settings->ttsVoice("festival"); | 203 | << "\tvoice: " << settings->ttsVoice("festival"); |
204 | 204 | ||
205 | // will populate the voices if the paths are correct, | 205 | // will populate the voices if the paths are correct, |
206 | // otherwise, it will require the user to press Refresh | 206 | // otherwise, it will require the user to press Refresh |
207 | updateVoices(); | 207 | updateVoices(); |
208 | 208 | ||
209 | // try to get config from settings | 209 | // try to get config from settings |
210 | QStringList paths = settings->ttsPath("festival").split(":"); | 210 | QStringList paths = settings->ttsPath("festival").split(":"); |
211 | if(paths.size() == 2) | 211 | if(paths.size() == 2) |
212 | { | 212 | { |
213 | ui.serverPath->setText(paths[0]); | 213 | ui.serverPath->setText(paths[0]); |
214 | ui.clientPath->setText(paths[1]); | 214 | ui.clientPath->setText(paths[1]); |
215 | } | 215 | } |
216 | 216 | ||
217 | this->setEnabled(true); | 217 | this->setEnabled(true); |
218 | this->exec(); | 218 | this->exec(); |
219 | } | 219 | } |
220 | 220 | ||
221 | void TTSFestivalGui::accept(void) | 221 | void TTSFestivalGui::accept(void) |
222 | { | 222 | { |
223 | //save settings in user config | 223 | //save settings in user config |
224 | QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); | 224 | QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); |
225 | qDebug() << "set\tpaths: " << newPath << "\n\tvoice: " << ui.voicesBox->currentText(); | 225 | qDebug() << "set\tpaths: " << newPath << "\n\tvoice: " << ui.voicesBox->currentText(); |
226 | settings->setTTSPath("festival", newPath); | 226 | settings->setTTSPath("festival", newPath); |
227 | settings->setTTSVoice("festival", ui.voicesBox->currentText()); | 227 | settings->setTTSVoice("festival", ui.voicesBox->currentText()); |
228 | 228 | ||
229 | settings->sync(); | 229 | settings->sync(); |
@@ -238,102 +238,103 @@ void TTSFestivalGui::reject(void) | |||
238 | 238 | ||
239 | void TTSFestivalGui::onBrowseClient() | 239 | void TTSFestivalGui::onBrowseClient() |
240 | { | 240 | { |
241 | BrowseDirtree browser(this); | 241 | BrowseDirtree browser(this); |
242 | browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); | 242 | browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); |
243 | 243 | ||
244 | QFileInfo currentPath(ui.clientPath->text().trimmed()); | 244 | QFileInfo currentPath(ui.clientPath->text().trimmed()); |
245 | if(currentPath.isDir()) | 245 | if(currentPath.isDir()) |
246 | { | 246 | { |
247 | browser.setDir(ui.clientPath->text()); | 247 | browser.setDir(ui.clientPath->text()); |
248 | } | 248 | } |
249 | else if (currentPath.isFile()) | 249 | else if (currentPath.isFile()) |
250 | { | 250 | { |
251 | browser.setDir(currentPath.dir().absolutePath()); | 251 | browser.setDir(currentPath.dir().absolutePath()); |
252 | } | 252 | } |
253 | if(browser.exec() == QDialog::Accepted) | 253 | if(browser.exec() == QDialog::Accepted) |
254 | { | 254 | { |
255 | qDebug() << browser.getSelected(); | 255 | qDebug() << browser.getSelected(); |
256 | QString exe = browser.getSelected(); | 256 | QString exe = browser.getSelected(); |
257 | if(!QFileInfo(exe).isExecutable()) | 257 | if(!QFileInfo(exe).isExecutable()) |
258 | return; | 258 | return; |
259 | ui.clientPath->setText(exe); | 259 | ui.clientPath->setText(exe); |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
263 | void TTSFestivalGui::onBrowseServer() | 263 | void TTSFestivalGui::onBrowseServer() |
264 | { | 264 | { |
265 | BrowseDirtree browser(this); | 265 | BrowseDirtree browser(this); |
266 | browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); | 266 | browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); |
267 | 267 | ||
268 | QFileInfo currentPath(ui.serverPath->text().trimmed()); | 268 | QFileInfo currentPath(ui.serverPath->text().trimmed()); |
269 | if(currentPath.isDir()) | 269 | if(currentPath.isDir()) |
270 | { | 270 | { |
271 | browser.setDir(ui.serverPath->text()); | 271 | browser.setDir(ui.serverPath->text()); |
272 | } | 272 | } |
273 | else if (currentPath.isFile()) | 273 | else if (currentPath.isFile()) |
274 | { | 274 | { |
275 | browser.setDir(currentPath.dir().absolutePath()); | 275 | browser.setDir(currentPath.dir().absolutePath()); |
276 | } | 276 | } |
277 | if(browser.exec() == QDialog::Accepted) | 277 | if(browser.exec() == QDialog::Accepted) |
278 | { | 278 | { |
279 | qDebug() << browser.getSelected(); | 279 | qDebug() << browser.getSelected(); |
280 | QString exe = browser.getSelected(); | 280 | QString exe = browser.getSelected(); |
281 | if(!QFileInfo(exe).isExecutable()) | 281 | if(!QFileInfo(exe).isExecutable()) |
282 | return; | 282 | return; |
283 | ui.serverPath->setText(exe); | 283 | ui.serverPath->setText(exe); |
284 | } | 284 | } |
285 | } | 285 | } |
286 | 286 | ||
287 | void TTSFestivalGui::onRefreshButton() | 287 | void TTSFestivalGui::onRefreshButton() |
288 | { | 288 | { |
289 | /* Temporarily commit the settings so that we get the new path when we check for voices */ | 289 | /* Temporarily commit the settings so that we get the new path when we check for voices */ |
290 | QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); | 290 | QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); |
291 | QString oldPath = settings->ttsPath("festival"); | 291 | QString oldPath = settings->ttsPath("festival"); |
292 | qDebug() << "new path: " << newPath << "\n" << "old path: " << oldPath << "\nuse new: " << (newPath != oldPath); | 292 | qDebug() << "new path: " << newPath << "\n" << "old path: " << oldPath << "\nuse new: " << (newPath != oldPath); |
293 | 293 | ||
294 | if(newPath != oldPath) | 294 | if(newPath != oldPath) |
295 | { | 295 | { |
296 | qDebug() << "Using new paths for getVoiceList"; | 296 | qDebug() << "Using new paths for getVoiceList"; |
297 | settings->setTTSPath("festival", newPath); | 297 | settings->setTTSPath("festival", newPath); |
298 | settings->sync(); | 298 | settings->sync(); |
299 | } | 299 | } |
300 | 300 | ||
301 | updateVoices(); | 301 | updateVoices(); |
302 | 302 | ||
303 | if(newPath != oldPath) | 303 | if(newPath != oldPath) |
304 | { | 304 | { |
305 | settings->setTTSPath("festival", oldPath); | 305 | settings->setTTSPath("festival", oldPath); |
306 | settings->sync(); | 306 | settings->sync(); |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | void TTSFestivalGui::onShowDescription(int state) | 310 | void TTSFestivalGui::onShowDescription(int state) |
311 | { | 311 | { |
312 | if(state == Qt::Unchecked) | 312 | if(state == Qt::Unchecked) |
313 | ui.descriptionLabel->setText(""); | 313 | ui.descriptionLabel->setText(""); |
314 | else | 314 | else |
315 | updateDescription(ui.voicesBox->currentText()); | 315 | updateDescription(ui.voicesBox->currentText()); |
316 | } | 316 | } |
317 | 317 | ||
318 | void TTSFestivalGui::updateVoices() | 318 | void TTSFestivalGui::updateVoices() |
319 | { | 319 | { |
320 | ui.voicesBox->clear(); | 320 | ui.voicesBox->clear(); |
321 | ui.voicesBox->addItem(tr("Loading..")); | 321 | ui.voicesBox->addItem(tr("Loading..")); |
322 | 322 | ||
323 | QStringList voiceList = festival->getVoiceList(); | 323 | QStringList voiceList = festival->getVoiceList(); |
324 | ui.voicesBox->clear(); | 324 | ui.voicesBox->clear(); |
325 | ui.voicesBox->addItems(voiceList); | 325 | ui.voicesBox->addItems(voiceList); |
326 | 326 | ||
327 | ui.voicesBox->setCurrentIndex(ui.voicesBox->findText(settings->ttsVoice("festival"))); | 327 | ui.voicesBox->setCurrentIndex(ui.voicesBox->findText(settings->ttsVoice("festival"))); |
328 | 328 | ||
329 | updateDescription(settings->ttsVoice("festival")); | 329 | updateDescription(settings->ttsVoice("festival")); |
330 | } | 330 | } |
331 | 331 | ||
332 | void TTSFestivalGui::updateDescription(QString value) | 332 | void TTSFestivalGui::updateDescription(QString value) |
333 | { | 333 | { |
334 | if(ui.showDescriptionCheckbox->checkState() == Qt::Checked) | 334 | if(ui.showDescriptionCheckbox->checkState() == Qt::Checked) |
335 | { | 335 | { |
336 | ui.descriptionLabel->setText(tr("Querying festival")); | 336 | ui.descriptionLabel->setText(tr("Querying festival")); |
337 | ui.descriptionLabel->setText(festival->getVoiceInfo(value)); | 337 | ui.descriptionLabel->setText(festival->getVoiceInfo(value)); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | |||
diff --git a/rbutil/rbutilqt/ttsgui.h b/rbutil/rbutilqt/ttsgui.h index ce7be408ad..693555cb6c 100644 --- a/rbutil/rbutilqt/ttsgui.h +++ b/rbutil/rbutilqt/ttsgui.h | |||
@@ -34,71 +34,72 @@ class TTSFestival; | |||
34 | 34 | ||
35 | class TTSSapiGui : public QDialog | 35 | class TTSSapiGui : public QDialog |
36 | { | 36 | { |
37 | Q_OBJECT | 37 | Q_OBJECT |
38 | public: | 38 | public: |
39 | TTSSapiGui(TTSSapi* sapi,QDialog* parent = NULL); | 39 | TTSSapiGui(TTSSapi* sapi,QDialog* parent = NULL); |
40 | 40 | ||
41 | void showCfg(); | 41 | void showCfg(); |
42 | void setCfg(RbSettings* sett){settings = sett;} | 42 | void setCfg(RbSettings* sett){settings = sett;} |
43 | public slots: | 43 | public slots: |
44 | 44 | ||
45 | virtual void accept(void); | 45 | virtual void accept(void); |
46 | virtual void reject(void); | 46 | virtual void reject(void); |
47 | virtual void reset(void); | 47 | virtual void reset(void); |
48 | void updateVoices(QString language); | 48 | void updateVoices(QString language); |
49 | void useSapi4Changed(int); | 49 | void useSapi4Changed(int); |
50 | private: | 50 | private: |
51 | Ui::SapiCfgFrm ui; | 51 | Ui::SapiCfgFrm ui; |
52 | RbSettings* settings; | 52 | RbSettings* settings; |
53 | TTSSapi* m_sapi; | 53 | TTSSapi* m_sapi; |
54 | }; | 54 | }; |
55 | 55 | ||
56 | class TTSExesGui : public QDialog | 56 | class TTSExesGui : public QDialog |
57 | { | 57 | { |
58 | Q_OBJECT | 58 | Q_OBJECT |
59 | public: | 59 | public: |
60 | TTSExesGui(QDialog* parent = NULL); | 60 | TTSExesGui(QDialog* parent = NULL); |
61 | 61 | ||
62 | void showCfg(QString m_name); | 62 | void showCfg(QString m_name); |
63 | void setCfg(RbSettings* sett){settings = sett;} | 63 | void setCfg(RbSettings* sett){settings = sett;} |
64 | 64 | ||
65 | public slots: | 65 | public slots: |
66 | virtual void accept(void); | 66 | virtual void accept(void); |
67 | virtual void reject(void); | 67 | virtual void reject(void); |
68 | virtual void reset(void); | 68 | virtual void reset(void); |
69 | void browse(void); | 69 | void browse(void); |
70 | private: | 70 | private: |
71 | Ui::TTSExesCfgFrm ui; | 71 | Ui::TTSExesCfgFrm ui; |
72 | RbSettings* settings; | 72 | RbSettings* settings; |
73 | QString m_name; | 73 | QString m_name; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | class TTSFestivalGui : public QDialog | 76 | class TTSFestivalGui : public QDialog |
77 | { | 77 | { |
78 | Q_OBJECT | 78 | Q_OBJECT |
79 | public: | 79 | public: |
80 | TTSFestivalGui(TTSFestival* festival, QDialog* parent = NULL); | 80 | TTSFestivalGui(TTSFestival* festival, QDialog* parent = NULL); |
81 | 81 | ||
82 | void showCfg(); | 82 | void showCfg(); |
83 | void setCfg(RbSettings* sett){settings = sett;} | 83 | void setCfg(RbSettings* sett){settings = sett;} |
84 | 84 | ||
85 | public slots: | 85 | public slots: |
86 | virtual void accept(void); | 86 | virtual void accept(void); |
87 | virtual void reject(void); | 87 | virtual void reject(void); |
88 | //virtual void reset(void); | 88 | //virtual void reset(void); |
89 | 89 | ||
90 | void onRefreshButton(); | 90 | void onRefreshButton(); |
91 | void onShowDescription(int state); | 91 | void onShowDescription(int state); |
92 | void onBrowseServer(); | 92 | void onBrowseServer(); |
93 | void onBrowseClient(); | 93 | void onBrowseClient(); |
94 | private: | 94 | private: |
95 | Ui::TTSFestivalCfgFrm ui; | 95 | Ui::TTSFestivalCfgFrm ui; |
96 | RbSettings* settings; | 96 | RbSettings* settings; |
97 | TTSFestival* festival; | 97 | TTSFestival* festival; |
98 | 98 | ||
99 | void updateVoices(); | 99 | void updateVoices(); |
100 | private slots: | 100 | private slots: |
101 | void updateDescription(QString value); | 101 | void updateDescription(QString value); |
102 | }; | 102 | }; |
103 | 103 | ||
104 | #endif | 104 | #endif |
105 | |||
diff --git a/rbutil/rbutilqt/voicefile.cpp b/rbutil/rbutilqt/voicefile.cpp index 6a04107cea..873329a47b 100644 --- a/rbutil/rbutilqt/voicefile.cpp +++ b/rbutil/rbutilqt/voicefile.cpp | |||
@@ -40,15 +40,15 @@ bool VoiceFileCreator::createVoiceFile(ProgressloggerInterface* logger) | |||
40 | m_abort = false; | 40 | m_abort = false; |
41 | m_logger = logger; | 41 | m_logger = logger; |
42 | m_logger->addItem(tr("Starting Voicefile generation"),LOGINFO); | 42 | m_logger->addItem(tr("Starting Voicefile generation"),LOGINFO); |
43 | 43 | ||
44 | // test if tempdir exists | 44 | // test if tempdir exists |
45 | if(!QDir(QDir::tempPath()+"/rbvoice/").exists()) | 45 | if(!QDir(QDir::tempPath()+"/rbvoice/").exists()) |
46 | { | 46 | { |
47 | QDir(QDir::tempPath()).mkdir("rbvoice"); | 47 | QDir(QDir::tempPath()).mkdir("rbvoice"); |
48 | } | 48 | } |
49 | 49 | ||
50 | m_path = QDir::tempPath() + "/rbvoice/"; | 50 | m_path = QDir::tempPath() + "/rbvoice/"; |
51 | 51 | ||
52 | // read rockbox-info.txt | 52 | // read rockbox-info.txt |
53 | RockboxInfo info(m_mountpoint); | 53 | RockboxInfo info(m_mountpoint); |
54 | if(!info.open()) | 54 | if(!info.open()) |
@@ -58,18 +58,18 @@ bool VoiceFileCreator::createVoiceFile(ProgressloggerInterface* logger) | |||
58 | emit done(false); | 58 | emit done(false); |
59 | return false; | 59 | return false; |
60 | } | 60 | } |
61 | 61 | ||
62 | QString target = info.target(); | 62 | QString target = info.target(); |
63 | QString features = info.features(); | 63 | QString features = info.features(); |
64 | QString version = info.version(); | 64 | QString version = info.version(); |
65 | version = version.left(version.indexOf("-")).remove(0,1); | 65 | version = version.left(version.indexOf("-")).remove(0,1); |
66 | 66 | ||
67 | //prepare download url | 67 | //prepare download url |
68 | QUrl genlangUrl = settings->genlangUrl() +"?lang=" +m_lang+"&t="+target+"&rev="+version+"&f="+features; | 68 | QUrl genlangUrl = settings->genlangUrl() +"?lang=" +m_lang+"&t="+target+"&rev="+version+"&f="+features; |
69 | 69 | ||
70 | qDebug() << "downloading " << genlangUrl; | 70 | qDebug() << "downloading " << genlangUrl; |
71 | 71 | ||
72 | //download the correct genlang output | 72 | //download the correct genlang output |
73 | QTemporaryFile *downloadFile = new QTemporaryFile(this); | 73 | QTemporaryFile *downloadFile = new QTemporaryFile(this); |
74 | downloadFile->open(); | 74 | downloadFile->open(); |
75 | filename = downloadFile->fileName(); | 75 | filename = downloadFile->fileName(); |
@@ -77,11 +77,11 @@ bool VoiceFileCreator::createVoiceFile(ProgressloggerInterface* logger) | |||
77 | // get the real file. | 77 | // get the real file. |
78 | getter = new HttpGet(this); | 78 | getter = new HttpGet(this); |
79 | getter->setFile(downloadFile); | 79 | getter->setFile(downloadFile); |
80 | 80 | ||
81 | connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool))); | 81 | connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool))); |
82 | connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int))); | 82 | connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int))); |
83 | connect(m_logger, SIGNAL(aborted()), getter, SLOT(abort())); | 83 | connect(m_logger, SIGNAL(aborted()), getter, SLOT(abort())); |
84 | 84 | ||
85 | getter->getFile(genlangUrl); | 85 | getter->getFile(genlangUrl); |
86 | return true; | 86 | return true; |
87 | } | 87 | } |
@@ -113,9 +113,9 @@ void VoiceFileCreator::downloadDone(bool error) | |||
113 | } | 113 | } |
114 | else m_logger->addItem(tr("Download finished."),LOGOK); | 114 | else m_logger->addItem(tr("Download finished."),LOGOK); |
115 | QCoreApplication::processEvents(); | 115 | QCoreApplication::processEvents(); |
116 | 116 | ||
117 | 117 | ||
118 | m_logger->setProgressMax(0); | 118 | m_logger->setProgressMax(0); |
119 | //open downloaded file | 119 | //open downloaded file |
120 | QFile genlang(filename); | 120 | QFile genlang(filename); |
121 | if(!genlang.open(QIODevice::ReadOnly)) | 121 | if(!genlang.open(QIODevice::ReadOnly)) |
@@ -124,12 +124,12 @@ void VoiceFileCreator::downloadDone(bool error) | |||
124 | m_logger->abort(); | 124 | m_logger->abort(); |
125 | emit done(false); | 125 | emit done(false); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | 128 | ||
129 | //tts | 129 | //tts |
130 | m_tts = TTSBase::getTTS(settings->curTTS()); | 130 | m_tts = TTSBase::getTTS(settings->curTTS()); |
131 | m_tts->setCfg(settings); | 131 | m_tts->setCfg(settings); |
132 | 132 | ||
133 | QString errStr; | 133 | QString errStr; |
134 | if(!m_tts->start(&errStr)) | 134 | if(!m_tts->start(&errStr)) |
135 | { | 135 | { |
@@ -141,9 +141,9 @@ void VoiceFileCreator::downloadDone(bool error) | |||
141 | } | 141 | } |
142 | 142 | ||
143 | // Encoder | 143 | // Encoder |
144 | m_enc = EncBase::getEncoder(settings->curEncoder()); | 144 | m_enc = EncBase::getEncoder(settings->curEncoder()); |
145 | m_enc->setCfg(settings); | 145 | m_enc->setCfg(settings); |
146 | 146 | ||
147 | if(!m_enc->start()) | 147 | if(!m_enc->start()) |
148 | { | 148 | { |
149 | m_logger->addItem(tr("Init of Encoder engine failed"),LOGERROR); | 149 | m_logger->addItem(tr("Init of Encoder engine failed"),LOGERROR); |
@@ -155,15 +155,15 @@ void VoiceFileCreator::downloadDone(bool error) | |||
155 | 155 | ||
156 | QCoreApplication::processEvents(); | 156 | QCoreApplication::processEvents(); |
157 | connect(m_logger,SIGNAL(aborted()),this,SLOT(abort())); | 157 | connect(m_logger,SIGNAL(aborted()),this,SLOT(abort())); |
158 | 158 | ||
159 | //read in downloaded file | 159 | //read in downloaded file |
160 | QList<QPair<QString,QString> > voicepairs; | 160 | QList<QPair<QString,QString> > voicepairs; |
161 | QTextStream in(&genlang); | 161 | QTextStream in(&genlang); |
162 | in.setCodec("UTF-8"); | 162 | in.setCodec("UTF-8"); |
163 | QString id, voice; | 163 | QString id, voice; |
164 | bool idfound = false; | 164 | bool idfound = false; |
165 | bool voicefound=false; | 165 | bool voicefound=false; |
166 | while (!in.atEnd()) | 166 | while (!in.atEnd()) |
167 | { | 167 | { |
168 | QString line = in.readLine(); | 168 | QString line = in.readLine(); |
169 | if(line.contains("id:")) //ID found | 169 | if(line.contains("id:")) //ID found |
@@ -176,58 +176,58 @@ void VoiceFileCreator::downloadDone(bool error) | |||
176 | voice = line.remove("voice:").remove('"').trimmed(); | 176 | voice = line.remove("voice:").remove('"').trimmed(); |
177 | voicefound=true; | 177 | voicefound=true; |
178 | } | 178 | } |
179 | 179 | ||
180 | if(idfound && voicefound) | 180 | if(idfound && voicefound) |
181 | { | 181 | { |
182 | voicepairs.append(QPair<QString,QString>(id,voice)); | 182 | voicepairs.append(QPair<QString,QString>(id,voice)); |
183 | idfound=false; | 183 | idfound=false; |
184 | voicefound=false; | 184 | voicefound=false; |
185 | } | 185 | } |
186 | } | 186 | } |
187 | genlang.close(); | 187 | genlang.close(); |
188 | 188 | ||
189 | // check for empty list | 189 | // check for empty list |
190 | if(voicepairs.size() == 0) | 190 | if(voicepairs.size() == 0) |
191 | { | 191 | { |
192 | m_logger->addItem(tr("The downloaded file was empty!"),LOGERROR); | 192 | m_logger->addItem(tr("The downloaded file was empty!"),LOGERROR); |
193 | m_logger->abort(); | 193 | m_logger->abort(); |
194 | m_tts->stop(); | 194 | m_tts->stop(); |
195 | emit done(false); | 195 | emit done(false); |
196 | return; | 196 | return; |
197 | } | 197 | } |
198 | 198 | ||
199 | m_logger->setProgressMax(voicepairs.size()); | 199 | m_logger->setProgressMax(voicepairs.size()); |
200 | m_logger->setProgressValue(0); | 200 | m_logger->setProgressValue(0); |
201 | 201 | ||
202 | // create voice clips | 202 | // create voice clips |
203 | QStringList mp3files; | 203 | QStringList mp3files; |
204 | for(int i=0; i< voicepairs.size(); i++) | 204 | for(int i=0; i< voicepairs.size(); i++) |
205 | { | 205 | { |
206 | if(m_abort) | 206 | if(m_abort) |
207 | { | 207 | { |
208 | m_logger->addItem("aborted.",LOGERROR); | 208 | m_logger->addItem("aborted.",LOGERROR); |
209 | m_logger->abort(); | 209 | m_logger->abort(); |
210 | m_tts->stop(); | 210 | m_tts->stop(); |
211 | emit done(false); | 211 | emit done(false); |
212 | return; | 212 | return; |
213 | } | 213 | } |
214 | 214 | ||
215 | m_logger->setProgressValue(i); | 215 | m_logger->setProgressValue(i); |
216 | 216 | ||
217 | QString wavname = m_path + "/" + voicepairs.at(i).first + ".wav"; | 217 | QString wavname = m_path + "/" + voicepairs.at(i).first + ".wav"; |
218 | QString toSpeak = voicepairs.at(i).second; | 218 | QString toSpeak = voicepairs.at(i).second; |
219 | QString encodedname = m_path + "/" + voicepairs.at(i).first +".mp3"; | 219 | QString encodedname = m_path + "/" + voicepairs.at(i).first +".mp3"; |
220 | 220 | ||
221 | // todo PAUSE | 221 | // todo PAUSE |
222 | if(voicepairs.at(i).first == "VOICE_PAUSE") | 222 | if(voicepairs.at(i).first == "VOICE_PAUSE") |
223 | { | 223 | { |
224 | QFile::copy(":/builtin/builtin/VOICE_PAUSE.wav",m_path + "/VOICE_PAUSE.wav"); | 224 | QFile::copy(":/builtin/builtin/VOICE_PAUSE.wav",m_path + "/VOICE_PAUSE.wav"); |
225 | 225 | ||
226 | } | 226 | } |
227 | else | 227 | else |
228 | { | 228 | { |
229 | if(toSpeak == "") continue; | 229 | if(toSpeak == "") continue; |
230 | 230 | ||
231 | m_logger->addItem(tr("creating ")+toSpeak,LOGINFO); | 231 | m_logger->addItem(tr("creating ")+toSpeak,LOGINFO); |
232 | QCoreApplication::processEvents(); | 232 | QCoreApplication::processEvents(); |
233 | 233 | ||
@@ -235,26 +235,26 @@ void VoiceFileCreator::downloadDone(bool error) | |||
235 | QString errStr; | 235 | QString errStr; |
236 | m_tts->voice(toSpeak,wavname, &errStr); // generate wav | 236 | m_tts->voice(toSpeak,wavname, &errStr); // generate wav |
237 | } | 237 | } |
238 | 238 | ||
239 | // todo strip | 239 | // todo strip |
240 | char buffer[255]; | 240 | char buffer[255]; |
241 | 241 | ||
242 | wavtrim((char*)qPrintable(wavname),m_wavtrimThreshold,buffer,255); | 242 | wavtrim((char*)qPrintable(wavname),m_wavtrimThreshold,buffer,255); |
243 | 243 | ||
244 | // encode wav | 244 | // encode wav |
245 | m_enc->encode(wavname,encodedname); | 245 | m_enc->encode(wavname,encodedname); |
246 | // remove the wav file | 246 | // remove the wav file |
247 | QFile::remove(wavname); | 247 | QFile::remove(wavname); |
248 | // remember the mp3 file for later removing | 248 | // remember the mp3 file for later removing |
249 | mp3files << encodedname; | 249 | mp3files << encodedname; |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | //make voicefile | 253 | //make voicefile |
254 | FILE* ids2 = fopen(filename.toUtf8(), "r"); | 254 | FILE* ids2 = fopen(filename.toUtf8(), "r"); |
255 | if (ids2 == NULL) | 255 | if (ids2 == NULL) |
256 | { | 256 | { |
257 | m_logger->addItem(tr("Error opening downloaded file"),LOGERROR); | 257 | m_logger->addItem(tr("Error opening downloaded file"),LOGERROR); |
258 | m_logger->abort(); | 258 | m_logger->abort(); |
259 | emit done(false); | 259 | emit done(false); |
260 | return; | 260 | return; |
@@ -263,32 +263,32 @@ void VoiceFileCreator::downloadDone(bool error) | |||
263 | FILE* output = fopen(QString(m_mountpoint + "/.rockbox/langs/" + m_lang + ".voice").toUtf8(), "wb"); | 263 | FILE* output = fopen(QString(m_mountpoint + "/.rockbox/langs/" + m_lang + ".voice").toUtf8(), "wb"); |
264 | if (output == NULL) | 264 | if (output == NULL) |
265 | { | 265 | { |
266 | m_logger->addItem(tr("Error opening output file"),LOGERROR); | 266 | m_logger->addItem(tr("Error opening output file"),LOGERROR); |
267 | emit done(false); | 267 | emit done(false); |
268 | return; | 268 | return; |
269 | } | 269 | } |
270 | 270 | ||
271 | voicefont(ids2,m_targetid,(char*)(const char*)m_path.toUtf8(), output); | 271 | voicefont(ids2,m_targetid,(char*)(const char*)m_path.toUtf8(), output); |
272 | 272 | ||
273 | //remove .mp3 files | 273 | //remove .mp3 files |
274 | for(int i=0;i< mp3files.size(); i++) | 274 | for(int i=0;i< mp3files.size(); i++) |
275 | { | 275 | { |
276 | QFile::remove(mp3files.at(i)); | 276 | QFile::remove(mp3files.at(i)); |
277 | } | 277 | } |
278 | 278 | ||
279 | // Add Voice file to the install log | 279 | // Add Voice file to the install log |
280 | QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0); | 280 | QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0); |
281 | installlog.beginGroup("selfcreated Voice"); | 281 | installlog.beginGroup("selfcreated Voice"); |
282 | installlog.setValue("/.rockbox/langs/" + m_lang + ".voice",QDate::currentDate().toString("yyyyMMdd")); | 282 | installlog.setValue("/.rockbox/langs/" + m_lang + ".voice",QDate::currentDate().toString("yyyyMMdd")); |
283 | installlog.endGroup(); | 283 | installlog.endGroup(); |
284 | installlog.sync(); | 284 | installlog.sync(); |
285 | 285 | ||
286 | m_logger->setProgressMax(100); | 286 | m_logger->setProgressMax(100); |
287 | m_logger->setProgressValue(100); | 287 | m_logger->setProgressValue(100); |
288 | m_logger->addItem(tr("successfully created."),LOGOK); | 288 | m_logger->addItem(tr("successfully created."),LOGOK); |
289 | m_logger->abort(); | 289 | m_logger->abort(); |
290 | 290 | ||
291 | emit done(true); | 291 | emit done(true); |
292 | } | 292 | } |
293 | 293 | ||
294 | void VoiceFileCreator::updateDataReadProgress(int read, int total) | 294 | void VoiceFileCreator::updateDataReadProgress(int read, int total) |
diff --git a/rbutil/rbutilqt/voicefile.h b/rbutil/rbutilqt/voicefile.h index df4ebaccfd..39205db756 100644 --- a/rbutil/rbutilqt/voicefile.h +++ b/rbutil/rbutilqt/voicefile.h | |||
@@ -45,39 +45,40 @@ public: | |||
45 | 45 | ||
46 | // set infos | 46 | // set infos |
47 | void setSettings(RbSettings* sett) { settings = sett;} | 47 | void setSettings(RbSettings* sett) { settings = sett;} |
48 | 48 | ||
49 | void setMountPoint(QString mountpoint) {m_mountpoint =mountpoint; } | 49 | void setMountPoint(QString mountpoint) {m_mountpoint =mountpoint; } |
50 | void setTargetId(int id){m_targetid = id;} | 50 | void setTargetId(int id){m_targetid = id;} |
51 | void setLang(QString name){m_lang =name;} | 51 | void setLang(QString name){m_lang =name;} |
52 | void setWavtrimThreshold(int th){m_wavtrimThreshold = th;} | 52 | void setWavtrimThreshold(int th){m_wavtrimThreshold = th;} |
53 | 53 | ||
54 | signals: | 54 | signals: |
55 | void done(bool error); | 55 | void done(bool error); |
56 | 56 | ||
57 | private slots: | 57 | private slots: |
58 | void abort(); | 58 | void abort(); |
59 | void downloadDone(bool error); | 59 | void downloadDone(bool error); |
60 | void updateDataReadProgress(int read, int total); | 60 | void updateDataReadProgress(int read, int total); |
61 | 61 | ||
62 | private: | 62 | private: |
63 | 63 | ||
64 | // ptr to encoder, tts and settings | 64 | // ptr to encoder, tts and settings |
65 | TTSBase* m_tts; | 65 | TTSBase* m_tts; |
66 | EncBase* m_enc; | 66 | EncBase* m_enc; |
67 | RbSettings* settings; | 67 | RbSettings* settings; |
68 | HttpGet *getter; | 68 | HttpGet *getter; |
69 | 69 | ||
70 | QString filename; //the temporary file | 70 | QString filename; //the temporary file |
71 | 71 | ||
72 | QString m_mountpoint; //mountpoint of the device | 72 | QString m_mountpoint; //mountpoint of the device |
73 | QString m_path; //path where the wav and mp3 files are stored to | 73 | QString m_path; //path where the wav and mp3 files are stored to |
74 | int m_targetid; //the target id | 74 | int m_targetid; //the target id |
75 | QString m_lang; // the language which will be spoken | 75 | QString m_lang; // the language which will be spoken |
76 | int m_wavtrimThreshold; | 76 | int m_wavtrimThreshold; |
77 | 77 | ||
78 | ProgressloggerInterface* m_logger; | 78 | ProgressloggerInterface* m_logger; |
79 | 79 | ||
80 | bool m_abort; | 80 | bool m_abort; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | #endif | 83 | #endif |
84 | |||