Skip to content

Conversation

@nikunjJuspay
Copy link
Contributor

@nikunjJuspay nikunjJuspay commented Nov 5, 2025

Summary by CodeRabbit

  • Improvements
    • Enhanced text-to-speech output handling for percentages and decimal numbers with clearer conversion guidance.
    • Improved consistency in voice generation instructions and formatting.

@coderabbitai
Copy link

coderabbitai bot commented Nov 5, 2025

Walkthrough

Modified tts.py to refactor system prompt generation from early-return pattern to accumulation-based approach. Introduces general instructions with percentage handling guidance and conditionally appends provider-specific instructions for ELEVENLABS, then concatenates both sections instead of returning early or empty string.

Changes

Cohort / File(s) Summary
TTS System Prompt Refactoring
app/agents/voice/automatic/prompts/system/tts.py
Refactored control flow from early-return to accumulation pattern; introduced general_instructions block with PERCENTAGE HANDLING guidance and decimal-to-word conversion examples; conditionally assigns provider_specific_instructions for ELEVENLABS provider; returns concatenated general and provider-specific instructions instead of empty string; adjusted quote formatting to standard double quotes

Sequence Diagram

sequenceDiagram
    autonumber
    participant Old as Old Flow
    participant New as New Flow
    
    Old->>Old: Check if ELEVENLABS?
    alt ELEVENLABS
        Old->>Old: Return provider-specific string
        Note over Old: Early exit
    else Other Provider
        Old->>Old: Return empty string
    end
    
    New->>New: Initialize general_instructions
    New->>New: Add PERCENTAGE HANDLING guidance
    New->>New: Initialize empty provider_specific_instructions
    New->>New: Check if ELEVENLABS?
    alt ELEVENLABS
        New->>New: Assign provider-specific block
    end
    New->>New: Concatenate general + provider-specific
    New->>New: Return combined instructions
    Note over New: Unified return path
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify the new general instructions content, particularly PERCENTAGE HANDLING examples and decimal-to-word conversions
  • Confirm provider-specific instructions for ELEVENLABS are preserved correctly after refactoring
  • Check quote formatting changes don't introduce any unintended parsing issues
  • Validate the concatenation logic produces correctly formatted instructions string

Poem

🐰 A system prompt takes new shape today,
Where instructions flow and blend just right,
No early exits block the way—
General and provider dance in light,
Now every word finds its proper place! ✨

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the specific bug being fixed - TTS breaking on percentage handling - which aligns with the main change of adding explicit percentage handling guidance and decimal-to-word conversion examples.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbb467e and 3cdea02.

📒 Files selected for processing (1)
  • app/agents/voice/automatic/prompts/system/tts.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/agents/voice/automatic/prompts/system/tts.py (1)
app/agents/voice/automatic/types/models.py (1)
  • TTSProvider (8-10)
🔇 Additional comments (2)
app/agents/voice/automatic/prompts/system/tts.py (2)

9-17: LGTM! Clear percentage handling guidance.

The general instructions provide comprehensive examples for handling percentages with decimals in TTS, directly addressing the PR objective. The guidance to replace decimal symbols with "point" is appropriate for TTS engines.


30-30: Behavioral change confirmed as intentional bug fix.

The git history shows commit 3cdea02 ("Fixed tts breaking on percentages") deliberately refactored the function to extract general percentage handling instructions and return them for all TTS providers, while preserving ELEVENLABS-specific currency/number handling. This was done as a bug fix to address percentage pronunciation issues across all TTS engines—a general concern, not provider-specific.

The change is correct and the code is ready.

Comment on lines +21 to 28
provider_specific_instructions = """
CURRENCY & NUMBER HANDLING
Do not include any currency symbols (₹, $, etc.) in your spoken responses.
For any number with more than two digits, expand it using a **digit-word hybrid format** for natural speech. Say numbers using digits for major units and words for place values.
- Example: 322 → say 3 hundred 22 rupees
- Example: 45,099 → say 45 thousand 99 rupees
- Example: "322" → say "3 hundred 22 rupees"
- Example: "45,099" → say "45 thousand 99 rupees"
"""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Fix indentation in provider-specific instructions.

The multi-line string for provider_specific_instructions has inconsistent indentation that will include unnecessary leading whitespace in the output.

Apply this diff to fix the indentation:

-        provider_specific_instructions = """
-            CURRENCY & NUMBER HANDLING
-            Do not include any currency symbols (₹, $, etc.) in your spoken responses.
-
-            For any number with more than two digits, expand it using a **digit-word hybrid format** for natural speech. Say numbers using digits for major units and words for place values.
-            - Example: "322" → say "3 hundred 22 rupees"
-            - Example: "45,099" → say "45 thousand 99 rupees"
-        """
+        provider_specific_instructions = """
+CURRENCY & NUMBER HANDLING
+Do not include any currency symbols (₹, $, etc.) in your spoken responses.
+
+For any number with more than two digits, expand it using a **digit-word hybrid format** for natural speech. Say numbers using digits for major units and words for place values.
+- Example: "322" → say "3 hundred 22 rupees"
+- Example: "45,099" → say "45 thousand 99 rupees"
+"""

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In app/agents/voice/automatic/prompts/system/tts.py around lines 21 to 28, the
multi-line string assigned to provider_specific_instructions contains
inconsistent leading indentation which will embed unwanted whitespace in the
string; reformat the triple-quoted string so its content lines are left-aligned
(no extra leading spaces), preserving line breaks and punctuation exactly as
intended, so the string contains clean text without leading indentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant