diff options
-rw-r--r-- | rbutil/talkfile.cpp | 204 | ||||
-rw-r--r-- | rbutil/talkfile.h | 101 |
2 files changed, 305 insertions, 0 deletions
diff --git a/rbutil/talkfile.cpp b/rbutil/talkfile.cpp new file mode 100644 index 0000000000..869432a8d5 --- /dev/null +++ b/rbutil/talkfile.cpp | |||
@@ -0,0 +1,204 @@ | |||
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 | |||
23 | TalkFileCreator::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 | |||
33 | bool TalkFileCreator::initEncoder() | ||
34 | { | ||
35 | if(::wxFileExists(m_EncExec)) | ||
36 | { | ||
37 | return true; | ||
38 | } | ||
39 | else | ||
40 | { | ||
41 | return false; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | bool TalkFileCreator::initTTS() | ||
46 | { | ||
47 | if(::wxFileExists(m_TTSexec)) | ||
48 | { | ||
49 | return true; | ||
50 | } | ||
51 | else | ||
52 | { | ||
53 | return false; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | bool 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 | |||
81 | bool 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 | |||
97 | bool 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 | |||
114 | wxString TalkFileCreator::getTTsOpts(wxString ttsname) | ||
115 | { | ||
116 | int index = m_supportedTTS.Index(ttsname); | ||
117 | |||
118 | return m_supportedTTSOpts[index]; | ||
119 | } | ||
120 | |||
121 | wxString TalkFileCreator::getEncOpts(wxString encname) | ||
122 | { | ||
123 | int index = m_supportedEnc.Index(encname); | ||
124 | |||
125 | return m_supportedEncOpts[index]; | ||
126 | } | ||
127 | |||
128 | wxDirTraverseResult 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 | |||
171 | wxDirTraverseResult 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 | } | ||
diff --git a/rbutil/talkfile.h b/rbutil/talkfile.h new file mode 100644 index 0000000000..196c923029 --- /dev/null +++ b/rbutil/talkfile.h | |||
@@ -0,0 +1,101 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * Module: rbutil | ||
9 | * File: tts.h | ||
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 | |||
22 | #ifndef _TALKFILE_H | ||
23 | #define _TALKFILE_H | ||
24 | |||
25 | #include "rbutil.h" | ||
26 | |||
27 | class TalkFileCreator | ||
28 | { | ||
29 | friend class TalkTraverser; | ||
30 | public: | ||
31 | TalkFileCreator(); | ||
32 | ~TalkFileCreator() {}; | ||
33 | |||
34 | bool createTalkFiles(); | ||
35 | |||
36 | void setTTSexe(wxString exe){m_TTSexec=exe;} | ||
37 | void setEncexe(wxString exe){m_EncExec=exe;} | ||
38 | |||
39 | wxArrayString getSupportedTTS(){return m_supportedTTS;} | ||
40 | bool setTTsType(wxString tts) {m_curTTS = tts; } | ||
41 | wxString getTTsOpts(wxString ttsname); | ||
42 | void setTTsOpts(wxString opts) {m_TTSOpts=opts;} | ||
43 | |||
44 | wxArrayString getSupportedEnc(){return m_supportedEnc;} | ||
45 | bool setEncType(wxString enc) {m_curEnc =enc; } | ||
46 | wxString getEncOpts(wxString encname); | ||
47 | void setEncOpts(wxString opts) {m_EncOpts=opts;} | ||
48 | |||
49 | void setDir(wxString dir){m_dir = dir; } | ||
50 | |||
51 | void setOverwriteTalk(bool ov) {m_overwriteTalk = ov;} | ||
52 | void setOverwriteWav(bool ov) {m_overwriteWav = ov;} | ||
53 | void setRemoveWav(bool ov) {m_removeWav = ov;} | ||
54 | void setRecursive(bool ov) {m_recursive = ov;} | ||
55 | void setStripExtensions(bool ov) {m_stripExtensions = ov;} | ||
56 | |||
57 | private: | ||
58 | |||
59 | bool initTTS(); | ||
60 | bool stopTTS(); | ||
61 | bool initEncoder(); | ||
62 | |||
63 | bool encode(wxString input,wxString output); | ||
64 | bool voice(wxString text,wxString wavfile); | ||
65 | |||
66 | wxString m_dir; | ||
67 | |||
68 | wxString m_curTTS; | ||
69 | wxString m_TTSexec; | ||
70 | wxArrayString m_supportedTTS; | ||
71 | wxArrayString m_supportedTTSOpts; | ||
72 | wxString m_TTSOpts; | ||
73 | |||
74 | wxString m_curEnc; | ||
75 | wxString m_EncExec; | ||
76 | wxArrayString m_supportedEnc; | ||
77 | wxArrayString m_supportedEncOpts; | ||
78 | wxString m_EncOpts; | ||
79 | |||
80 | bool m_overwriteTalk; | ||
81 | bool m_overwriteWav; | ||
82 | bool m_removeWav; | ||
83 | bool m_recursive; | ||
84 | bool m_stripExtensions; | ||
85 | }; | ||
86 | |||
87 | |||
88 | class TalkTraverser: public wxDirTraverser | ||
89 | { | ||
90 | public: | ||
91 | TalkTraverser(TalkFileCreator* talkcreator) : m_talkcreator(talkcreator) { } | ||
92 | |||
93 | virtual wxDirTraverseResult OnFile(const wxString& filename); | ||
94 | |||
95 | virtual wxDirTraverseResult OnDir(const wxString& dirname); | ||
96 | |||
97 | private: | ||
98 | TalkFileCreator* m_talkcreator; | ||
99 | }; | ||
100 | |||
101 | #endif | ||