Spaces:
Sleeping
Sleeping
File size: 1,964 Bytes
55056c0 bdac835 6ed901c bdac835 6ed901c bdac835 6ed901c bdac835 6ed901c bdac835 6ed901c bdac835 6ed901c bdac835 6ed901c 55056c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import streamlit as st
from model import generate
import io
import numpy as np
from scipy.io.wavfile import write
@st.cache_data
def np_to_wav(waveform, sample_rate) -> bytes:
bytes_wav = bytes()
byte_io = io.BytesIO(bytes_wav)
write(byte_io, sample_rate, waveform.T)
return byte_io.read()
if "result" not in st.session_state:
st.session_state["result"] = None
st.title("Sound Exploration")
col1, col2 = st.columns(2)
with col1:
instrument = st.selectbox(
'Which intrument do you want ?',
('πΈ Bass', 'πΊ Brass', 'πͺ Flute', 'πͺ Guitar', 'πΉ Keyboard', 'π¨ Mallet', 'Organ', 'π· Reed', 'π» String', 'β‘ Synth lead', 'π€ Vocal')
)
with col2:
instrument_t = st.selectbox(
'Which type intrument do you want ?',
('π― Acoustic', 'ποΈ Electronic', 'ποΈ Synthetic')
)
with st.expander("Magical parameters πͺ"):
col1, col2 = st.columns(2)
with col1:
p1 = st.slider('p1', 0., 1., step=0.001, label_visibility='collapsed')
p2 = st.slider('p2', 0., 1., step=0.001, label_visibility='collapsed')
p3 = st.slider('p3', 0., 1., step=0.001, label_visibility='collapsed')
with col2:
p4 = st.slider('p4', 0., 1., step=0.001, label_visibility='collapsed')
p5 = st.slider('p5', 0., 1., step=0.001, label_visibility='collapsed')
use_params = st.toggle('Use magical parameters ?')
params = (p1, p2, p3, p4, p5) if use_params else None
if st.button("Generate β¨", type="primary"):
st.session_state["result"] = generate([instrument, instrument_t], params)
if st.session_state["result"] is not None:
col1, col2 = st.columns(2)
with col1:
st.audio(st.session_state["result"], sample_rate=16000)
with col2:
st.download_button(
label="Download β¬οΈ",
data=np_to_wav(st.session_state["result"], 16000),
file_name='result.wav',
)
|