summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rbutil/rbutilqt/base/ttsbase.h2
-rw-r--r--rbutil/rbutilqt/base/ttscarbon.cpp49
-rw-r--r--rbutil/rbutilqt/configure.cpp33
3 files changed, 48 insertions, 36 deletions
diff --git a/rbutil/rbutilqt/base/ttsbase.h b/rbutil/rbutilqt/base/ttsbase.h
index f04016c85f..c6bbdcfb0b 100644
--- a/rbutil/rbutilqt/base/ttsbase.h
+++ b/rbutil/rbutilqt/base/ttsbase.h
@@ -36,7 +36,7 @@ class TTSBase : public EncTtsSettingInterface
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 public: 38 public:
39 enum Capability { None = 0, RunInParallel = 1 }; 39 enum Capability { None = 0, RunInParallel = 1, CanSpeak = 2 };
40 Q_DECLARE_FLAGS(Capabilities, Capability) 40 Q_DECLARE_FLAGS(Capabilities, Capability)
41 41
42 TTSBase(QObject *parent); 42 TTSBase(QObject *parent);
diff --git a/rbutil/rbutilqt/base/ttscarbon.cpp b/rbutil/rbutilqt/base/ttscarbon.cpp
index 63fb5315e3..ba744b5fcf 100644
--- a/rbutil/rbutilqt/base/ttscarbon.cpp
+++ b/rbutil/rbutilqt/base/ttscarbon.cpp
@@ -36,7 +36,7 @@ TTSCarbon::TTSCarbon(QObject* parent) : TTSBase(parent)
36 36
37TTSBase::Capabilities TTSCarbon::capabilities() 37TTSBase::Capabilities TTSCarbon::capabilities()
38{ 38{
39 return None; 39 return TTSBase::CanSpeak;
40} 40}
41 41
42bool TTSCarbon::configOk() 42bool TTSCarbon::configOk()
@@ -75,7 +75,7 @@ bool TTSCarbon::start(QString *errStr)
75 if(voiceIndex == numVoices) { 75 if(voiceIndex == numVoices) {
76 // voice not found. Add user notification here and proceed with 76 // voice not found. Add user notification here and proceed with
77 // system default voice. 77 // system default voice.
78 qDebug() << "selected voice not found, using system default!"; 78 qDebug() << "[TTSCarbon] Selected voice not found, using system default!";
79 GetVoiceDescription(&vspec, &vdesc, sizeof(vdesc)); 79 GetVoiceDescription(&vspec, &vdesc, sizeof(vdesc));
80 if(vdesc.script != -1) 80 if(vdesc.script != -1)
81 m_voiceScript = (CFStringBuiltInEncodings)vdesc.script; 81 m_voiceScript = (CFStringBuiltInEncodings)vdesc.script;
@@ -160,18 +160,21 @@ TTSStatus TTSCarbon::voice(QString text, QString wavfile, QString* errStr)
160 TTSStatus status = NoError; 160 TTSStatus status = NoError;
161 OSErr error; 161 OSErr error;
162 162
163 QString aifffile = wavfile + ".aiff"; 163 char* tmpfile;
164 // FIXME: find out why we need to do this. 164 if(!wavfile.isEmpty()) {
165 // Create a local copy of the temporary file filename. 165 QString aifffile = wavfile + ".aiff";
166 // Not doing so causes weird issues (path contains trailing spaces) 166 // FIXME: find out why we need to do this.
167 unsigned int len = aifffile.size() + 1; 167 // Create a local copy of the temporary file filename.
168 char* tmpfile = (char*)malloc(len * sizeof(char)); 168 // Not doing so causes weird issues (path contains trailing spaces)
169 strncpy(tmpfile, aifffile.toLocal8Bit().constData(), len); 169 unsigned int len = aifffile.size() + 1;
170 CFStringRef tmpfileref = CFStringCreateWithCString(kCFAllocatorDefault, 170 tmpfile = (char*)malloc(len * sizeof(char));
171 tmpfile, kCFStringEncodingUTF8); 171 strncpy(tmpfile, aifffile.toLocal8Bit().constData(), len);
172 CFURLRef urlref = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, 172 CFStringRef tmpfileref = CFStringCreateWithCString(kCFAllocatorDefault,
173 tmpfileref, kCFURLPOSIXPathStyle, false); 173 tmpfile, kCFStringEncodingUTF8);
174 SetSpeechInfo(m_channel, soOutputToFileWithCFURL, urlref); 174 CFURLRef urlref = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
175 tmpfileref, kCFURLPOSIXPathStyle, false);
176 SetSpeechInfo(m_channel, soOutputToFileWithCFURL, urlref);
177 }
175 178
176 // speak it. 179 // speak it.
177 // Convert the string to the encoding requested by the voice. Do this 180 // Convert the string to the encoding requested by the voice. Do this
@@ -206,15 +209,17 @@ TTSStatus TTSCarbon::voice(QString text, QString wavfile, QString* errStr)
206 free(textbuf); 209 free(textbuf);
207 CFRelease(cfstring); 210 CFRelease(cfstring);
208 211
209 // convert the temporary aiff file to wav 212 if(!wavfile.isEmpty()) {
210 if(status == NoError 213 // convert the temporary aiff file to wav
211 && convertAiffToWav(tmpfile, wavfile.toLocal8Bit().constData()) != 0) { 214 if(status == NoError
212 *errStr = tr("Could not convert intermediate file"); 215 && convertAiffToWav(tmpfile, wavfile.toLocal8Bit().constData()) != 0) {
213 status = FatalError; 216 *errStr = tr("Could not convert intermediate file");
217 status = FatalError;
218 }
219 // remove temporary aiff file
220 unlink(tmpfile);
221 free(tmpfile);
214 } 222 }
215 // remove temporary aiff file
216 unlink(tmpfile);
217 free(tmpfile);
218 223
219 return status; 224 return status;
220} 225}
diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp
index 8bfa20e6a0..9b6376e469 100644
--- a/rbutil/rbutilqt/configure.cpp
+++ b/rbutil/rbutilqt/configure.cpp
@@ -731,14 +731,16 @@ void Config::testTts()
731{ 731{
732 QString errstr; 732 QString errstr;
733 int index = ui.comboTts->currentIndex(); 733 int index = ui.comboTts->currentIndex();
734 TTSBase* tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString()); 734 TTSBase* tts;
735
736 ui.testTTS->setEnabled(false);
737 tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString());
735 if(!tts->configOk()) 738 if(!tts->configOk())
736 { 739 {
737 QMessageBox::warning(this,tr("TTS configuration invalid"), 740 QMessageBox::warning(this,tr("TTS configuration invalid"),
738 tr("TTS configuration invalid. \n Please configure TTS engine.")); 741 tr("TTS configuration invalid. \n Please configure TTS engine."));
739 return; 742 return;
740 } 743 }
741 ui.testTTS->setEnabled(false);
742 if(!tts->start(&errstr)) 744 if(!tts->start(&errstr))
743 { 745 {
744 QMessageBox::warning(this,tr("Could not start TTS engine."), 746 QMessageBox::warning(this,tr("Could not start TTS engine."),
@@ -748,10 +750,13 @@ void Config::testTts()
748 return; 750 return;
749 } 751 }
750 752
751 QTemporaryFile file(this); 753 QString filename;
752 file.open(); 754 if(!(tts->capabilities() & TTSBase::CanSpeak)) {
753 QString filename = file.fileName(); 755 QTemporaryFile file(this);
754 file.close(); 756 file.open();
757 filename = file.fileName();
758 file.close();
759 }
755 760
756 if(tts->voice(tr("Rockbox Utility Voice Test"),filename,&errstr) == FatalError) 761 if(tts->voice(tr("Rockbox Utility Voice Test"),filename,&errstr) == FatalError)
757 { 762 {
@@ -763,16 +768,18 @@ void Config::testTts()
763 return; 768 return;
764 } 769 }
765 tts->stop(); 770 tts->stop();
771 if(!(tts->capabilities() & TTSBase::CanSpeak)) {
766#if defined(Q_OS_LINUX) 772#if defined(Q_OS_LINUX)
767 QString exe = Utils::findExecutable("aplay"); 773 QString exe = Utils::findExecutable("aplay");
768 if(exe == "") exe = Utils::findExecutable("play"); 774 if(exe == "") exe = Utils::findExecutable("play");
769 if(exe != "") 775 if(exe != "")
770 { 776 {
771 QProcess::execute(exe+" "+filename); 777 QProcess::execute(exe+" "+filename);
772 } 778 }
773#else 779#else
774 QSound::play(filename); 780 QSound::play(filename);
775#endif 781#endif
782 }
776 ui.testTTS->setEnabled(true); 783 ui.testTTS->setEnabled(true);
777 delete tts; /* Config objects are never deleted (in fact, they are 784 delete tts; /* Config objects are never deleted (in fact, they are
778 leaked..), so we can't rely on QObject, since that would 785 leaked..), so we can't rely on QObject, since that would