Skip to content

Commit

Permalink
Enable user to exit podcast generation gracefully (#74)
Browse files Browse the repository at this point in the history
* Add try/except if user wants to stop podcast gen early

* Add feature note in docs
  • Loading branch information
Kostis-S-Z authored Jan 9, 2025
1 parent 6cb80f4 commit d88c330
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
2 changes: 2 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ document-to-podcast \
--text_to_text_model "Qwen/Qwen2.5-1.5B-Instruct-GGUF/qwen2.5-1.5b-instruct-q8_0.gguf"
```

Note that you can also exit the podcast generation prematurely (before the whole podcast is created), by pressing Ctrl+C in the terminal. This will make the application stop the generation, but still save the result (script & audio) to disk up until that point.

---

::: document_to_podcast.cli.document_to_podcast
Expand Down
45 changes: 24 additions & 21 deletions src/document_to_podcast/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,30 @@ def document_to_podcast(
system_prompt = system_prompt.replace(
"{SPEAKERS}", "\n".join(str(speaker) for speaker in config.speakers)
)
for chunk in text_to_text_stream(
clean_text, text_model, system_prompt=system_prompt
):
text += chunk
podcast_script += chunk
if text.endswith("\n") and "Speaker" in text:
logger.debug(text)
speaker_id = re.search(r"Speaker (\d+)", text).group(1)
voice_profile = next(
speaker.voice_profile
for speaker in config.speakers
if speaker.id == int(speaker_id)
)
speech = text_to_speech(
text.split(f'"Speaker {speaker_id}":')[-1],
speech_model,
voice_profile,
tokenizer=speech_tokenizer, # Applicable only for parler models
)
podcast_audio.append(speech)
text = ""
try:
for chunk in text_to_text_stream(
clean_text, text_model, system_prompt=system_prompt
):
text += chunk
podcast_script += chunk
if text.endswith("\n") and "Speaker" in text:
logger.debug(text)
speaker_id = re.search(r"Speaker (\d+)", text).group(1)
voice_profile = next(
speaker.voice_profile
for speaker in config.speakers
if speaker.id == int(speaker_id)
)
speech = text_to_speech(
text.split(f'"Speaker {speaker_id}":')[-1],
speech_model,
voice_profile,
tokenizer=speech_tokenizer, # Applicable only for parler models
)
podcast_audio.append(speech)
text = ""
except KeyboardInterrupt:
logger.warning("Podcast generation stopped by user.")

logger.info("Saving Podcast...")
sf.write(
Expand Down

0 comments on commit d88c330

Please sign in to comment.