mirror of
https://github.com/langgenius/dify.git
synced 2026-01-14 06:07:33 +08:00
fix: remove unnecessary Flask context preservation to avoid circular import in audio service (#27380)
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Main CI Pipeline / Check Changed Files (push) Waiting to run
Main CI Pipeline / API Tests (push) Blocked by required conditions
Main CI Pipeline / Web Tests (push) Blocked by required conditions
Main CI Pipeline / Style Check (push) Waiting to run
Main CI Pipeline / VDB Tests (push) Blocked by required conditions
Main CI Pipeline / DB Migration Test (push) Blocked by required conditions
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Main CI Pipeline / Check Changed Files (push) Waiting to run
Main CI Pipeline / API Tests (push) Blocked by required conditions
Main CI Pipeline / Web Tests (push) Blocked by required conditions
Main CI Pipeline / Style Check (push) Waiting to run
Main CI Pipeline / VDB Tests (push) Blocked by required conditions
Main CI Pipeline / DB Migration Test (push) Blocked by required conditions
This commit is contained in:
parent
a4b38e7521
commit
634fb192ef
@ -82,54 +82,51 @@ class AudioService:
|
|||||||
message_id: str | None = None,
|
message_id: str | None = None,
|
||||||
is_draft: bool = False,
|
is_draft: bool = False,
|
||||||
):
|
):
|
||||||
from app import app
|
|
||||||
|
|
||||||
def invoke_tts(text_content: str, app_model: App, voice: str | None = None, is_draft: bool = False):
|
def invoke_tts(text_content: str, app_model: App, voice: str | None = None, is_draft: bool = False):
|
||||||
with app.app_context():
|
if voice is None:
|
||||||
if voice is None:
|
if app_model.mode in {AppMode.ADVANCED_CHAT, AppMode.WORKFLOW}:
|
||||||
if app_model.mode in {AppMode.ADVANCED_CHAT, AppMode.WORKFLOW}:
|
if is_draft:
|
||||||
if is_draft:
|
workflow = WorkflowService().get_draft_workflow(app_model=app_model)
|
||||||
workflow = WorkflowService().get_draft_workflow(app_model=app_model)
|
else:
|
||||||
else:
|
workflow = app_model.workflow
|
||||||
workflow = app_model.workflow
|
if (
|
||||||
if (
|
workflow is None
|
||||||
workflow is None
|
or "text_to_speech" not in workflow.features_dict
|
||||||
or "text_to_speech" not in workflow.features_dict
|
or not workflow.features_dict["text_to_speech"].get("enabled")
|
||||||
or not workflow.features_dict["text_to_speech"].get("enabled")
|
):
|
||||||
):
|
raise ValueError("TTS is not enabled")
|
||||||
|
|
||||||
|
voice = workflow.features_dict["text_to_speech"].get("voice")
|
||||||
|
else:
|
||||||
|
if not is_draft:
|
||||||
|
if app_model.app_model_config is None:
|
||||||
|
raise ValueError("AppModelConfig not found")
|
||||||
|
text_to_speech_dict = app_model.app_model_config.text_to_speech_dict
|
||||||
|
|
||||||
|
if not text_to_speech_dict.get("enabled"):
|
||||||
raise ValueError("TTS is not enabled")
|
raise ValueError("TTS is not enabled")
|
||||||
|
|
||||||
voice = workflow.features_dict["text_to_speech"].get("voice")
|
voice = text_to_speech_dict.get("voice")
|
||||||
else:
|
|
||||||
if not is_draft:
|
|
||||||
if app_model.app_model_config is None:
|
|
||||||
raise ValueError("AppModelConfig not found")
|
|
||||||
text_to_speech_dict = app_model.app_model_config.text_to_speech_dict
|
|
||||||
|
|
||||||
if not text_to_speech_dict.get("enabled"):
|
model_manager = ModelManager()
|
||||||
raise ValueError("TTS is not enabled")
|
model_instance = model_manager.get_default_model_instance(
|
||||||
|
tenant_id=app_model.tenant_id, model_type=ModelType.TTS
|
||||||
voice = text_to_speech_dict.get("voice")
|
)
|
||||||
|
try:
|
||||||
model_manager = ModelManager()
|
if not voice:
|
||||||
model_instance = model_manager.get_default_model_instance(
|
voices = model_instance.get_tts_voices()
|
||||||
tenant_id=app_model.tenant_id, model_type=ModelType.TTS
|
if voices:
|
||||||
)
|
voice = voices[0].get("value")
|
||||||
try:
|
if not voice:
|
||||||
if not voice:
|
|
||||||
voices = model_instance.get_tts_voices()
|
|
||||||
if voices:
|
|
||||||
voice = voices[0].get("value")
|
|
||||||
if not voice:
|
|
||||||
raise ValueError("Sorry, no voice available.")
|
|
||||||
else:
|
|
||||||
raise ValueError("Sorry, no voice available.")
|
raise ValueError("Sorry, no voice available.")
|
||||||
|
else:
|
||||||
|
raise ValueError("Sorry, no voice available.")
|
||||||
|
|
||||||
return model_instance.invoke_tts(
|
return model_instance.invoke_tts(
|
||||||
content_text=text_content.strip(), user=end_user, tenant_id=app_model.tenant_id, voice=voice
|
content_text=text_content.strip(), user=end_user, tenant_id=app_model.tenant_id, voice=voice
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
if message_id:
|
if message_id:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user