Código de Python - Generador de audiotextos (nueva versión)

Imágen de perfil
Val: 712
Bronce
Ha aumentado 1 puesto en Python (en relación al último mes)
Gráfica de Python

Generador de audiotextos (nueva versión)gráfica de visualizaciones


Python

Actualizado el 20 de Agosto del 2022 por Antonio (75 códigos) (Publicado el 5 de Octubre del 2020)
16.445 visualizaciones desde el 5 de Octubre del 2020
Este programa genera archivos "mp3" a partir de textos introducidos por el usuario, en diferentes idiomas.
Botones:
"CREATE AUDIO-TEXT": Genera un audio, a partir del texto presente en el recuadro superior.
"TRANSLATE TEXT": Traduce el texto a cualquiera de los idiomas seleccionables del margen derecho.
"CLEAR TEXT": Borra el texto del cuadro superior.
"LISTEN AUDIO-FILE": Reproduce el último archivo de voz, creado.

aum

Requerimientos

Lenguaje: Python
Librerías y recursos: tkinter, ttk, gtts, threading, googletrans, os, playsound.
Conexión a Internet.
Se recomienda tener la última versión de "gtts".

1.2

Actualizado el 22 de Julio del 2021 (Publicado el 5 de Octubre del 2020)gráfica de visualizaciones de la versión: 1.2
3.259 visualizaciones desde el 5 de Octubre del 2020

1.2.1

Actualizado el 20 de Agosto del 2022 (Publicado el 23 de Agosto del 2021)gráfica de visualizaciones de la versión: 1.2.1
13.187 visualizaciones desde el 23 de Agosto del 2021
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

atm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox, filedialog
import tkinter.scrolledtext as sct
import gtts, playsound
import threading
from googletrans import Translator
import os
 
langs = gtts.lang.tts_langs()
 
class app():
    def __init__(self):
        self.window = tk.Tk()
        self.window.title("AudioText Maker")
        self.window['bg'] = 'gainsboro'
        self.window.geometry("785x299")
        self.translator = Translator()
        self.translation = ""
        self.text = ""
        self.lang = ""
        self.canvas = tk.Canvas(self.window)
        self.canvas.place(x=598,y=40)
        self.ultimo = ""
        self.currentDir = tk.StringVar()
        self.currentDir.set(os.getcwd())
 
        tk.Entry(self.window,textvariable=self.currentDir,width=130).place(x=0,y=0)
        self.entry = sct.ScrolledText(self.window,wrap=tk.WORD,width=69,height=8,bg='azure1')
        self.entry.focus()
        self.entry.place(x=10,y=40)
        tk.Button(self.window,text='CREATE AUDIO-TEXT',width=81,bg='thistle2',command=self.init_audio).place(x=10,y=195)
        tk.Button(self.window,text='TRANSLATE TEXT',width=81,bg='thistle2',command=self.init_translation).place(x=10,y=225)
        tk.Button(self.window,text='CLEAR TEXT',width=39,bg='thistle2',command=self.clear).place(x=10,y=255)
        tk.Button(self.window,text='LISTEN AUDIO-FILE',width=39,bg='thistle2',command=self.init_playsound).place(x=304,y=255)
        self.scrollbar = tk.Scrollbar(self.canvas,orient=tk.VERTICAL)
        self.scrollbar.pack(side=tk.RIGHT,fill=tk.Y)
        self.entryLang = tk.Listbox(self.canvas,width=26,height=15)
        self.entryLang.pack()
        self.entryLang.config(yscrollcommand = self.scrollbar.set)
        self.scrollbar.config(command = self.entryLang.yview)
        self.label = tk.Label(self.window,text="",width=81,bg='gainsboro',fg='blue')
        self.label.place(x=10,y=174)
 
        self.valores = list(langs.values())
        self.claves = list(langs.keys())
 
        self.insertb()
 
        self.window.mainloop()
 
    def translate(self):
        try:
            self.label.configure(text='TRASLATING...')
            self.define_lang()
            self.text = self.entry.get('1.0',tk.END)
            self.entry.delete('1.0',tk.END)
            self.position = (self.entryLang.curselection())[0]
            self.lang = self.claves[(self.valores).index(self.entryLang.get(int(self.position)))]
            self.translation = (self.translator.translate(self.text,dest=self.lang).text)
 
        except Exception as e:
            if str(e) == "tuple index out of range":
                messagebox.showwarning("ERROR","Make sure you have chosen a language.")
            else:
                print(str(e))
                messagebox.showwarning("ERROR",("Unexpected error: "+str(e)))
 
        self.label.configure(text="")
        self.insert_translation()
 
    def play_audio(self):
        try:
            self.label.configure(text='PLAYING: {}'.format((self.ultimo).split("/")[-1]))
            playsound.playsound(self.ultimo)
        except:
            messagebox.showwarning("ERROR",'Can not play {}'.format((self.ultimo).split("/")[-1]))
        self.label.configure(text="")
 
 
    def clear(self):
        self.entry.delete('1.0',tk.END)
 
    def insert_translation(self):
        if self.translation != "":
            self.entry.insert(tk.END,self.translation)
 
    def make_audio(self):
        self.myFile=filedialog.asksaveasfilename(initialdir="/",title="Save as",defaultextension=".mp3")
        if self.myFile != "":
            self.ultimo = self.myFile
            self.label.configure(text="CREATING AUDIO FILE")
            try:
                self.define_lang()
                if self.translation == self.entry.get('1.0',tk.END):
                    self.tts = gtts.gTTS(self.translation,lang=self.lang)
                else:
                    lan = (self.translator.translate(self.entry.get('1.0',tk.END)).src)
                    self.tts = gtts.gTTS(self.entry.get('1.0',tk.END),lang=lan)
                if os.path.exists(self.myFile):
                    os.remove(self.myFile)
                    self.tts.save(self.myFile)
                else:
                    self.tts.save(self.myFile)
                messagebox.showinfo("TASK COMPLETED","File created successfully.")
            except Exception as e:
                messagebox.showwarning("ERROR","Unexpected error: "+str(e))
                print(str(e))
            self.label.configure(text="")
            self.lang = ""
            self.translation = ""
 
    def define_lang(self):
        if self.lang == "":
            self.lang = (self.translator.translate(self.entry.get('1.0',tk.END)).src)
            self.translation = self.entry.get('1.0',tk.END)
 
    def insertb(self):
        for i in self.valores:
            self.entryLang.insert(tk.END,i)
 
    def init_translation(self):
        if len(self.entry.get('1.0',tk.END))>1:
            t1 = threading.Thread(target=self.translate)
            t1.start()
        else:
            messagebox.showwarning("NO TEXT","You haven't written anything to translate.")
 
    def init_audio(self):
        if len(self.entry.get('1.0',tk.END))>1:
            t = threading.Thread(target=self.make_audio)
            t.start()
 
    def init_playsound(self):
        if self.ultimo != "":
            t1 = threading.Thread(target=self.play_audio)
            t1.start()
        else:
            messagebox.showwarning("NO FILE CREATED","You haven't created your audio file yet.")
 
if __name__=="__main__":
    app()



Comentarios sobre la versión: 1.2.1 (0)


No hay comentarios
 

Comentar la versión: 1.2.1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s6521