Skip to content

Instantly share code, notes, and snippets.

@MikeTheWatchGuy
Last active March 31, 2019 20:55
Show Gist options
  • Save MikeTheWatchGuy/5ac1fe5432f4fae5f12546044616d3f1 to your computer and use it in GitHub Desktop.
Save MikeTheWatchGuy/5ac1fe5432f4fae5f12546044616d3f1 to your computer and use it in GitHub Desktop.
Duplication of GUI presented on Reddit, just to see what it would be like to write.
import PySimpleGUI as sg
import subprocess
def slider(key, initial_value):
return [sg.Slider((1, 200), resolution=0, default_value=initial_value, orientation='h', size=(10,15),key=key)]
layout = [ [sg.Text('Pitch')], slider('pitch', 64),
[sg.Text('Speed')], slider('speed',72),
[sg.Text('Mouth')], slider('mouth',128),
[sg.Text('Throat')],slider('throat',128),
[sg.CBox('Phoenetic', key='CBP')], [sg.CBox('Save', key='CBS')],[sg.CBox('Output', key='CBO')],
[sg.Input('Commodore64', key='SaveName', size=(16,1))],
[sg.Button('Play')]]
window = sg.Window('Commodore 64').Layout(layout)
while True:
event, v = window.Read()
if event is None:
break
if event == 'Play':
command = f"sam.exe -pitch {int(v['pitch'])} -speed {int(v['speed'])} -mouth {int(v['mouth'])} -throat {int(v['throat'])} {v['SaveName']}"
if v['CBP']:
command += f" -phoenetic {1*v['CBP']}"
if v['CBS']:
command += f" -wav {v['SaveName']}_p{int(v['pitch'])}m{int(v['mouth'])}s{int(v['speed'])}t{int(v['throat'])}.wav"
if v['CBO']:
subprocess.call(command)
print(command)
@MikeTheWatchGuy
Copy link
Author

This code duplicates the code located in this Reddit post
https://www.reddit.com/r/Python/comments/b7qsf5/made_a_gui_for_a_c64_speech_synthesizer_and_a/

    from tkinter import *
    import subprocess
    
    def createcommand():
    	output = "sam.exe"
    	output += ' ' 
    	output += "-pitch " + str(pitch.get())
    	output += ' ' 
    	output += "-speed " + str(speed.get())
    	output += ' '
    	output += "-mouth " + str(mouth.get())
    	output += ' '
    	output += "-throat " + str(throat.get())
    	output += ' '
    	if(phonetic.get()):
    		output += "-phonetic"
    		output += ' '
    	output += textbox.get()
    	output += ' '
    	return output
    	
    def play():
    	command = createcommand()
    	if(save.get()):
    		subprocess.call(command + "-wav " + textbox.get() + "_p" + str(pitch.get()) + 'm' + str(mouth.get()) + 's' + str(speed.get()) + 't' + str(throat.get()) + ".wav")
    		print(command + "-wav " + textbox.get() + "_p" + str(pitch.get()) + 'm' + str(mouth.get()) + 's' + str(speed.get()) + 't' + str(throat.get()) + ".wav")
    	else:
    		print (command)
    	if(output.get()):
    		subprocess.call(command)
    
    master = Tk()
    
    pitch = Scale(master, from_=1, to=200, orient=HORIZONTAL, label = "pitch")
    pitch.set(64)
    pitch.pack()
    
    speed = Scale(master, from_=1, to=200, orient=HORIZONTAL, label = "speed")
    speed.set(72)
    speed.pack()
    
    mouth = Scale(master, from_=1, to=200, orient=HORIZONTAL, label = "mouth")
    mouth.set(128)
    mouth.pack()
    
    throat = Scale(master, from_=1, to=200, orient=HORIZONTAL, label = "throat")
    throat.set(128)
    throat.pack()
    
    phonetic = IntVar()
    checkBoxPhonetic = Checkbutton(variable=phonetic, onvalue=1, offvalue=0, text="Phonetic")
    checkBoxPhonetic.pack()
    
    save = IntVar()
    checkBoxSave = Checkbutton(variable=save, onvalue=1, offvalue=0, text="Save")
    checkBoxSave.pack()
    
    output = IntVar()
    outputBoxOutput = Checkbutton(variable=output, onvalue=1, offvalue=0, text="Output")
    outputBoxOutput.pack()
    outputBoxOutput.select()
    
    textbox = Entry(master)
    textbox.pack()
    textbox.delete(0, END)
    textbox.insert(0, "Commodore 64")
    
    Button(master, text='Play', command=play).pack()
    
    mainloop()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment