pndurette / gTTS

Python library and CLI tool to interface with Google Translate's text-to-speech API
http://gtts.readthedocs.org/
MIT License
2.26k stars 361 forks source link

GTTS is adding in a word when speaking. #447

Closed dermotgouk closed 8 months ago

dermotgouk commented 8 months ago

Prerequisites

Current Behaviour (steps to reproduce)

GTTS is speaking the following sentence and after the number 4 its adding a word that sounds like feat/feed/feet ('Space 4 ', 'RS027', 'Operational', 'Space 4 ')

                finished = ("Space 4","RS027","Operational","Space 4")
                finishing =str(finished)
                print(finishing)
                var= gTTS(text = finishing,lang = 'en') 
                var.save('eng.mp3')

Expected Behaviour

It should not add this additional word afterwards

code

Context

Space 4 is called from a variable which parses an array list for the index.

Environment

pndurette commented 8 months ago

@dermotgouk Ah, I see why.

So when you're transforming your tuple to string (with str(finished)), it actually creates the string ('Space 4', 'RS027', 'Operational', 'Space 4')

The last ' is read like "feet" as in the imperial measurement, most likely because this is how Google reads ' when it comes after a number, e.g. 6' (six feet). It does the same on the first space 4 in the string as well.

If you really want it to read a list verbatim, I'd use a join(), i.e.:

finished = ("Space 4", "RS027", "Operational", "Space")
- finishing = str(finished)
+ finishing = ", ".join(finished)
print(finishing)
var = gTTS(text=finishing, lang="en")
var.save("eng.mp3")

That way it'll read Space 4, RS027, Operational, Space 4