Updating requirements and app.py
Browse files- app.py +13 -4
- requirements.txt +1 -0
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
from transformers import pipeline
|
3 |
import scipy.io.wavfile
|
4 |
import tempfile
|
|
|
5 |
|
6 |
|
7 |
# -----------------------------------------------------------
|
@@ -29,11 +30,19 @@ def main():
|
|
29 |
if user_text:
|
30 |
music = synthesizer(user_text, forward_params={"do_sample": True})
|
31 |
|
32 |
-
with tempfile.NamedTemporaryFile(delete=
|
33 |
print(f"Temporary file created at: {tmp.name}")
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
st.audio(tmp.name, format="audio/wav", start_time=0)
|
38 |
|
39 |
except Exception as e:
|
|
|
2 |
from transformers import pipeline
|
3 |
import scipy.io.wavfile
|
4 |
import tempfile
|
5 |
+
import numpy as np
|
6 |
|
7 |
|
8 |
# -----------------------------------------------------------
|
|
|
30 |
if user_text:
|
31 |
music = synthesizer(user_text, forward_params={"do_sample": True})
|
32 |
|
33 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
|
34 |
print(f"Temporary file created at: {tmp.name}")
|
35 |
+
# Ensure the audio data is in the correct format (int16 for WAV)
|
36 |
+
if music["audio"].dtype != np.int16:
|
37 |
+
# Assuming the audio is normalized between -1 and 1, scale to int16
|
38 |
+
audio_data = np.int16(music["audio"] / np.max(np.abs(music["audio"])) * 32767)
|
39 |
+
else:
|
40 |
+
audio_data = music["audio"]
|
41 |
+
|
42 |
+
# Write the audio data to the temporary file
|
43 |
+
scipy.io.wavfile.write(tmp.name, rate=music["sampling_rate"], data=audio_data)
|
44 |
+
|
45 |
+
# Display the audio player in Streamlit
|
46 |
st.audio(tmp.name, format="audio/wav", start_time=0)
|
47 |
|
48 |
except Exception as e:
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
transformers
|
2 |
scipy
|
3 |
torch
|
|
|
|
1 |
transformers
|
2 |
scipy
|
3 |
torch
|
4 |
+
numpy
|