Skip to content

Commit

Permalink
LipsyncTTS: only add TTS cost when TTS provider is 11 labs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikochiko committed Oct 4, 2023
1 parent 087e330 commit c0a239d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
25 changes: 16 additions & 9 deletions recipes/LipsyncTTS.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import textwrap
import typing

from pydantic import BaseModel
Expand All @@ -6,7 +7,7 @@
from bots.models import Workflow
from recipes.DeforumSD import safety_checker
from recipes.Lipsync import LipsyncPage
from recipes.TextToSpeech import TextToSpeechPage
from recipes.TextToSpeech import TextToSpeechPage, TextToSpeechProviders
from daras_ai_v2.loom_video_widget import youtube_video

DEFAULT_LIPSYNC_TTS_META_IMG = "https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/assets/lipsync_meta_img.gif"
Expand Down Expand Up @@ -150,17 +151,23 @@ def render_output(self):
self.render_example(st.session_state)

def get_raw_price(self, state: dict):
return LipsyncPage.get_raw_price(self, state) + \
TextToSpeechPage.get_raw_price(self, state)
# _get_tts_provider comes from TextToSpeechPage
if self._get_tts_provider(state) == TextToSpeechProviders.ELEVEN_LABS:
return LipsyncPage.get_raw_price(self, state) + \
TextToSpeechPage.get_raw_price(self, state)
else:
return LipsyncPage.get_raw_price(self, state)

def additional_notes(self):
notes = f"""
*Cost = Lipsync Cost + TTS Cost*
"""
if lipsync_notes := LipsyncPage.additional_notes(self):
notes += "\n" + f"*Lipsync* {lipsync_notes}"
lipsync_notes = LipsyncPage.additional_notes(self)
if tts_notes := TextToSpeechPage.additional_notes(self):
notes += "\n" + f"*TTS* {tts_notes}"
notes = textwrap.dedent(f"""\
- *Lipsync* {lipsync_notes.strip()}
- *TTS* {tts_notes.strip()}
""")
else:
notes = lipsync_notes

return notes

def render_usage_guide(self):
Expand Down
6 changes: 3 additions & 3 deletions recipes/TextToSpeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def render_output(self):

def _get_eleven_labs_price(self, state: dict):
text = state.get("text_prompt", "")
# 4 credits for 10 words ~ 50 chars
return (len(text) / 50) * 4
# 0.079 credits / character ~ 4 credits / 10 words
return len(text) * 0.079

def _get_tts_provider(self, state: dict):
tts_provider = state.get(
Expand All @@ -140,7 +140,7 @@ def additional_notes(self):
tts_provider = st.session_state.get("tts_provider")
if tts_provider == TextToSpeechProviders.ELEVEN_LABS.name:
return """
*Eleven Labs cost ≈ 4 credits for every 50 characters ≈ 0.4 credits per word*
*Eleven Labs cost ≈ 4 credits per 10 words*
"""
else:
return ""
Expand Down

0 comments on commit c0a239d

Please sign in to comment.