From 6de3d6eedce0d3e5c4f0a7f00f38d9a1d4b9b8f8 Mon Sep 17 00:00:00 2001 From: harry Date: Mon, 13 May 2024 18:29:59 +0800 Subject: [PATCH] 1. support voice preview 2, update version to 1.1.6 --- app/config/config.py | 2 +- app/services/voice.py | 1 + webui/Main.py | 24 ++++++++++++++++++++++++ webui/i18n/de.json | 6 +++++- webui/i18n/en.json | 6 +++++- webui/i18n/vi.json | 6 +++++- webui/i18n/zh.json | 6 +++++- 7 files changed, 46 insertions(+), 5 deletions(-) diff --git a/app/config/config.py b/app/config/config.py index 1d53c1f..ee10fb6 100644 --- a/app/config/config.py +++ b/app/config/config.py @@ -56,7 +56,7 @@ listen_port = _cfg.get("listen_port", 8080) project_name = _cfg.get("project_name", "MoneyPrinterTurbo") project_description = _cfg.get("project_description", "https://github.com/harry0703/MoneyPrinterTurbo") -project_version = _cfg.get("project_version", "1.1.5") +project_version = _cfg.get("project_version", "1.1.6") reload_debug = False imagemagick_path = app.get("imagemagick_path", "") diff --git a/app/services/voice.py b/app/services/voice.py index 5474fac..2611835 100644 --- a/app/services/voice.py +++ b/app/services/voice.py @@ -1035,6 +1035,7 @@ def tts(text: str, voice_name: str, voice_file: str) -> [SubMaker, None]: def azure_tts_v1(text: str, voice_name: str, voice_file: str) -> [SubMaker, None]: + voice_name = parse_voice_name(voice_name) text = text.strip() for i in range(3): try: diff --git a/webui/Main.py b/webui/Main.py index 307fd0c..857ee73 100644 --- a/webui/Main.py +++ b/webui/Main.py @@ -416,6 +416,10 @@ with middle_panel: index=0) with st.container(border=True): st.write(tr("Audio Settings")) + + # tts_providers = ['edge', 'azure'] + # tts_provider = st.selectbox(tr("TTS Provider"), tts_providers) + voices = voice.get_all_azure_voices( filter_locals=support_locales) friendly_names = { @@ -442,6 +446,26 @@ with middle_panel: params.voice_name = voice_name config.ui['voice_name'] = voice_name + if st.button(tr("Play Voice")): + play_content = params.video_subject + if not play_content: + play_content = params.video_script + if not play_content: + play_content = tr("Voice Example") + with st.spinner(tr("Synthesizing Voice")): + temp_dir = utils.storage_dir("temp", create=True) + audio_file = os.path.join(temp_dir, f"tmp-voice-{str(uuid4())}.mp3") + sub_maker = voice.tts(text=play_content, voice_name=voice_name, voice_file=audio_file) + # if the voice file generation failed, try again with a default content. + if not sub_maker: + play_content = "This is a example voice. if you hear this, the voice synthesis failed with the original content." + sub_maker = voice.tts(text=play_content, voice_name=voice_name, voice_file=audio_file) + + if sub_maker and os.path.exists(audio_file): + st.audio(audio_file, format="audio/mp3") + if os.path.exists(audio_file): + os.remove(audio_file) + if voice.is_azure_v2_voice(voice_name): saved_azure_speech_region = config.azure.get(f"speech_region", "") saved_azure_speech_key = config.azure.get(f"speech_key", "") diff --git a/webui/i18n/de.json b/webui/i18n/de.json index 4a4cfd4..d3c5be9 100644 --- a/webui/i18n/de.json +++ b/webui/i18n/de.json @@ -66,6 +66,10 @@ "TikTok": "TikTok (TikTok support is coming soon)", "Bilibili": "Bilibili (Bilibili support is coming soon)", "Xiaohongshu": "Xiaohongshu (Xiaohongshu support is coming soon)", - "Local file": "Local file" + "Local file": "Local file", + "Play Voice": "Play Voice", + "Voice Example": "This is an example text for testing speech synthesis", + "Synthesizing Voice": "Synthesizing voice, please wait...", + "TTS Provider": "Select the voice synthesis provider" } } \ No newline at end of file diff --git a/webui/i18n/en.json b/webui/i18n/en.json index 5136b92..2933665 100644 --- a/webui/i18n/en.json +++ b/webui/i18n/en.json @@ -67,6 +67,10 @@ "TikTok": "TikTok (TikTok support is coming soon)", "Bilibili": "Bilibili (Bilibili support is coming soon)", "Xiaohongshu": "Xiaohongshu (Xiaohongshu support is coming soon)", - "Local file": "Local file" + "Local file": "Local file", + "Play Voice": "Play Voice", + "Voice Example": "This is an example text for testing speech synthesis", + "Synthesizing Voice": "Synthesizing voice, please wait...", + "TTS Provider": "Select the voice synthesis provider" } } \ No newline at end of file diff --git a/webui/i18n/vi.json b/webui/i18n/vi.json index e9be295..45a510b 100644 --- a/webui/i18n/vi.json +++ b/webui/i18n/vi.json @@ -67,6 +67,10 @@ "TikTok": "TikTok (TikTok support is coming soon)", "Bilibili": "Bilibili (Bilibili support is coming soon)", "Xiaohongshu": "Xiaohongshu (Xiaohongshu support is coming soon)", - "Local file": "Local file" + "Local file": "Local file", + "Play Voice": "Play Voice", + "Voice Example": "This is an example text for testing speech synthesis", + "Synthesizing Voice": "Synthesizing voice, please wait...", + "TTS Provider": "Select the voice synthesis provider" } } diff --git a/webui/i18n/zh.json b/webui/i18n/zh.json index 3702f16..d7e596b 100644 --- a/webui/i18n/zh.json +++ b/webui/i18n/zh.json @@ -67,6 +67,10 @@ "TikTok": "抖音 (TikTok 支持中,敬请期待)", "Bilibili": "哔哩哔哩 (Bilibili 支持中,敬请期待)", "Xiaohongshu": "小红书 (Xiaohongshu 支持中,敬请期待)", - "Local file": "本地文件" + "Local file": "本地文件", + "Play Voice": "试听语音合成", + "Voice Example": "这是一段测试语音合成的示例文本", + "Synthesizing Voice": "语音合成中,请稍候...", + "TTS Provider": "语音合成提供商" } } \ No newline at end of file