Spaces:
Running
Running
Curinha
commited on
Commit
·
4949a8d
1
Parent(s):
5029ee2
Update output file naming in sound_generator.py to include timestamps for unique identification
Browse files- sound_generator.py +8 -4
sound_generator.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
import torch
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Load the pretrained models and move them to GPU if available
|
| 6 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -24,9 +26,10 @@ def generate_sound(prompt: str):
|
|
| 24 |
- str: The path to the saved audio file.
|
| 25 |
"""
|
| 26 |
descriptions = [prompt]
|
|
|
|
| 27 |
wav = sound_model.generate(descriptions) # Generate audio
|
| 28 |
|
| 29 |
-
output_path = '
|
| 30 |
audio_write(output_path, wav[0].cpu(), sound_model.sample_rate, strategy="loudness")
|
| 31 |
|
| 32 |
return f"{output_path}.wav"
|
|
@@ -42,9 +45,10 @@ def generate_music(prompt: str):
|
|
| 42 |
- str: The path to the saved audio file.
|
| 43 |
"""
|
| 44 |
descriptions = [prompt]
|
|
|
|
| 45 |
wav = music_model.generate(descriptions) # Generate music
|
| 46 |
|
| 47 |
-
output_path = '
|
| 48 |
audio_write(output_path, wav[0].cpu(), music_model.sample_rate, strategy="loudness")
|
| 49 |
|
| 50 |
return f"{output_path}.wav"
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
|
| 3 |
import torch
|
| 4 |
+
from audiocraft.data.audio import audio_write
|
| 5 |
+
from audiocraft.models import AudioGen, MusicGen
|
| 6 |
|
| 7 |
# Load the pretrained models and move them to GPU if available
|
| 8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 26 |
- str: The path to the saved audio file.
|
| 27 |
"""
|
| 28 |
descriptions = [prompt]
|
| 29 |
+
timestamp = str(time.time()).replace(".", "")
|
| 30 |
wav = sound_model.generate(descriptions) # Generate audio
|
| 31 |
|
| 32 |
+
output_path = f'{prompt}_{timestamp}'
|
| 33 |
audio_write(output_path, wav[0].cpu(), sound_model.sample_rate, strategy="loudness")
|
| 34 |
|
| 35 |
return f"{output_path}.wav"
|
|
|
|
| 45 |
- str: The path to the saved audio file.
|
| 46 |
"""
|
| 47 |
descriptions = [prompt]
|
| 48 |
+
timestamp = str(time.time()).replace(".", "")
|
| 49 |
wav = music_model.generate(descriptions) # Generate music
|
| 50 |
|
| 51 |
+
output_path = f'{prompt}_{timestamp}'
|
| 52 |
audio_write(output_path, wav[0].cpu(), music_model.sample_rate, strategy="loudness")
|
| 53 |
|
| 54 |
return f"{output_path}.wav"
|