shikhr commited on
Commit
7a56273
·
1 Parent(s): e697813
Files changed (2) hide show
  1. app.py +8 -9
  2. 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 soundfile as sf
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
- response = requests.get(url)
21
- response.raise_for_status()
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, float_audio
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)