0

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
9
  • Where did this morse_to_audio() function come from? Perhaps it's generating corrupted data, that crashes the player after the end of the sound. Commented Jul 23, 2024 at 20:44
  • @jasonharper Thank you for the reply. I've edited the question and added the details. Commented Jul 24, 2024 at 5:54
  • If your application crashes after playing the audio, then it is most likely caused by the function play(). What is play()? Commented Jul 24, 2024 at 6:59
  • @acw1668 play( ) is the default playback function provided by the pydub library. Commented Jul 24, 2024 at 8:47
  • Then you need to find out which player is used internally by pydub. The code for using ffplay internally has issue. Commented Jul 24, 2024 at 9:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.