|
import gradio as gr |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
|
|
|
|
def image_to_audio(image): |
|
|
|
gray_image = np.dot(image[..., :3], [0.2989, 0.5870, 0.1140]) |
|
|
|
normalized_image = gray_image / 255.0 |
|
|
|
audio_signal = normalized_image.flatten() |
|
|
|
sample_rate = 44100 |
|
|
|
return (sample_rate, audio_signal) |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
|
input_image = gr.Image(label="Input Image") |
|
|
|
output_audio = gr.Audio(label="Output Audio", streaming=True, autoplay=True) |
|
|
|
|
|
input_image.change(image_to_audio, inputs=input_image, outputs=output_audio) |
|
|
|
|
|
demo.launch(show_error=True) |