Auto-update: Thu Aug 8 06:18:49 PDT 2024

This commit is contained in:
sanj 2024-08-08 06:18:49 -07:00
parent ecd06715dd
commit 1f4c7622d3
3 changed files with 8 additions and 10 deletions

View file

@ -1,9 +1,5 @@
''' '''
Image generation module using StableDiffusion and similar models by way of ComfyUI. Image generation module using StableDiffusion and similar models by way of ComfyUI.
DEPENDS ON:
LLM module
COMFYUI_URL, COMFYUI_DIR, COMFYUI_OUTPUT_DIR, TS_SUBNET, TS_ADDRESS, DATA_DIR, IMG_CONFIG_DIR, IMG_DIR, IMG_WORKFLOWS_DIR, LOCAL_HOSTS
*unimplemented.
''' '''
#routers/img.py #routers/img.py

View file

@ -65,7 +65,7 @@ async def generate_summary(text: str) -> str:
summary = await llm.summarize_text(text, "Summarize the provided text. Respond with the summary and nothing else.") summary = await llm.summarize_text(text, "Summarize the provided text. Respond with the summary and nothing else.")
return summary.replace('\n', ' ') return summary.replace('\n', ' ')
async def handle_tts(bg_tasks: BackgroundTasks, article: Article, title: str, tts_mode: str, voice: str, summary: str) -> Optional[str]: async def handle_tts(bg_tasks: BackgroundTasks, article: Article, title: str, tts_mode: str, voice: str, summary: str, model: str = "eleven_turbo_v2") -> Optional[str]:
if tts_mode in ["full", "content"]: if tts_mode in ["full", "content"]:
tts_text = article.text tts_text = article.text
elif tts_mode in ["summary", "excerpt"]: elif tts_mode in ["summary", "excerpt"]:
@ -79,12 +79,13 @@ async def handle_tts(bg_tasks: BackgroundTasks, article: Article, title: str, tt
bg_tasks=bg_tasks, bg_tasks=bg_tasks,
text=tts_text, text=tts_text,
voice=voice, voice=voice,
model="xtts", model=model,
podcast=True, podcast=True,
title=audio_filename, title=audio_filename,
output_dir=Path(OBSIDIAN_VAULT_DIR) / OBSIDIAN_RESOURCES_DIR output_dir=Path(OBSIDIAN_VAULT_DIR) / OBSIDIAN_RESOURCES_DIR
) )
return f"![[{Path(audio_path).name}]]" return f"![[{Path(audio_path).name}]]"
except HTTPException as e: except HTTPException as e:
err(f"Failed to generate TTS: {str(e)}") err(f"Failed to generate TTS: {str(e)}")
return None return None
@ -182,9 +183,6 @@ async def process_and_save_article(
# Save markdown file # Save markdown file
await save_markdown_file(markdown_filename, markdown_content) await save_markdown_file(markdown_filename, markdown_content)
# Add to daily note
# await note.add_to_daily_note(relative_path)
return f"Successfully saved: {relative_path}" return f"Successfully saved: {relative_path}"
except Exception as e: except Exception as e:

View file

@ -147,6 +147,7 @@ async def generate_speech(
if model == "eleven_turbo_v2": if model == "eleven_turbo_v2":
info("Using ElevenLabs.") info("Using ElevenLabs.")
voice = determine_voice_id(voice)
audio_file_path = await elevenlabs_tts(model, text, voice, title, output_dir) audio_file_path = await elevenlabs_tts(model, text, voice, title, output_dir)
else: # if model == "xtts": else: # if model == "xtts":
info("Using XTTS2") info("Using XTTS2")
@ -182,6 +183,7 @@ async def get_model(voice: str = None, voice_file: UploadFile = None):
async def determine_voice_id(voice_name: str) -> str: async def determine_voice_id(voice_name: str) -> str:
debug(f"Searching for voice id for {voice_name}") debug(f"Searching for voice id for {voice_name}")
# Todo: move this to tts.yaml
hardcoded_voices = { hardcoded_voices = {
"alloy": "E3A1KVbKoWSIKSZwSUsW", "alloy": "E3A1KVbKoWSIKSZwSUsW",
"echo": "b42GBisbu9r5m5n6pHF7", "echo": "b42GBisbu9r5m5n6pHF7",
@ -192,7 +194,8 @@ async def determine_voice_id(voice_name: str) -> str:
"Luna": "6TayTBKLMOsghG7jYuMX", "Luna": "6TayTBKLMOsghG7jYuMX",
"Sangye": "E7soeOyjpmuZFurvoxZ2", "Sangye": "E7soeOyjpmuZFurvoxZ2",
"Herzog": "KAX2Y6tTs0oDWq7zZXW7", "Herzog": "KAX2Y6tTs0oDWq7zZXW7",
"Attenborough": "b42GBisbu9r5m5n6pHF7" "Attenborough": "b42GBisbu9r5m5n6pHF7",
"Victoria": "7UBkHqZOtFRLq6cSMQQg"
} }
if voice_name in hardcoded_voices: if voice_name in hardcoded_voices:
@ -212,6 +215,7 @@ async def determine_voice_id(voice_name: str) -> str:
for voice in voices_data: for voice in voices_data:
if voice_name == voice["voice_id"] or voice_name == voice["name"]: if voice_name == voice["voice_id"] or voice_name == voice["name"]:
return voice["voice_id"] return voice["voice_id"]
except Exception as e: except Exception as e:
err(f"Error determining voice ID: {str(e)}") err(f"Error determining voice ID: {str(e)}")