File size: 837 Bytes
0a405d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torch
import scipy
import numpy as np
from diffusers import AudioLDMPipeline

pipe = AudioLDMPipeline.from_pretrained(
    "cvssp/audioldm-m-full",
    torch_dtype=torch.float32
).to("cpu")

def generate_audio_from_description(description, output_path="output.wav"):
    audio = pipe(description, num_inference_steps=50).audios[0]
    audio_np = (audio * 32767).astype(np.int16)
    scipy.io.wavfile.write(output_path, rate=16000, data=audio_np)
    return output_path

iface = gr.Interface(
    fn=generate_audio_from_description,
    inputs=gr.Textbox(lines=2, placeholder="e.g., Stirring onions in a hot pan"),
    outputs=gr.Audio(label="Generated Audio", type="filepath"),
    title="🍳 Cooking Sound Generator",
    description="Enter a cooking action. Get the sound it would make."
)

iface.launch()