-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI_client.py
136 lines (113 loc) · 3.87 KB
/
GUI_client.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
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
from tkinter import *
from os import _exit as ex
import socket
import os
import sys
from scipy.io import wavfile
import pygame as py
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import time
#import threading
#初始化
py.mixer.init()
def callbackFunc():
text = Entry.get() # 取得文字
if not text:
return 0
resultButton2.configure(state="active")
lang = var.get()
model = var2.get()
sp = speech_regulator.get()
if (sp*100) % 10 == 0 or sp == 1.1:
sp-=0.01
if lang == "中文":
port = 4000
elif lang == "英文":
port = 3000
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('***.***.**.***', port)) # Enter your IP
except socket.error as msg:
print(msg)
print(sys.exit(1))
s.send(text.encode()) # 傳送文字
time.sleep(0.001)
s.send(str(sp).encode())
time.sleep(0.001)
s.send(model.encode())
with open("speech.wav",'w') as f: # 以空白覆蓋檔案
f.close
with open("speech.wav",'ab') as f:
while True:
if model == "FFT":
time.sleep(0.1)
wav = s.recv(65536)
f.write(wav)
if not wav:
break
else:
time.sleep(0.1)
wav = s.recv(65536)
f.write(wav)
if not wav:
break
f.close()
wav = py.mixer.Sound('speech.wav') #文件加載
wav.play()
s.close()
def callbackFunc2():
if os.path.exists('speech.wav'):
wav = py.mixer.Sound('speech.wav') #文件加載
wav.play()
else:
resultButton2.configure(state="disabled")
def close():
ex(0)
window = Tk()
window.title("Text-to-Speech")
window.geometry("700x350")
# Label
label = Label(window, text="請輸入文字", font=("Lucida Grande", 20))
label.place(x = 60, y = 40)
label2 = Label(window, text="語速", font=("Lucida Grande", 20))
label2.place(x = 325, y = 305)
label3 = Label(window, text="請輸入 \"對應\" 的語言,標點符號:英文為\"半形\"、中文為\"全形\"",
font=("Lucida Grande", 15), bg="yellow", fg="red")
label3.place(x = 60, y = 80)
# Text entry
Entry = Entry(window, font=("Lucida Grande", 20))
Entry.place(x = 220, y = 40)
# Dropdown menu
OptionList = ["中文", "英文"]
OptionList2 = ["FFT", "TransformerTTS"]
var = StringVar(window)
var.set("中文") # default value
var2 = StringVar(window)
var2.set("FFT")
opt = OptionMenu(window, var, *OptionList)
opt2 = OptionMenu(window, var2, *OptionList2)
opt.configure(font=("Lucida Grande", 20))
opt2.configure(font=("Lucida Grande", 20))
opt.place(x = 60, y = 125)
opt2.place(x = 60, y = 185)
menu = window.nametowidget(opt.menuname)
menu.config(font=("Lucida Grande", 20))
menu2 = window.nametowidget(opt2.menuname)
menu2.config(font=("Lucida Grande", 20))
# Scale
sp_var = IntVar(window)
sp_var.set(1)
speech_regulator = Scale(window, from_=0.35, to=2, orient="horizontal", resolution=0.01,
length=200, width=25, sliderrelief="flat", font=("Lucida Grande", 20))
speech_regulator.place(x = 245, y = 230)
# Button
resultButton = Button(window, text = ' 合成 ', command=callbackFunc)
resultButton.configure(font=("Lucida Grande", 20))
resultButton.place(x = 200, y = 125)
resultButton2 = Button(window, text = ' 重播 ', state="disabled", command=callbackFunc2)
resultButton2.configure(font=("Lucida Grande", 20))
resultButton2.place(x = 360, y = 125)
exitButton = Button(window, text = ' Exit ', command=close)
exitButton.configure(font=("Lucida Grande", 18))
exitButton.place(x = 530, y = 240)
window.mainloop()