Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import os
|
2 |
-
from flask import Flask, request, jsonify, send_file
|
3 |
import torch
|
4 |
import torchaudio
|
5 |
import librosa
|
@@ -13,6 +13,7 @@ from modules.bigvgan import bigvgan
|
|
13 |
from transformers import AutoFeatureExtractor, WhisperModel
|
14 |
from modules.audio import mel_spectrogram
|
15 |
from modules.rmvpe import RMVPE
|
|
|
16 |
|
17 |
# Initialize Flask app
|
18 |
app = Flask(__name__)
|
@@ -134,13 +135,14 @@ def voice_conversion_api():
|
|
134 |
output_wave = (output_wave * 32768.0).astype(np.int16)
|
135 |
|
136 |
# Convert to MP3 and send the response
|
137 |
-
|
|
|
138 |
output_wave.tobytes(), frame_rate=sr,
|
139 |
sample_width=output_wave.dtype.itemsize, channels=1
|
140 |
-
).export(format="mp3", bitrate="320k")
|
|
|
141 |
|
142 |
-
|
143 |
-
return send_file(mp3_bytes, mimetype="audio/mpeg", as_attachment=True, download_name="converted_audio.mp3")
|
144 |
|
145 |
if __name__ == "__main__":
|
146 |
# Run the Flask app
|
|
|
1 |
import os
|
2 |
+
from flask import Flask, request, jsonify, send_file, Response
|
3 |
import torch
|
4 |
import torchaudio
|
5 |
import librosa
|
|
|
13 |
from transformers import AutoFeatureExtractor, WhisperModel
|
14 |
from modules.audio import mel_spectrogram
|
15 |
from modules.rmvpe import RMVPE
|
16 |
+
from io import BytesIO
|
17 |
|
18 |
# Initialize Flask app
|
19 |
app = Flask(__name__)
|
|
|
135 |
output_wave = (output_wave * 32768.0).astype(np.int16)
|
136 |
|
137 |
# Convert to MP3 and send the response
|
138 |
+
mp3_file = BytesIO()
|
139 |
+
AudioSegment(
|
140 |
output_wave.tobytes(), frame_rate=sr,
|
141 |
sample_width=output_wave.dtype.itemsize, channels=1
|
142 |
+
).export(mp3_file, format="mp3", bitrate="320k")
|
143 |
+
mp3_file.seek(0) # Ensure the stream is at the beginning
|
144 |
|
145 |
+
return send_file(mp3_file, mimetype="audio/mpeg", as_attachment=True, download_name="converted_audio.mp3")
|
|
|
146 |
|
147 |
if __name__ == "__main__":
|
148 |
# Run the Flask app
|