1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
11 * Copyright (C) 2007 Dominik wenger
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
23 TalkFileCreator::TalkFileCreator()
25 m_supportedTTS
.Add(wxT("espeak"));
26 m_supportedTTSOpts
.Add(wxT(""));
28 m_supportedEnc
.Add(wxT("lame"));
29 m_supportedEncOpts
.Add(wxT("--vbr-new -t --nores -S"));
33 bool TalkFileCreator::initEncoder()
35 if(::wxFileExists(m_EncExec
))
45 bool TalkFileCreator::initTTS()
47 if(::wxFileExists(m_TTSexec
))
57 bool TalkFileCreator::createTalkFiles()
61 MESG_DIALOG(wxT("Init of TTS engine failed") );
66 MESG_DIALOG(wxT("Init of encoder failed") );
72 TalkTraverser
traverser(this);
73 if(talkdir
.Traverse(traverser
) == (size_t)-1)
81 bool TalkFileCreator::voice(wxString text
,wxString wavfile
)
83 if(m_curTTS
== wxT("espeak"))
87 wxExecute(m_TTSexec
+wxT(" ")+m_TTSOpts
+wxT(" -w \"")+wavfile
+wxT("\" \"")+text
+wxT("\""),out
,err
);
92 MESG_DIALOG(wxT("Unsupported TTS engine") );
97 bool TalkFileCreator::encode(wxString input
,wxString output
)
99 if(m_curEnc
== wxT("lame"))
103 wxExecute(m_EncExec
+wxT(" ")+m_EncOpts
+wxT(" \"")+input
+wxT("\" \"")+output
+wxT("\""),out
,err
);
108 MESG_DIALOG(wxT("Unsupported encoder") );
114 wxString
TalkFileCreator::getTTsOpts(wxString ttsname
)
116 int index
= m_supportedTTS
.Index(ttsname
);
118 return m_supportedTTSOpts
[index
];
121 wxString
TalkFileCreator::getEncOpts(wxString encname
)
123 int index
= m_supportedEnc
.Index(encname
);
125 return m_supportedEncOpts
[index
];
128 wxDirTraverseResult
TalkTraverser::OnFile(const wxString
& file
)
130 if(file
.EndsWith(wxT(".talk")) || file
.EndsWith(wxT(".talk.wav")))
132 return wxDIR_CONTINUE
;
135 wxFileName
fname(file
);
137 if(m_talkcreator
->m_stripExtensions
)
139 toSpeak
= fname
.GetName();
143 toSpeak
= fname
.GetName()+fname
.GetExt();
145 wxString filename
= file
+ wxT(".talk");
146 wxString wavname
= filename
+ wxT(".wav");
148 if(!wxFileExists(filename
) || m_talkcreator
->m_overwriteTalk
)
150 if(!wxFileExists(wavname
) || m_talkcreator
->m_overwriteWav
)
152 if(!m_talkcreator
->voice(toSpeak
,wavname
))
157 if(!m_talkcreator
->encode(wavname
,filename
))
163 if(m_talkcreator
->m_removeWav
)
165 wxRemoveFile(wavname
);
168 return wxDIR_CONTINUE
;
171 wxDirTraverseResult
TalkTraverser::OnDir(const wxString
& dirname
)
173 wxFileName
fname(dirname
,wxEmptyString
);
174 wxArrayString dirs
=fname
.GetDirs();
175 wxString toSpeak
= dirs
[dirs
.GetCount()-1];
177 wxString filename
= dirname
+ wxT("" PATH_SEP
"_dirname.talk");
178 wxString wavname
= filename
+ wxT(".wav");
180 if(!wxFileExists(filename
) || m_talkcreator
->m_overwriteTalk
)
182 if(!wxFileExists(wavname
) || m_talkcreator
->m_overwriteWav
)
184 if(!m_talkcreator
->voice(toSpeak
,wavname
))
189 if(!m_talkcreator
->encode(wavname
,filename
))
195 if(m_talkcreator
->m_removeWav
)
197 wxRemoveFile(wavname
);
200 if(!m_talkcreator
->m_recursive
)
203 return wxDIR_CONTINUE
;