summaryrefslogtreecommitdiff
path: root/rbutil/talkfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/talkfile.cpp')
-rw-r--r--rbutil/talkfile.cpp204
1 files changed, 0 insertions, 204 deletions
diff --git a/rbutil/talkfile.cpp b/rbutil/talkfile.cpp
deleted file mode 100644
index 345b327802..0000000000
--- a/rbutil/talkfile.cpp
+++ /dev/null
@@ -1,204 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * Module: rbutil
9 * File: tts.cpp
10 *
11 * Copyright (C) 2007 Dominik wenger
12 *
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.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#include "talkfile.h"
22
23TalkFileCreator::TalkFileCreator()
24{
25 m_supportedTTS.Add(wxT("espeak"));
26 m_supportedTTSOpts.Add(wxT(""));
27
28 m_supportedEnc.Add(wxT("lame"));
29 m_supportedEncOpts.Add(wxT("--vbr-new -t --nores -S"));
30
31}
32
33bool TalkFileCreator::initEncoder()
34{
35 if(::wxFileExists(m_EncExec))
36 {
37 return true;
38 }
39 else
40 {
41 return false;
42 }
43}
44
45bool TalkFileCreator::initTTS()
46{
47 if(::wxFileExists(m_TTSexec))
48 {
49 return true;
50 }
51 else
52 {
53 return false;
54 }
55}
56
57bool TalkFileCreator::createTalkFiles()
58{
59 if(!initTTS())
60 {
61 MESG_DIALOG(wxT("Init of TTS engine failed") );
62 return false;
63 }
64 if(!initEncoder())
65 {
66 MESG_DIALOG(wxT("Init of encoder failed") );
67 return false;
68 }
69
70 // enumerate the dirs
71 wxDir talkdir(m_dir);
72 TalkTraverser traverser(this);
73 if(talkdir.Traverse(traverser) == (size_t)-1)
74 return false;
75 else
76 return true;
77
78
79}
80
81bool TalkFileCreator::voice(wxString text,wxString wavfile)
82{
83 if(m_curTTS == wxT("espeak"))
84 {
85 wxArrayString out;
86 wxArrayString err;
87 wxExecute(m_TTSexec+wxT(" ")+m_TTSOpts+wxT(" -w \"")+wavfile+wxT("\" \"")+text+wxT("\""),out,err);
88 return true;
89 }
90 else
91 {
92 MESG_DIALOG(wxT("Unsupported TTS engine") );
93 return false;
94 }
95}
96
97bool TalkFileCreator::encode(wxString input,wxString output)
98{
99 if(m_curEnc == wxT("lame"))
100 {
101 wxArrayString out;
102 wxArrayString err;
103 wxExecute(m_EncExec+wxT(" ")+m_EncOpts+wxT(" \"")+input+wxT("\" \"")+output+wxT("\""),out,err);
104 return true;
105 }
106 else
107 {
108 MESG_DIALOG(wxT("Unsupported encoder") );
109 return false;
110 }
111
112}
113
114wxString TalkFileCreator::getTTsOpts(wxString ttsname)
115{
116 int index = m_supportedTTS.Index(ttsname);
117
118 return m_supportedTTSOpts[index];
119}
120
121wxString TalkFileCreator::getEncOpts(wxString encname)
122{
123 int index = m_supportedEnc.Index(encname);
124
125 return m_supportedEncOpts[index];
126}
127
128wxDirTraverseResult TalkTraverser::OnFile(const wxString& file)
129{
130 if(file.EndsWith(wxT(".talk")) || file.EndsWith(wxT(".talk.wav")))
131 {
132 return wxDIR_CONTINUE;
133 }
134
135 wxFileName fname(file);
136 wxString toSpeak;
137 if(m_talkcreator->m_stripExtensions)
138 {
139 toSpeak = fname.GetName();
140 }
141 else
142 {
143 toSpeak = fname.GetName()+fname.GetExt();
144 }
145 wxString filename = file+ wxT(".talk");
146 wxString wavname = filename + wxT(".wav");
147
148 if(!wxFileExists(filename) || m_talkcreator->m_overwriteTalk)
149 {
150 if(!wxFileExists(wavname) || m_talkcreator->m_overwriteWav)
151 {
152 if(!m_talkcreator->voice(toSpeak,wavname))
153 {
154 return wxDIR_STOP;
155 }
156 }
157 if(!m_talkcreator->encode(wavname,filename))
158 {
159 return wxDIR_STOP;
160 }
161 }
162
163 if(m_talkcreator->m_removeWav)
164 {
165 wxRemoveFile(wavname);
166 }
167
168 return wxDIR_CONTINUE;
169}
170
171wxDirTraverseResult TalkTraverser::OnDir(const wxString& dirname)
172{
173 wxFileName fname(dirname,wxEmptyString);
174 wxArrayString dirs=fname.GetDirs();
175 wxString toSpeak = dirs[dirs.GetCount()-1];
176
177 wxString filename = dirname + wxT("" PATH_SEP "_dirname.talk");
178 wxString wavname = filename + wxT(".wav");
179
180 if(!wxFileExists(filename) || m_talkcreator->m_overwriteTalk)
181 {
182 if(!wxFileExists(wavname) || m_talkcreator->m_overwriteWav)
183 {
184 if(!m_talkcreator->voice(toSpeak,wavname))
185 {
186 return wxDIR_STOP;
187 }
188 }
189 if(!m_talkcreator->encode(wavname,filename))
190 {
191 return wxDIR_STOP;
192 }
193 }
194
195 if(m_talkcreator->m_removeWav)
196 {
197 wxRemoveFile(wavname);
198 }
199
200 if(!m_talkcreator->m_recursive)
201 return wxDIR_IGNORE;
202 else
203 return wxDIR_CONTINUE;
204}