Zacgo commited on
Commit
70cfc82
1 Parent(s): 2d0ef1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -29
app.py CHANGED
@@ -25,13 +25,14 @@ from infer import *
25
  import logging
26
  from infer_tools.infer_tool import *
27
  import io
 
 
28
 
29
  clip_completed = False
30
- def render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title2):
31
  logging.getLogger('numba').setLevel(logging.WARNING)
32
  title = int(title)
33
  title2 = int(title2)
34
-
35
  project_name = "Unnamed"
36
  model_path = ckpt_temp_file
37
  config_path= config_temp_file
@@ -43,15 +44,33 @@ def render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title
43
  key = title # 音高调整,支持正负(半音)
44
  # 加速倍数
45
  pndm_speedup = 20
46
- wav_gen='queeeeee.wav'
47
 
48
  # Show the spinner and run the run_clip function inside the 'with' block
49
  with st.spinner("Rendering Audio..."):
50
- f0_tst, f0_pred, audio = run_clip(svc_model,file_path=wav_fn, key=key, acc=title2, use_crepe=True, use_pe=True, thre=0.05,
51
- use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  clip_completed = True
53
  if clip_completed:
54
-
55
  st.audio(wav_gen)
56
 
57
  #######################################################
@@ -61,11 +80,10 @@ st.set_page_config(
61
  initial_sidebar_state="expanded",
62
  )
63
  ############
64
- st.title('DIFF-SVC Render')
65
-
66
- ###CKPT LOADER
67
- ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')
68
- # Check if user uploaded a CKPT file
69
  if ckpt is not None:
70
  #TEMP FUNCTION
71
  with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp:
@@ -80,8 +98,7 @@ if ckpt is not None:
80
  if "ckpt_temp_file" in locals():
81
  st.success("File saved to: {}".format(ckpt_temp_file))
82
  # File uploader
83
- config = st.file_uploader("Choose your config", type= 'yaml')
84
- # Check if user uploaded a config file
85
  if config is not None:
86
  #TEMP FUNCTION
87
  with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
@@ -95,8 +112,8 @@ if config is not None:
95
  # Display the file path
96
  if "config_temp_file" in locals():
97
  st.success("File saved to: {}".format(config_temp_file))
98
- audio = st.file_uploader("Choose your audio", type=["wav"])
99
- # Check if user uploaded an audio file
100
  if audio is not None:
101
  #EMP FUNCTION
102
  with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp:
@@ -110,17 +127,25 @@ if audio is not None:
110
  # Display the file path
111
  if "audio_temp_file" in locals():
112
  st.success("File saved to: {}".format(audio_temp_file))
113
- # Add a text input for the title with a default value of 0
114
- title = st.text_input("Key", value="0")
115
- title2 = st.text_input("Speedup", value="20")
116
- # Add a button to start the rendering process
117
- # Add a button to start the rendering process
118
- # if st.button("Render audio"):
119
- # password = st.text_input("Enter password")
120
- # with open("network/hubert/Hifi.txt", "r") as f:
121
- # correct_password = f.read().strip()
122
- # if password == correct_password:
123
- # render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title2)
124
- #
125
- # else:
126
- # st.error("Incorrect password")
 
 
 
 
 
 
 
 
 
25
  import logging
26
  from infer_tools.infer_tool import *
27
  import io
28
+ import parselmouth
29
+ from parselmouth.praat import call
30
 
31
  clip_completed = False
32
+ def render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title2, title3, choice, noise_step, use_mel_as_base):
33
  logging.getLogger('numba').setLevel(logging.WARNING)
34
  title = int(title)
35
  title2 = int(title2)
 
36
  project_name = "Unnamed"
37
  model_path = ckpt_temp_file
38
  config_path= config_temp_file
 
44
  key = title # 音高调整,支持正负(半音)
45
  # 加速倍数
46
  pndm_speedup = 20
47
+ wav_gen='que.wav'
48
 
49
  # Show the spinner and run the run_clip function inside the 'with' block
50
  with st.spinner("Rendering Audio..."):
