Hello Gentlemen,
I am testing the GTTS function IN PYTHON , CGI ENVIRONMENT , with the
aim of implementing it in browsers that do not support text-to-speech.
I can turn text to speech in MICROSOFT EDGE AND GOOGLE CHROME
browsers with the speechSynthesis function.
This function acts on error messages ( for example ) , system caption (
onmouseover ) , etc.
In OPERA , VIVALD , FIREFOX browsers, the speechSynthesis function is
not working.
The PYTHON script to convert text to speech is very simple:
#!c:\python\python.exe
from gtts import gTTS
from gtts.tokenizer.pre_processors import abbreviations, end_of_line
from time import sleep
from datetime import datetime
import os
import pyglet
import cgi
Create the text
form = cgi.FieldStorage()
idioma = form.getvalue(‘idioma’)
texto = form.getvalue(‘texto’)
date_s = (datetime.now().strftime(‘%Y%m%d%H%M%S%f’))
tts = gTTS(text=texto, lang=idioma , slow=False, pre_processor_funcs = [abbreviations, end_of_line])
filename = ‘c:/payback/temp/’ + date_s + ‘.mp3’
if os.path.exists(filename): os.remove(filename) #remove temperory file
tts.save(filename)
music = pyglet.media.load(filename, streaming=False)
music.play()
sleep(music.duration) #prevent from killing
os.remove(filename) #remove temperory file
#print (“Content-Type: text/html\n\n”)
This script is run from the URL:
https://server_domain/tts.py?idioma=en&texto=Hello gentlemen, let’s discuss our strategic planning for the year 2024
My problem is in the last line of the script ( print (“Content-Type: text/html\n\n”) that is, if you don’t include it, the script plays the created mp3 file (so it converted text into voice) however it sends an error message: Internal Server Error ( Premature end of script headers: tts.py )
If you include it, the script plays the mp3 file (no error) however it sends a new empty page harming the systematics of my need ( speak an error message , speak a caption with the onmouseover event , etc )
no pagination.
I’m researching the CALLBACK function in javascript to try to work around this problem.This function would call the URL and when returning it would execute a BACK(-1) function.
Note - Doesn’t seem like a good solution.
Does anyone know how to solve this problem more properly?
Thank you for your attention,
Kleber
Note - This text was translated by google.