forked from sourav-bhaduri/Text-to-audiofile-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
82 lines (76 loc) · 4.26 KB
/
main.py
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
import tkinter as tk
#if your using python 2.xx
# import Tkinter as tk
from tkinter import ttk
from comtypes.client import CreateObject
from comtypes.gen import SpeechLib
import logging
from tkinter import messagebox as mbx
"""sets up initial conversion"""
import os
class MainApplication(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
"""application configuration"""
menu = tk.Menu()
Font = "helevetica 10"
root.grid_rowconfigure(2, weight=2)
style = ttk.Style()
style.configure("TLabel", relief="flat", foreground="black", background="lightgreen")
style.configure("TButton", relief="grooved", foreground="#800", background="lightgreen", width=30)
root.config(menu=menu)
root.resizable(0, 0)
root.title("Text To Audio Converter")
root.geometry("500x200")
menu.add_command(label="Exit", command=root.quit)
menu.add_command(label="Help", command=self.showhelp)
menu.add_command(label="About", command=self.about)
root.configure(background="lightgreen")
menu.configure(background="white")
self.basic = ttk.Label(text="Please click the help button on the menu to learn how to use program \n", font=Font)
self.basic.pack()
self.Linput = ttk.Label(root, text="Input file", width=30)
self.Linput.pack()
self.inputentry = ttk.Entry(root, width=30)
self.inputentry.pack()
self.Loutput = ttk.Label(text="Output file", width=30)
self.Loutput.grid_rowconfigure(4, weight=2)
self.Loutput.pack()
self.OutputEntry = ttk.Entry(width=30)
self.OutputEntry.pack()
self.Lspeed = ttk.Label(text="Set voice rate", width=30)
self.Lspeed.pack()
self.Setrate = ttk.Entry(width=30)
self.Setrate.pack()
self.Convert = ttk.Button(text="Convert Text", command=self.ConverterToAudio)
self.Convert.pack(side="top")
"""sets up main root nction"""
def ConverterToAudio(self):
try:
self.engine = CreateObject("SAPI.SpVoice")
self.stream = CreateObject("SAPI.SpFileStream")
self.infile = self.inputentry.get()
self.outfile = self.OutputEntry.get()
self.stream.Open(self.outfile, SpeechLib.SSFMCreateForWrite)
self.engine.AudioOutputStream = self.stream
with open(self.infile, "r") as text:
self.content = text.read()
self.engine.rate = int(self.Setrate.get())
self.engine.pitch =int(self.Setrate.get())
self.engine.GetVoices("microsoft zira")
self.engine.speak(self.content)
self.stream.Close()
mbx.showinfo("output", f" conversion of source file {self.infile} to destination{self.outfile}")
with open("converter-conversions-log.txt","a") as C:
C.write(f"output: conversion of {self.infile} {self.outfile} completed")
#mbx.showinfo("Output", "Conversion of {} to {}".format(self.infile, self.outfile))#
except Exception as e:
mbx.showwarning("error", e)
with open("converter-error-log.txt", "a") as E:
E.write(f"\n error: {e}")
def showhelp(self):mbx.showinfo("Help", "To use this application make sure you type in the file or directory you need converted in the input entry and output\n entru for example text.txt and\n then in the output entry do text.mp3 you can also tab to the next entry\nthe new feature you can is set the rate of the scale from -10 to 10 in the rate entry box but there must be a number, i will add voices as I go. if you have a problem email aheisleycook@gmail.com or notify me at my github. amke sure to send the logs you ahve when you find a error pelse send converter-error-log and converter-conversions-log as well ")
def about(self):
mbx.showinfo("About", "\n\n created by austin heisley-cook\ndate 2/1/2018 original year is 2013 this program the idea is credited to past boss because I am making the idea becomes a reality.\n I have spent years creating this.")
root = tk.Tk()
app = MainApplication()
root.mainloop()