Spaces:
Running
Running
c1
Browse files- app.py +8 -9
- output.mid +0 -0
app.py
CHANGED
@@ -6,8 +6,7 @@ import torch
|
|
6 |
import numpy as np
|
7 |
import pretty_midi
|
8 |
from io import BytesIO
|
9 |
-
import
|
10 |
-
|
11 |
import requests
|
12 |
|
13 |
# URL of the file to download
|
@@ -16,12 +15,12 @@ url = "https://raw.githubusercontent.com/urish/cinto/refs/heads/master/media/Flu
|
|
16 |
# Local filename to save the file
|
17 |
filename = "FluidR3_GM.sf2"
|
18 |
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
response.
|
22 |
-
|
23 |
-
with open(filename, "wb") as file:
|
24 |
-
file.write(response.content)
|
25 |
|
26 |
|
27 |
def score_to_audio(score, sample_rate: int = 44100) -> tuple[int, np.ndarray]:
|
@@ -48,8 +47,8 @@ def score_to_audio(score, sample_rate: int = 44100) -> tuple[int, np.ndarray]:
|
|
48 |
# Convert to 16-bit integer PCM
|
49 |
# Scale to full int16 range (-32768 to 32767)
|
50 |
int_audio = (float_audio * 32767).astype(np.int16)
|
51 |
-
|
52 |
-
return sample_rate,
|
53 |
|
54 |
|
55 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
6 |
import numpy as np
|
7 |
import pretty_midi
|
8 |
from io import BytesIO
|
9 |
+
import os
|
|
|
10 |
import requests
|
11 |
|
12 |
# URL of the file to download
|
|
|
15 |
# Local filename to save the file
|
16 |
filename = "FluidR3_GM.sf2"
|
17 |
|
18 |
+
if not os.path.exists(filename):
|
19 |
+
response = requests.get(url)
|
20 |
+
response.raise_for_status()
|
21 |
|
22 |
+
with open(filename, "wb") as file:
|
23 |
+
file.write(response.content)
|
|
|
|
|
|
|
24 |
|
25 |
|
26 |
def score_to_audio(score, sample_rate: int = 44100) -> tuple[int, np.ndarray]:
|
|
|
47 |
# Convert to 16-bit integer PCM
|
48 |
# Scale to full int16 range (-32768 to 32767)
|
49 |
int_audio = (float_audio * 32767).astype(np.int16)
|
50 |
+
int_audio = np.trim_zeros(int_audio, "b")
|
51 |
+
return sample_rate, int_audio
|
52 |
|
53 |
|
54 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
output.mid
DELETED
Binary file (1.51 kB)
|
|