Código de Python - Generador de audiotextos.

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.gráfica de visualizaciones


Python

Actualizado el 28 de Noviembre del 2022 por Antonio (75 códigos) (Publicado el 21 de Septiembre del 2020)
6.345 visualizaciones desde el 21 de Septiembre 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.

PARA CUALQUIER DUDA O ERROR, NO DUDEN EN COMENTARMELO.

autm

Requerimientos

Lenguaje: Python
Librerías y recursos: tkinter, ttk, gtts, threading, googletrans, os.
Conexión a Internet

1.1

Actualizado el 21 de Febrero del 2022 (Publicado el 21 de Septiembre del 2020)gráfica de visualizaciones de la versión: 1.1
2.201 visualizaciones desde el 21 de Septiembre del 2020

1.2
estrellaestrellaestrellaestrellaestrella(3)

Actualizado el 23 de Agosto del 2022 (Publicado el 21 de Febrero del 2022)gráfica de visualizaciones de la versión: 1.2
1.472 visualizaciones desde el 21 de Febrero del 2022

2.0
estrellaestrellaestrellaestrellaestrella(3)

Actualizado el 28 de Noviembre del 2022 (Publicado el 23 de Octubre del 2022)gráfica de visualizaciones de la versión: 2.0
2.673 visualizaciones desde el 23 de Octubre del 2022
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

Incluye posibilidad de importar texto, copiándolo.

app
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/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
import pyperclip
import time
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.window.resizable(width=tk.FALSE,height=tk.FALSE)
        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=26,bg='thistle2',command=self.clear).place(x=10,y=255)
        tk.Button(self.window,text='IMPORT TEXT',width=26,bg='thistle2',command=self.init_import).place(x=202,y=255)
        tk.Button(self.window,text='LISTEN AUDIO-FILE',width=26,bg='thistle2',command=self.init_playsound).place(x=395,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 import_text(self):
        self.label.configure(text="IMPORTING TEXT")
        self.entry.delete('1.0',tk.END)
        self.ultima_copia = pyperclip.paste().strip()
        messagebox.showinfo("COPY TEXT","Select and copy your text")
        while True:
            time.sleep(0.1)
            self.copia = pyperclip.paste().strip()
            if self.copia != self.ultima_copia:
                self.entry.insert(tk.END,self.copia)
                self.ultima_copia = self.copia
                break
        self.label.configure(text="")
 
    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:
            threading.Thread(target=self.translate).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:
            threading.Thread(target=self.make_audio).start()
 
    def init_import(self):
        threading.Thread(target=self.import_text).start()
 
    def init_playsound(self):
        if self.ultimo != "":
            threading.Thread(target=self.play_audio).start()
        else:
            messagebox.showwarning("NO FILE CREATED","You haven't created your audio file yet.")
 
if __name__=="__main__":
    app()



Comentarios sobre la versión: 2.0 (3)

Imágen de perfil
4 de Diciembre del 2022
estrellaestrellaestrellaestrellaestrella
Oye y tienes que tener una api key de google para usar tu programa?
Responder
Imágen de perfil
14 de Diciembre del 2022
estrellaestrellaestrellaestrellaestrella
No
Responder
25 de Septiembre del 2023
estrellaestrellaestrellaestrellaestrella
No ha dejado ningún comentario
Responder

Comentar la versión: 2.0

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/s6490