mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-14 15:42:28 -05:00
rbutil: Oops, forgot the new files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13907 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
1ad4b2c809
commit
d4b484663c
2 changed files with 305 additions and 0 deletions
204
rbutil/talkfile.cpp
Normal file
204
rbutil/talkfile.cpp
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* Module: rbutil
|
||||
* File: tts.cpp
|
||||
*
|
||||
* Copyright (C) 2007 Dominik wenger
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "talkfile.h"
|
||||
|
||||
TalkFileCreator::TalkFileCreator()
|
||||
{
|
||||
m_supportedTTS.Add(wxT("espeak"));
|
||||
m_supportedTTSOpts.Add(wxT(""));
|
||||
|
||||
m_supportedEnc.Add(wxT("lame"));
|
||||
m_supportedEncOpts.Add(wxT("--vbr-new -t --nores -S"));
|
||||
|
||||
}
|
||||
|
||||
bool TalkFileCreator::initEncoder()
|
||||
{
|
||||
if(::wxFileExists(m_EncExec))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TalkFileCreator::initTTS()
|
||||
{
|
||||
if(::wxFileExists(m_TTSexec))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TalkFileCreator::createTalkFiles()
|
||||
{
|
||||
if(!initTTS())
|
||||
{
|
||||
MESG_DIALOG(wxT("Init of TTS engine failed") );
|
||||
return false;
|
||||
}
|
||||
if(!initEncoder())
|
||||
{
|
||||
MESG_DIALOG(wxT("Init of encoder failed") );
|
||||
return false;
|
||||
}
|
||||
|
||||
// enumerate the dirs
|
||||
wxDir talkdir(m_dir);
|
||||
TalkTraverser traverser(this);
|
||||
if(talkdir.Traverse(traverser) == (size_t)-1)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool TalkFileCreator::voice(wxString text,wxString wavfile)
|
||||
{
|
||||
if(m_curTTS == wxT("espeak"))
|
||||
{
|
||||
wxArrayString out;
|
||||
wxArrayString err;
|
||||
wxExecute(m_TTSexec+wxT(" ")+m_TTSOpts+wxT(" -w \"")+wavfile+wxT("\" \"")+text+wxT("\""),out,err);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
MESG_DIALOG(wxT("Unsupported TTS engine") );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TalkFileCreator::encode(wxString input,wxString output)
|
||||
{
|
||||
if(m_curEnc == wxT("lame"))
|
||||
{
|
||||
wxArrayString out;
|
||||
wxArrayString err;
|
||||
wxExecute(m_EncExec+wxT(" ")+m_EncOpts+wxT(" \"")+input+wxT("\" \"")+output+wxT("\""),out,err);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
MESG_DIALOG(wxT("Unsupported encoder") );
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wxString TalkFileCreator::getTTsOpts(wxString ttsname)
|
||||
{
|
||||
int index = m_supportedTTS.Index(ttsname);
|
||||
|
||||
return m_supportedTTSOpts[index];
|
||||
}
|
||||
|
||||
wxString TalkFileCreator::getEncOpts(wxString encname)
|
||||
{
|
||||
int index = m_supportedEnc.Index(encname);
|
||||
|
||||
return m_supportedEncOpts[index];
|
||||
}
|
||||
|
||||
wxDirTraverseResult TalkTraverser::OnFile(const wxString& file)
|
||||
{
|
||||
if(file.EndsWith(wxT(".talk")) || file.EndsWith(wxT(".talk.wav")))
|
||||
{
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
wxFileName fname(file);
|
||||
wxString toSpeak;
|
||||
if(m_talkcreator->m_stripExtensions)
|
||||
{
|
||||
toSpeak = fname.GetName();
|
||||
}
|
||||
else
|
||||
{
|
||||
toSpeak = fname.GetName()+fname.GetExt();
|
||||
}
|
||||
wxString filename = file+ wxT(".talk");
|
||||
wxString wavname = filename + wxT(".wav");
|
||||
|
||||
if(!wxFileExists(filename) || m_talkcreator->m_overwriteTalk)
|
||||
{
|
||||
if(!wxFileExists(wavname) || m_talkcreator->m_overwriteWav)
|
||||
{
|
||||
if(!m_talkcreator->voice(toSpeak,wavname))
|
||||
{
|
||||
return wxDIR_STOP;
|
||||
}
|
||||
}
|
||||
if(!m_talkcreator->encode(wavname,filename))
|
||||
{
|
||||
return wxDIR_STOP;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_talkcreator->m_removeWav)
|
||||
{
|
||||
wxRemoveFile(wavname);
|
||||
}
|
||||
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
wxDirTraverseResult TalkTraverser::OnDir(const wxString& dirname)
|
||||
{
|
||||
wxFileName fname(dirname,wxEmptyString);
|
||||
wxArrayString dirs=fname.GetDirs();
|
||||
wxString toSpeak = dirs[dirs.GetCount()-1];
|
||||
|
||||
wxString filename = dirname + wxT(PATH_SEP "_dirname.talk");
|
||||
wxString wavname = filename + wxT(".wav");
|
||||
|
||||
if(!wxFileExists(filename) || m_talkcreator->m_overwriteTalk)
|
||||
{
|
||||
if(!wxFileExists(wavname) || m_talkcreator->m_overwriteWav)
|
||||
{
|
||||
if(!m_talkcreator->voice(toSpeak,wavname))
|
||||
{
|
||||
return wxDIR_STOP;
|
||||
}
|
||||
}
|
||||
if(!m_talkcreator->encode(wavname,filename))
|
||||
{
|
||||
return wxDIR_STOP;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_talkcreator->m_removeWav)
|
||||
{
|
||||
wxRemoveFile(wavname);
|
||||
}
|
||||
|
||||
if(!m_talkcreator->m_recursive)
|
||||
return wxDIR_IGNORE;
|
||||
else
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
101
rbutil/talkfile.h
Normal file
101
rbutil/talkfile.h
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* Module: rbutil
|
||||
* File: tts.h
|
||||
*
|
||||
* Copyright (C) 2007 Dominik wenger
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef _TALKFILE_H
|
||||
#define _TALKFILE_H
|
||||
|
||||
#include "rbutil.h"
|
||||
|
||||
class TalkFileCreator
|
||||
{
|
||||
friend class TalkTraverser;
|
||||
public:
|
||||
TalkFileCreator();
|
||||
~TalkFileCreator() {};
|
||||
|
||||
bool createTalkFiles();
|
||||
|
||||
void setTTSexe(wxString exe){m_TTSexec=exe;}
|
||||
void setEncexe(wxString exe){m_EncExec=exe;}
|
||||
|
||||
wxArrayString getSupportedTTS(){return m_supportedTTS;}
|
||||
bool setTTsType(wxString tts) {m_curTTS = tts; }
|
||||
wxString getTTsOpts(wxString ttsname);
|
||||
void setTTsOpts(wxString opts) {m_TTSOpts=opts;}
|
||||
|
||||
wxArrayString getSupportedEnc(){return m_supportedEnc;}
|
||||
bool setEncType(wxString enc) {m_curEnc =enc; }
|
||||
wxString getEncOpts(wxString encname);
|
||||
void setEncOpts(wxString opts) {m_EncOpts=opts;}
|
||||
|
||||
void setDir(wxString dir){m_dir = dir; }
|
||||
|
||||
void setOverwriteTalk(bool ov) {m_overwriteTalk = ov;}
|
||||
void setOverwriteWav(bool ov) {m_overwriteWav = ov;}
|
||||
void setRemoveWav(bool ov) {m_removeWav = ov;}
|
||||
void setRecursive(bool ov) {m_recursive = ov;}
|
||||
void setStripExtensions(bool ov) {m_stripExtensions = ov;}
|
||||
|
||||
private:
|
||||
|
||||
bool initTTS();
|
||||
bool stopTTS();
|
||||
bool initEncoder();
|
||||
|
||||
bool encode(wxString input,wxString output);
|
||||
bool voice(wxString text,wxString wavfile);
|
||||
|
||||
wxString m_dir;
|
||||
|
||||
wxString m_curTTS;
|
||||
wxString m_TTSexec;
|
||||
wxArrayString m_supportedTTS;
|
||||
wxArrayString m_supportedTTSOpts;
|
||||
wxString m_TTSOpts;
|
||||
|
||||
wxString m_curEnc;
|
||||
wxString m_EncExec;
|
||||
wxArrayString m_supportedEnc;
|
||||
wxArrayString m_supportedEncOpts;
|
||||
wxString m_EncOpts;
|
||||
|
||||
bool m_overwriteTalk;
|
||||
bool m_overwriteWav;
|
||||
bool m_removeWav;
|
||||
bool m_recursive;
|
||||
bool m_stripExtensions;
|
||||
};
|
||||
|
||||
|
||||
class TalkTraverser: public wxDirTraverser
|
||||
{
|
||||
public:
|
||||
TalkTraverser(TalkFileCreator* talkcreator) : m_talkcreator(talkcreator) { }
|
||||
|
||||
virtual wxDirTraverseResult OnFile(const wxString& filename);
|
||||
|
||||
virtual wxDirTraverseResult OnDir(const wxString& dirname);
|
||||
|
||||
private:
|
||||
TalkFileCreator* m_talkcreator;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue