1. Google_tts

Converting a few Euphoria demos to GUI form. Who can add code to enable translation from one language to another?

-- net/google_tts.ex 
-- Use the Google TTS service to create, then play an MP3 file 
 
constant docs = "<u><b>Google TTS</b></u>\n" & 
     "Enter something in the input box below, and click the OK button" 
 
include std/net/http.e 
include std/net/url.e 
include std/sequence.e 
include std/io.e 
include GtkEngine.e 
include std/console.e 
 
constant languages = {"en","es","it","fr"}  
 
constant errimg = create(GtkImage,"~/demos/thumbnails/net0.png") 
 
constant win = create(GtkWindow) 
connect(win,"destroy","Quit") 
set(win,"border width",5) 
set(win,"default size",400,100) 
set(win,"position",GTK_WIN_POS_CENTER) 
 
constant panel = create(GtkBox,1) 
add(win,panel) 
 
constant lbl = create(GtkLabel) 
	set(lbl,"font","8") 
	set(lbl,"markup",docs) 
	add(panel,lbl) 
	 
constant input = create(GtkEntry) 
set(input,"margin bottom",10) 
pack(panel,input) 
 
constant lang = create(GtkComboBoxText) 
for i = 1 to length(languages) do 
	set(lang,"append text",languages[i]) 
end for 
set(lang,"active",1) 
add(panel,lang) 
 
constant btn1 = create(GtkButton,"gtk-quit","Quit"), 
	btn2  = create(GtkButton,"gtk-ok","SendTTS"), 
	btnbox = create(GtkButtonBox) 
	add(btnbox,{btn1,btn2}) 
	pack(panel,-btnbox) 
 
show_all(win) 
main() 
 
global function SendTTS() 
sequence errmsg = "Unknown error" 
sequence txt = encode(get(input,"text"),"%20") 
sequence tl = get(lang,"active text") 
display(txt) 
 
sequence u = sprintf("http://translate.google.com/translate_tts?tl=%s&q=%s",{tl,txt}) 
 
object r = http_get(u) 
if atom(r) then 
	switch r do 
		case -5 then errmsg = "Not able to connect to web!" 
	end switch 
	Error(win,"Web error!",sprintf("Err code: %d\n", { r }),errmsg,,,errimg) 
	 
elsif length(r[2]) = 0 then 
	Info(win,"Error", 
		"Google did not translate for us", 
		"They do have an unpublished 'max' character count,\n" & 
		"perhaps you exceeded this?") 
else 
	write_file("google_tts.mp3", r[2]) 
	if Question(win,"Success!","MP3 stored as google_tts.mp3","Play it now?") = MB_YES then 
			system("totem google_tts.mp3 &",0) 
	end if 
end if 
return 1 
end function 
new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu