Text to MP3 using pyTTS - Non-programmer question

S

seyeRMReyes

I'm not a programmer, but I'd like to make a program that will open and
read a txt file and output to a mp3 file. I don't need to ever hear the
voice, but I'd like the program to direct

I've been google'ing around and have found a few tutorials about
converting pdfs to mp3 and converting typed text (in the source file)
to wave, but I'm looking for the ability to directly convert from txt
to mp3/ogg/wma.

Currently I'm running on WinXP, but I also have access to a Linux box.

Any help would be appreciated.
 
D

Dieter Deyke

I'm not a programmer, but I'd like to make a program that will open and
read a txt file and output to a mp3 file. I don't need to ever hear the
voice, but I'd like the program to direct

I've been google'ing around and have found a few tutorials about
converting pdfs to mp3 and converting typed text (in the source file)
to wave, but I'm looking for the ability to directly convert from txt
to mp3/ogg/wma.

Currently I'm running on WinXP, but I also have access to a Linux box.

Any help would be appreciated.

I have written a script to convert .pdf to .wma, which may get you
started:

#! /usr/bin/env python
# -*- coding: iso-latin-1 -*-

import os
import sys

basename, suffix = os.path.splitext(sys.argv[1])
suffix = suffix.lower()

pdfname = basename + ".pdf"
txtname = basename + ".txt"
wavname = basename + ".wav"

# pdf --> txt

if suffix == ".pdf":
os.system('pdftotext "%s"' % (pdfname, ))
suffix = ".txt"

# txt --> wav

if suffix == ".txt":
import re
data = open(txtname).read()
data = data.replace(". . .", "")
data = data.replace("<", "")
data = data.replace(">", "")
data = data.replace("Mr.", "Mister")
data = data.replace("«", '"')
data = data.replace("»", '"')
data = data.replace(',,', '"')
data = re.sub("\\d+\\s* ", "", data)
data = re.sub("\n\\s*\\d+\\.*\\s*\n", "\n", data)
data = re.sub("\n\\s*\n\\s*\n", "\n\n", data)
data = re.sub("-([a-z])", "\\1", data)
open(txtname, "w").write(data)
import pyTTS
tts = pyTTS.Create()
tts.SetRate(0)
tts.Volume = 100
tts.SetVoiceByName("ATT-DT-14-Klara16")
tts.SpeakToWave(wavname, data)
suffix = ".wav"

# split, wav --> mp3/ogg/wma

if suffix == ".wav":
import wave
os.mkdir(basename)
fi = wave.open(wavname, "r")
nchannels, sampwidth, framerate, nframes, comptype, compname = fi.getparams()
n = 0
while 1:
n += 1
data = fi.readframes(600 * framerate)
if not data: break
fo = wave.open("tmp.wav", "w")
fo.setparams((nchannels, sampwidth, framerate, 0, comptype, compname))
fo.writeframes(data)
fo.close()
# os.system('lame -m m --cbr -b 32 -q 0 -S tmp.wav "%s\\%02d.mp3" "%s"' % (basename, n))
# os.system('oggenc -q -1 -o "%s\\%02d.ogg" tmp.wav' % (basename, n))
os.system('cscript WMCmd.vbs -profile a20_1 -input tmp.wav -output "%s\\%02d.wma' % (basename, n))
fi.close()
os.remove("tmp.wav")

os.remove(wavname) ### This is just too big to keep around
 
S

seyeRMReyes

Thanks for the script. Are there any online python intrepreters?

I'd like to play around with the script. I don't have access to my home
PC.
 
R

Ravi Teja

Thanks for the script. Are there any online python intrepreters?

I'd like to play around with the script. I don't have access to my home
PC.

You probably will have to wait till you get to yours. There were some
AJAXian ones but I doubt that you will find a free (assuming that you
meant that) online interpreter on a MS Windows box that allows you to
install your modules and give you an FTP or such account to get the
recorded file back.
 
M

Marc Shapiro

I'm not a programmer, but I'd like to make a program that will open and
read a txt file and output to a mp3 file. I don't need to ever hear the
voice, but I'd like the program to direct

I've been google'ing around and have found a few tutorials about
converting pdfs to mp3 and converting typed text (in the source file)
to wave, but I'm looking for the ability to directly convert from txt
to mp3/ogg/wma.

Currently I'm running on WinXP, but I also have access to a Linux box.

Any help would be appreciated.
From what I've seen, pyTTS is Windows only. Is there a package that
runs on linux that provides similar functionality. I have festival and
festlite, but I would prefer a Python solution.
 
M

Michael

Marc said:
From what I've seen, pyTTS is Windows only.  Is there a package that
runs on linux that provides similar functionality.  I have festival and
festlite, but I would prefer a Python solution.

From: http://www.cam.org/~nico/cicero/cicero-README.txt

"""
Cicero TTS: A Small, Fast and Free Text-To-Speech Engine.

Copyright 2003-2006 Nicolas Pitre <[email protected]>
Copyright 2003-2006 Stéphane Doyon <[email protected]>

Version 0.7, March 2006

Our TTS engine currently speaks French and some resemblance of English,
although we hope it can some day be taught to speak good English or other
languages. The engine uses context-sensitive rules to produce phonemes
from the text. It relies on MBROLA
(http://tcts.fpms.ac.be/synthesis/mbrola.html) to generate actual audio
output from the phonemes. The TTS engine is implemented using the Python
programming language.

We've come up with this TTS to try and meet our own needs as blind users.
"""

"""
This is still an early release of our TTS, quality is beta-ish.
Installation/integration surely has rough edges still, and pronunciation
is constantly improving. The TODO-list is still generous.
"""

I've not tried this, but I suspect this might be a good place to start
(though coaxing it to do english might well be a project in itself,
depending on what they mean by "some semblance of English" :)

Regards,


Michael.
 
S

seyeRMReyes

Thanks for much for all the help, but it doesn't seem as if the wav
file is being created, but I really don't get an error message.

Initially, I got error messages about TCL and TK lidbrary and I added
them to the PATH.

Do the encoder need to be in the source folder along with the code?

Again, I don't know anything about programmer, but was able to make
sense of most of it.

Any help would be helpful.

Thanks
 
S

seyeRMReyes

Thanks for much for all the help, but it doesn't seem as if the wav
file is being created, but I really don't get an error message.

Initially, I got error messages about TCL and TK lidbrary and I added
them to the PATH.

Do the encoder need to be in the source folder along with the code?

Again, I don't know anything about programming, but was able to make
sense of most of it.

Any help would be helpful.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top