File size: 1,266 Bytes
b39d3e8
 
 
 
 
 
 
 
 
 
 
 
53400df
f3e395e
b218224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import subprocess
import sys

# Function to install required packages using subprocess
def install_package(package):
    subprocess.check_call([sys.executable, "-m", "pip", "install", package])

# Install the necessary packages
install_package("numpy")
install_package("scipy")
install_package("gradio")
install_package("pydub")
install_package("morse-tunes")

import gradio as gr
from scipy.io.wavfile import write
from morse_tunes.morse import text_to_morse
from morse_tunes.audio import morse_to_numpy
import numpy as np

def convert_and_generate_audio(text):
    """Converts text to Morse code and generates a NumPy audio array."""
    morse_code = text_to_morse(text)
    audio_data = morse_to_numpy(morse_code)
    return morse_code, (44100, audio_data)

# Define the Gradio interface
interface = gr.Interface(
    fn=convert_and_generate_audio,
    inputs=gr.Textbox(label="Input Text", placeholder="Enter text to convert to Morse code"),
    outputs=[
        gr.Textbox(label="Morse Code"),
        gr.Audio(label="Morse Code Audio", type="numpy"),
    ],
    title="MorseTunes",
    description="Convert text to Morse code and generate audio that can be played in the browser.",
)

# Launch the Gradio app
if __name__ == "__main__":
    interface.launch()