Vaishnavi0404 commited on
Commit
929facd
·
verified ·
1 Parent(s): 594632a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -106,6 +106,7 @@ def process_text_to_singing(text, voice_type="neutral", tempo=100, pitch_shift=0
106
 
107
  # Adjust tempo based on emotion if not explicitly set
108
  tempo_value = tempo
 
109
 
110
  generate_accompaniment(
111
  lyrics=text,
@@ -116,6 +117,9 @@ def process_text_to_singing(text, voice_type="neutral", tempo=100, pitch_shift=0
116
  time_signature="4/4",
117
  style=style
118
  )
 
 
 
119
 
120
  # Step 6: Mix singing voice with accompaniment
121
  final_output_path = "output_song.wav"
@@ -142,6 +146,32 @@ def process_text_to_singing(text, voice_type="neutral", tempo=100, pitch_shift=0
142
 
143
  return speech_audio_path, final_output_path
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  # Create Gradio interface
146
  with gr.Blocks(title="Text2Sing-DiffSinger") as demo:
147
  gr.Markdown("# Text2Sing-DiffSinger")
 
106
 
107
  # Adjust tempo based on emotion if not explicitly set
108
  tempo_value = tempo
109
+ accompaniment_midi_path = "temp_accompaniment.mid"
110
 
111
  generate_accompaniment(
112
  lyrics=text,
 
117
  time_signature="4/4",
118
  style=style
119
  )
120
+
121
+ accompaniment_path = "temp_accompaniment.wav"
122
+ convert_midi_to_wav(accompaniment_midi_path, accompaniment_path)
123
 
124
  # Step 6: Mix singing voice with accompaniment
125
  final_output_path = "output_song.wav"
 
146
 
147
  return speech_audio_path, final_output_path
148
 
149
+ def convert_midi_to_wav(midi_path, wav_path, soundfont_path='/usr/share/sounds/sf2/FluidR3_GM.sf2'):
150
+ """Convert MIDI file to WAV using fluidsynth"""
151
+ import subprocess
152
+
153
+ # Check if the MIDI file exists
154
+ if not os.path.exists(midi_path):
155
+ raise FileNotFoundError(f"MIDI file not found: {midi_path}")
156
+
157
+ try:
158
+ # Use fluidsynth to convert MIDI to WAV
159
+ subprocess.run([
160
+ 'fluidsynth',
161
+ '-a', 'file',
162
+ '-F', wav_path,
163
+ soundfont_path,
164
+ midi_path
165
+ ], check=True)
166
+
167
+ return wav_path
168
+ except subprocess.CalledProcessError as e:
169
+ print(f"Error converting MIDI to WAV: {e}")
170
+ raise
171
+ except FileNotFoundError:
172
+ print("fluidsynth not found. Please install it.")
173
+ raise
174
+
175
  # Create Gradio interface
176
  with gr.Blocks(title="Text2Sing-DiffSinger") as demo:
177
  gr.Markdown("# Text2Sing-DiffSinger")