Text to Speech unter Windows

@Hoants:
Notevibes (in its free version) is restricted to 200 characters per query. For longer texts, you need to split the text into several parts and then combine the mp3 files afterwards.

In case of the TonUINO project this is no restriction since it is using very short text fragments, but your text is longer than 200 characters.

@Peer
But i don’t know why this code work for news.txt


it more than 200 charaters :slight_smile:

Dosesn’t work with this txt file under 200 character:

Hi @Peer
In Notevibes free version you can convert text to speech under 3000 or 4000 characters.
You code get error when convert unicode text like that: " Ngày tháng năm ngày tháng năm"
print(link)
https://storage.googleapis.com/audiog-204018.appspot.com/files/ngà y-tháng-năm-ngà y-tháng-năm_tonuino.mp3

But the correct link is:
https://storage.googleapis.com/audiog-204018.appspot.com/files/ngày-tháng-năm-ngày-tháng-năm_tonuino.mp3

p/s: Sorry for my bad English

Ok.

The German version notevibes.com/de/ notes says that there is a restriction to 200 characters, which I cited:

Erstellen Sie ein Konto, um eine unbegrenzte Nutzung zu erhalten. Kostenlose Version auf 200 Zeichen begrenzt. Nur für den persönlichen Gebrauch.

However, at the bottom of the same website the restriction is said to be 5000 characters…

The problem with the Unicode characters is, that the python function urllib.urlretrieve is not able to parse unicode urls. You need to convert the link before calling urlretrieve. This can be done in the following way:

import urllib
import urlparse

...
   link=txt[start:end]
   parsed_link = urlparse.urlsplit(link.encode('utf8'))
   parsed_link = parsed_link._replace(path=urllib.quote(parsed_link.path))
   encoded_link = parsed_link.geturl()
   urllib.urlretrieve(encoded_link, filename)
1 „Gefällt mir“

With str " Ngày tháng năm ngày tháng năm"
I got:

UnicodeDecodeError: ‚ascii‘ codec can’t decode byte 0xc3 in position 65: ordinal not in range(128)

It is still difficult to find the reason for the error message without knowing the exact code you have used.

Please:
Simplify the code as much as possible, such that it still shows the behaviour. E.g.:

def text2mp3(textstring,filename):
    ... # exact definition of the code you are using

text2mp3(u'Ngày tháng năm ngày tháng năm','test.mp3')

And then post the output of the script.

The code:

# -*- coding: utf-8 -*-
import requests
import comtypes.client
import codecs
import urllib
import urlparse
def text2mp3(textstring,filename):
    req = requests.post("https://notevibes.com/", data={'time': '_tonuino', 'content': textstring, 'speed': 1 , 'pitch': 0 , 'voice': 'vi-VN-Standard-A'})
    if(req.status_code != 200):
        print(req.status_code, req.reason)
        return
    txt = req.text
    start = txt.find('https://storage.googleapis.com/audiog')
    end = txt.find('.mp3',start) + 4
    link = txt[start:end]
    print("link =" + link)
    parsed_link = urlparse.urlsplit(link.encode('utf8'))
    parsed_link = parsed_link._replace(path=urllib.quote(parsed_link.path))
    encoded_link = parsed_link.geturl()
    print("encoded_link = " + encoded_link)
    urllib.urlretrieve(encoded_link, filename)    
text2mp3(u'Ngày tháng năm ngày tháng năm content', '0300_new_tag.mp3')

And the result:

kq

I think, I found the problem: The link which needs to be extracted from the website is not unicode-encoded, but treated as if it were. When I replace req.text by req.content, it is interpreted as simple 8 bit text and everything works fine:

def text2mp3(textstring,filename):
    req = requests.post("https://notevibes.com/", data={'time': '_tonuino', 'content': textstring, 'speed': 1 , 'pitch': 0 , 'voice': 'vi-VN-Standard-A'})
    if(req.status_code != 200):
        print(req.status_code, req.reason)
        return
    txt = req.content
    start = txt.find('https://storage.googleapis.com/audiog')
    end = txt.find('.mp3',start) + 4
    link = txt[start:end]
    urllib.urlretrieve(link, filename)
1 „Gefällt mir“

Hi, könntest du eine Schritt für Schritt Anleitung schreiben?
Ich kenn mit mit python leider null aus. Ich habe es mit der google cloud platform Variante Probiert, hab aber keine Kreditkarte und das mit dem Bankkonto bekomm ich iwie nicht ausgewählt.

Wäre echt nett.

Danke im voraus

Notevibes lässt sich leider nicht mehr mit dem Script fernsteuern, da die jetzt Recaptcha auf der Internetseite integriert haben .

Ok schade :slight_smile: Trotzdem danke. Weißt du ob es ein Programm gibt, mit dem ich gut und einfach vorhandene mp3´s mit einer erstellten Sprachdatei verbinden kann? Am liebsten wäre mir eine batch oder ähnliches. Ich habe mp3directCut aber da muss ich jede Datei einzeln zusammenfügen.