I'm building a basic text to audio app using python.When I play an audio file after taking an input from a user and clicking a button, the window closes after the audio file is played.
app = CTk()
app.title("Text to Morse Code")
app.geometry("600x400")
def gui_handler():
def input_to_morse():
morse_code = text_to_morse(entry.get())
morse_audio = morse_to_audio(morse_code)
threading.Thread(target=play, args=(morse_audio,)).start()
print("Hello")
gen_morse_button = CTkButton(app, text="Generate Morse Code", command=input_to_morse)
entry = CTkEntry(app, placeholder_text="Enter text to be converted")
app.grid_columnconfigure(0, weight=1)
entry.grid(row=0, column=0, padx=40, pady=20, sticky="ew")
gen_morse_button.grid(row=1, column=0, padx=40, pady=20, sticky="ew")
gui_handler()
app.mainloop()
This is the exit code for when the window closes.
Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)
I looked this up and it says some sort of segmentation error but I'm not sure how to fix it. I've tried using simple audio where I export the file from pydub and played it using simple audio but it's the same issue.
Edit : This is the morse_to_audio function
# Audio objects
dash = AudioSegment.from_file("./audio/beep.wav", format="wav")[:200]
dot = dash[:50]
short_gap = AudioSegment.silent(duration=100)
medium_gap = AudioSegment.silent(duration=200)
long_gap = AudioSegment.silent(duration=500)
def morse_to_audio(morse_code: list):
"""
Converts a given list of morse code values and returns an audio file.
:param morse_code: List of Morse code values depicted in "." "-"
:return: Audio of Morse code being played.
"""
morse_audio = AudioSegment.empty()
for i, letter in enumerate(morse_code):
if letter == " ":
morse_audio += long_gap
else:
for j, symbol in enumerate(letter):
if symbol == ".":
morse_audio += dot
elif symbol == "-":
morse_audio += dash
# if the symbol isn't the last symbol in a letter add a short gap
if j < len(letter) - 1:
morse_audio += short_gap
# if there is a next letter, and it isn't a space add a medium gap
if i + 1 < len(morse_code) and morse_code[i + 1] != " ":
morse_audio += medium_gap
return morse_audio
morse_to_audio()function come from? Perhaps it's generating corrupted data, that crashes the player after the end of the sound.play(). What isplay()?pydub. The code for usingffplayinternally has issue.