diff --git a/infer-web.py b/infer-web.py index 4bb9c0b..2098c39 100644 --- a/infer-web.py +++ b/infer-web.py @@ -57,14 +57,21 @@ os.environ["TEMP"] = tmp warnings.filterwarnings("ignore") torch.manual_seed(114514) -DoFormant = False -Quefrency = 8.0 -Timbre = 1.2 +global DoFormant, Quefrency, Timbre -with open('formanting.txt', 'w+') as fsf: - fsf.truncate(0) - fsf.writelines([str(DoFormant) + '\n', str(Quefrency) + '\n', str(Timbre) + '\n']) +try: + with open('formanting.txt', 'r') as psx: + content = psx.readlines() + Quefrency, Timbre = content[1].split('\n')[0], content[2].split('\n')[0] + DoFormant = True if content[0].split('\n')[0] == 'True' else False + +except Exception: + with open('formanting.txt', 'w+') as fsf: + fsf.truncate(0) + DoFormant = False + Quefrency, Timbre = 8.0, 1.2 + fsf.writelines([str(DoFormant) + '\n', str(Quefrency) + '\n', str(Timbre) + '\n']) config = Config() @@ -2126,7 +2133,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app: ) formant_preset.change(fn=preset_apply, inputs=[formant_preset, qfrency, tmbre], outputs=[qfrency, tmbre]) - frmntbut = gr.Button("Apply", variant="primary", visible=False) + frmntbut = gr.Button("Apply", variant="primary", visible=DoFormant) formanting.change(fn=formant_enabled,inputs=[formanting,qfrency,tmbre,frmntbut,formant_preset,formant_refresh_button],outputs=[formanting,qfrency,tmbre,frmntbut,formant_preset,formant_refresh_button]) frmntbut.click(fn=formant_apply,inputs=[qfrency, tmbre], outputs=[qfrency, tmbre]) formant_refresh_button.click(fn=update_fshift_presets,inputs=[formant_preset, qfrency, tmbre],outputs=[formant_preset, qfrency, tmbre]) diff --git a/my_utils.py b/my_utils.py index 90eeb52..c939798 100644 --- a/my_utils.py +++ b/my_utils.py @@ -34,15 +34,14 @@ def load_audio(file, sr, DoFormant, Quefrency, Timbre): # os.system(f"stftpitchshift -i {file} -q {Quefrency} -t {Timbre} -o {file_formanted}") # print('stftpitchshift -i "%s" -p 1.0 --rms -w 128 -v 8 -q %s -t %s -o "%s"' % (file, Quefrency, Timbre, file_formanted)) print("formanting...") - os.system( - 'stftpitchshift -i "%s" -q %s -t %s -o "%sFORMANTED"' + 'runtime\Scripts\stftpitchshift.exe -i "%s" -q %s -t %s -o "%sFORMANTED"' % (file, Quefrency, Timbre, file_formanted) ) print("formanted!") # filepraat = (os.path.abspath(os.getcwd()) + '\\' + file).replace('/','\\') # file_formantedpraat = ('"' + os.path.abspath(os.getcwd()) + '/' + 'formanted'.join(file_formanted) + '"').replace('/','\\') - + out, _ = ( ffmpeg.input("%sFORMANTED%s" % (file_formanted, ".wav"), threads=0) .output("-", format="f32le", acodec="pcm_f32le", ac=1, ar=sr)