51
+ f0_tst, f0_pred, audio = run_clip(svc_model,file_path=wav_fn, key=key, acc=title2, use_crepe=choice, use_pe=False, thre=0.05,
52
+ use_gt_mel=use_mel_as_base, add_noise_step=noise_step,project_name=project_name,out_path=wav_gen)
53
+ ##PRAAT
54
+ formant_shift_ratio_str = title3
55
+ formant_shift_ratio = float(formant_shift_ratio_str)
56
+
57
+ # If the formant shift ratio is not equal to 1.0, change the gender of the sound using parselmouth
58
+ if formant_shift_ratio != 1.0:
59
+ sound = parselmouth.Sound(wav_gen)
60
+ print(wav_gen)
61
+ sound.get_power()
62
+ sampling_rate = sound.sampling_frequency
63
+ print(sampling_rate)
64
+ resampled_sound = sound.resample(sampling_rate)
65
+ print(resampled_sound)
66
+ factor = formant_shift_ratio
67
+ print(factor)
68
+ manipulated_sound = call(sound, "Change gender", 75, 500, factor, 0, 1, 1)
69
+ print(manipulated_sound)
70
+ manipulated_sound.save("que.wav", "WAV")
71
+ print("Gender correct!")
72
  clip_completed = True
73
  if clip_completed:
 
74
  st.audio(wav_gen)
75
 
76
  #######################################################
 
80
  initial_sidebar_state="expanded",
81
  )
82
  ############
83
+ col1, col2 = st.columns(2)
84
+ col1.title('DIFF-SVC Render')
85
+ col2.title('Settings')
86
+ ckpt = col1.file_uploader("Choose your CKPT", type='ckpt')
 
87
  if ckpt is not None:
88
  #TEMP FUNCTION
89
  with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp:
 
98
  if "ckpt_temp_file" in locals():
99
  st.success("File saved to: {}".format(ckpt_temp_file))
100
  # File uploader
101
+ config = col1.file_uploader("Choose your config", type='yaml')
 
102
  if config is not None:
103
  #TEMP FUNCTION
104
  with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
 
112
  # Display the file path
113
  if "config_temp_file" in locals():
114
  st.success("File saved to: {}".format(config_temp_file))
115
+
116
+ audio = col1.file_uploader("Choose your audio", type=["wav"])
117
  if audio is not None:
118
  #EMP FUNCTION
119
  with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp:
 
127
  # Display the file path
128
  if "audio_temp_file" in locals():
129
  st.success("File saved to: {}".format(audio_temp_file))
130
+
131
+ title = col2.number_input("Key", value=0, step=1, min_value=-12, max_value=12)
132
+ title2 = col2.number_input("Speedup", value=20, step=1, min_value=1, max_value=100)
133
+ title3 = col2.number_input("Gender Flag", value=1.00, step=0.01, min_value=0.70, max_value=1.30, help='Default is 1.0, it works by decimals, setting it at 1.05 will make your render sound more female-ish, setting it to 0.95 will make it sound more masculine, for example.')
134
+ choice = col2.checkbox('Use Crepe', value=False)
135
+ # Create checkbox for using Mel as Base
136
+ use_mel_as_base = col2.checkbox('Use Mel as Base', value=False, help='gt mel: Enabling this will use the input audio as a base and will unlock a new parameter, do not use this if you dont know what it does.')
137
+ noise_step = 600
138
+ # Show "Noise Step" input parameter when checkbox is checked
139
+ if use_mel_as_base:
140
+ noise_step = col2.number_input('Noise Step', value=600, min_value=1, max_value=1000, step=50)
141
+ else:
142
+ noise_step = 600
143
+ password = col2.text_input("Enter password", help='Hi,Zacgo')
144
+ correct_password = "Zacgo"
145
+ ###
146
+ if st.button("Render audio"):
147
+ if password == "Zacgo":
148
+ render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title2, title3, noise_step, choice, use_mel_as_base)
149
+
150
+ else:
151
+ render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title2, title3, noise_step, choice, use_mel_as_base)