Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,27 +22,26 @@ else:
|
|
| 22 |
# ✅ Sound generation tool with structured docstring for smolagents
|
| 23 |
@tool
|
| 24 |
def generate_sound(sound_type: str, duration: int) -> str:
|
| 25 |
-
"""
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
duration (int): The duration of the sound in seconds (integer).
|
| 31 |
|
| 32 |
Returns:
|
| 33 |
-
|
| 34 |
"""
|
| 35 |
try:
|
| 36 |
-
duration_ms = duration * 1000
|
| 37 |
-
output_path = f"/home/user/app/{sound_type}_{duration}s.wav"
|
| 38 |
-
|
| 39 |
if sound_type == "rain":
|
| 40 |
sound = WhiteNoise().to_audio_segment(duration=duration_ms).low_pass_filter(5000)
|
|
|
|
| 41 |
else:
|
| 42 |
return f"Unsupported sound type: {sound_type}"
|
| 43 |
|
|
|
|
| 44 |
sound.export(output_path, format="wav")
|
| 45 |
-
return output_path
|
| 46 |
|
| 47 |
except Exception as e:
|
| 48 |
return f"Error generating sound: {str(e)}"
|
|
|
|
| 22 |
# ✅ Sound generation tool with structured docstring for smolagents
|
| 23 |
@tool
|
| 24 |
def generate_sound(sound_type: str, duration: int) -> str:
|
| 25 |
+
"""Generates a simple sound based on the specified type and duration.
|
| 26 |
+
|
| 27 |
+
Args:
|
| 28 |
+
sound_type: Type of sound to generate (e.g., 'rain', 'white_noise').
|
| 29 |
+
duration: Duration of the sound in seconds.
|
|
|
|
| 30 |
|
| 31 |
Returns:
|
| 32 |
+
Path to the generated audio file.
|
| 33 |
"""
|
| 34 |
try:
|
| 35 |
+
duration_ms = duration * 1000 # Convert to milliseconds
|
|
|
|
|
|
|
| 36 |
if sound_type == "rain":
|
| 37 |
sound = WhiteNoise().to_audio_segment(duration=duration_ms).low_pass_filter(5000)
|
| 38 |
+
|
| 39 |
else:
|
| 40 |
return f"Unsupported sound type: {sound_type}"
|
| 41 |
|
| 42 |
+
output_path = f"/tmp/{sound_type}_{duration}s.wav"
|
| 43 |
sound.export(output_path, format="wav")
|
| 44 |
+
return output_path
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error generating sound: {str(e)}"
|