codejin/diffsingerkr
6
1import streamlit as st2 3from Inference import Inferencer4 5def app_diffsingerkr():6 if not 'diffsingerkr_duration' in st.session_state.keys():7 st.session_state.diffsingerkr_duration = ''8 if not 'diffsingerkr_lyric' in st.session_state.keys():9 st.session_state.diffsingerkr_lyric = ''10 if not 'diffsingerkr_note' in st.session_state.keys():11 st.session_state.diffsingerkr_note = ''12 if not 'inferencer' in st.session_state.keys():13 st.session_state.inferencer = Inferencer(14 hp_path= 'Hyper_Parameters.yaml',15 checkpoint_path= 'Checkpoint/S_200000.pt',16 batch_size= 117 )18 19 st.title('DiffSinger-KR')20 st.markdown('* This code is an implementation of DiffSinger for Korean.')21 st.markdown('* When music score which is note, duration, and lyric information are entered, singing voices are synthesized accordingly.')22 st.markdown('* Due to the range of the trained dataset, the supported notes are between 65 and 89.')23 st.markdown('* Please refer to the [here](https://github.com/CODEJIN/DiffSingerKR) for the source code for training the model.')24 25 st.markdown('''---''')26 status_indicator = st.empty()27 status_indicator.header('Insert the music!')28 st.markdown('''---''') 29 example1_col, example2_col, example3_col, _ = st.columns(4)30 if example1_col.button('Example 1'):31 st.session_state.diffsingerkr_duration = '0.52,0.17,0.35,0.35,0.35,0.35,0.70,0.35,0.35,0.70,0.35,0.35,0.70,0.52,0.17,0.35,0.35,0.35,0.35,0.70,0.35,0.35,0.35,0.35,1.39'32 st.session_state.diffsingerkr_lyric = '떴,다,떴,다,비,행,기,날,아,라,날,아,라,높,이,높,이,날,아,라,우,리,비,행,기'33 st.session_state.diffsingerkr_note = '76,74,72,74,76,76,76,74,74,74,76,79,79,76,74,72,74,76,76,76,74,74,76,74,72'34 st.experimental_rerun()35 if example2_col.button('Example 2'):36 st.session_state.diffsingerkr_duration = '0.53,0.52,0.50,0.57,0.58,0.46,0.48,0.50,0.37,0.13,0.43,0.21,0.57,0.43,0.49,1.44,0.26,0.49,0.14,0.13,0.57,0.26,0.06,0.15,0.63,0.26,0.51,0.20,0.48,0.72,0.22'37 st.session_state.diffsingerkr_lyric = '만,나,고,<X>,난,외,로,움,을,<X>,알,았,어,내,겐,<X>,관,심,조,<X>,차,<X>,없,<X>,다,는,걸,<X>,알,면,서'38 st.session_state.diffsingerkr_note = '76,78,79,0,71,74,72,71,72,0,71,69,69,71,74,0,79,78,79,0,71,0,74,0,74,72,72,0,71,71,69'39 st.experimental_rerun()40 if example3_col.button('Example 3'):41 st.session_state.diffsingerkr_duration = '0.33,0.16,0.33,0.49,0.33,0.16,0.81,0.33,0.16,0.16,0.33,0.16,0.49,0.16,0.82,0.33,0.16,0.33,0.49,0.33,0.16,0.33,0.49,0.33,0.33,0.16,0.33,1.47,0.33,0.16,0.33,0.49,0.33,0.16,0.81,0.33,0.16,0.16,0.33,0.16,0.49,0.16,0.82,0.33,0.16,0.33,0.16,0.33,0.49,0.16,0.33,0.33,0.33,0.33,0.16,0.33,0.82'42 st.session_state.diffsingerkr_lyric = '마,음,울,적,한,날,에,<X>,거,리,를,걸,어,보,고,향,기,로,운,칵,테,일,에,취,해,도,보,고,한,편,의,시,가,있,는,<X>,전,시,회,장,도,가,고,밤,새,도,<X>,록,그,리,움,에,편,질,쓰,고,파'43 st.session_state.diffsingerkr_note = '80,80,80,87,85,84,82,0,84,84,84,85,84,79,79,77,77,77,80,80,78,77,75,77,80,79,80,82,80,80,80,87,85,84,82,0,84,84,84,85,84,79,79,77,77,77,79,80,80,77,75,75,77,80,79,82,80'44 st.experimental_rerun()45 st.markdown('''---''')46 duration = st.text_input('Duration', value= st.session_state.diffsingerkr_duration)47 lyric = st.text_input('Lyric', value= st.session_state.diffsingerkr_lyric)48 note = st.text_input('Note', value= st.session_state.diffsingerkr_note)49 singer = 'CSD'50 genre = 'Children'51 key_adjustment = st.select_slider(52 label= 'Key adjustment',53 options= [x for x in range(-6, 7)],54 value= 055 )56 57 if st.button("Generate!"):58 if duration != '' and lyric != '' and note != '':59 status_indicator.header('Generating...')60 audio = st.session_state.inferencer.Inference_Epoch(61 message_times_list= [[float(x) for x in duration.strip().split(',')]],62 lyrics= [[x for x in lyric.strip().split(',')]],63 notes= [[64 (int(x) + key_adjustment if int(x) != 0 else int(x))65 for x in note.strip().split(',')66 ]],67 singers= [singer],68 genres= [genre]69 )[0]70 71 st.audio(72 audio,73 format="audio/wav",74 start_time=0,75 sample_rate= st.session_state.inferencer.hp.Sound.Sample_Rate76 )77 78 status_indicator.header('Done.')79 80if __name__ == '__main__':81 app_diffsingerkr()