Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for speech rate multiplier #136

Merged
merged 6 commits into from
Feb 18, 2025

Conversation

justinshannon
Copy link
Contributor

@justinshannon justinshannon commented Feb 15, 2025

Summary by CodeRabbit

  • New Features
    • Introduced an adjustable speech rate multiplier for text-to-speech audio, allowing users to personalize playback speed.
    • Added a new dropdown in the settings interface with descriptive tooltips for easy selection of available speech rates.
    • Enhanced the configuration capabilities to manage speech rates effectively, ensuring consistency across all audio interactions.

Copy link
Contributor

coderabbitai bot commented Feb 15, 2025

Walkthrough

This update introduces a speech rate feature across the application. A new property for speech rate is added to both the voice metadata and the text-to-speech request data transfer objects. The cloning logic in the voice metadata model now preserves this property. The text-to-speech service forwards the speech rate when requesting audio. A new converter and UI control in the general configuration view allow users to select and display the speech rate, while the view model manages allowed speech rates and applies the configuration.

Changes

File(s) Change Summary
vATIS.Desktop/Profiles/Models/AtisVoiceMeta.cs Added SpeechRate (int, default 180) property; updated Clone method to include the property.
vATIS.Desktop/TextToSpeech/TextToSpeechRequestDto.cs Added SpeechRate (double?) property to the DTO for text-to-speech requests.
vATIS.Desktop/TextToSpeech/TextToSpeechService.cs Updated RequestAudio to set SpeechRate from voice meta; changed VoiceList initialization to instantiate a new list.
vATIS.Desktop/Ui/AtisConfiguration/GeneralConfigView.axaml Modified XAML: added SpeechRateMultiplierConverter to resources and introduced a new ComboBox bound to SelectedSpeechRate.
vATIS.Desktop/Ui/Converters/SpeechRateMultiplierConverter.cs Added new SpeechRateMultiplierConverter implementing IValueConverter to convert between double values and formatted strings (e.g., "0.5x").
vATIS.Desktop/Ui/ViewModels/AtisConfiguration/GeneralConfigViewModel.cs Added static allowed speech rates array; new properties SpeechRates (ObservableCollection) and SelectedSpeechRate with change notifications; updated configuration methods to apply speech rate settings.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant V as GeneralConfigView (UI)
    participant VM as GeneralConfigViewModel
    participant M as AtisVoiceMeta Model
    participant TTS as TextToSpeechService

    U->>V: Select speech rate from ComboBox
    V->>VM: Update SelectedSpeechRate
    VM->>M: Validate and apply new SpeechRate
    VM->>TTS: Include SpeechRate in TTS request
    TTS-->>VM: Process updated audio request
Loading

Poem

In a field of code so wide,
A rabbit hops with joyful stride.
A new speech rate to guide the tone,
From model to UI, the change is shown.
With converters and views in line,
Our code now sings in perfect time! 🐇🎶


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 790371b and 474667a.

📒 Files selected for processing (6)
  • vATIS.Desktop/Profiles/Models/AtisVoiceMeta.cs (2 hunks)
  • vATIS.Desktop/TextToSpeech/TextToSpeechRequestDto.cs (1 hunks)
  • vATIS.Desktop/TextToSpeech/TextToSpeechService.cs (1 hunks)
  • vATIS.Desktop/Ui/AtisConfiguration/GeneralConfigView.axaml (3 hunks)
  • vATIS.Desktop/Ui/Converters/SpeechRateMultiplierConverter.cs (1 hunks)
  • vATIS.Desktop/Ui/ViewModels/AtisConfiguration/GeneralConfigViewModel.cs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • vATIS.Desktop/TextToSpeech/TextToSpeechRequestDto.cs
  • vATIS.Desktop/Ui/AtisConfiguration/GeneralConfigView.axaml
  • vATIS.Desktop/Ui/Converters/SpeechRateMultiplierConverter.cs
  • vATIS.Desktop/Ui/ViewModels/AtisConfiguration/GeneralConfigViewModel.cs
  • vATIS.Desktop/TextToSpeech/TextToSpeechService.cs
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: Analyze (csharp)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: Analyze (csharp)
🔇 Additional comments (2)
vATIS.Desktop/Profiles/Models/AtisVoiceMeta.cs (2)

23-26: LGTM! Property is well-documented and properly initialized.

The new SpeechRate property is correctly implemented with proper XML documentation and a sensible default value.


38-38: LGTM! Clone method properly includes the new property.

The SpeechRate property is correctly included in the cloning process, ensuring that voice metadata is completely copied.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (6)
vATIS.Desktop/Ui/Converters/SpeechRateMultiplierConverter.cs (2)

20-28: Add null check and culture-aware formatting.

The Convert method could be more robust:

  1. Add explicit null handling
  2. Use culture-aware number formatting
 public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
 {
+    if (value is null)
+        return null;
+        
     if (value is double rate)
     {
-        return $"{rate}x"; // Format as 0.5x, 1.0x, etc.
+        return $"{rate.ToString(culture)}x"; // Format as 0.5x, 1.0x, etc.
     }

     return value;
 }

38-47: Enhance ConvertBack method's error handling.

The ConvertBack method could be more robust in handling invalid input formats.

 public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
 {
+    if (value is null)
+        return null;
+        
     // If converting back (e.g., from "0.5x" to 0.5), remove the "x" and parse the number.
-    if (value is string rateString && double.TryParse(rateString.Replace("x", ""), out var result))
+    if (value is string rateString && 
+        double.TryParse(rateString.Replace("x", "").Trim(), culture, out var result))
     {
         return result;
     }

     return value;
 }
vATIS.Desktop/Ui/AtisConfiguration/GeneralConfigView.axaml (1)

119-120: Consider extracting duplicate tooltip text.

The same tooltip text appears in both the TextBlock and ComboBox. Consider moving it to a resource or constant to avoid duplication and make maintenance easier.

+    <UserControl.Resources>
+        <x:String x:Key="SpeechRateTooltip">Adjust the speech speed. Choose from: 0.5x (slowest), 0.75x (slower), 1x (normal), 1.25x (faster), and 1.5x (fastest).</x:String>
+    </UserControl.Resources>
     ...
-    <TextBlock VerticalAlignment="Center" ToolTip.Tip="Adjust the speech speed. Choose from: 0.5x (slowest), 0.75x (slower), 1x (normal), 1.25x (faster), and 1.5x (fastest).">Speech Rate Multiplier:</TextBlock>
+    <TextBlock VerticalAlignment="Center" ToolTip.Tip="{StaticResource SpeechRateTooltip}">Speech Rate Multiplier:</TextBlock>
-    <ComboBox Width="100" Classes="Dark" ItemsSource="{Binding SpeechRates, DataType=vm:GeneralConfigViewModel}" SelectedValue="{Binding SelectedSpeechRate, DataType=vm:GeneralConfigViewModel}" IsEnabled="{Binding UseTextToSpeech, DataType=vm:GeneralConfigViewModel, FallbackValue=False}" ToolTip.Tip="Adjust the speech speed. Choose from: 0.5x (slowest), 0.75x (slower), 1x (normal), 1.25x (faster), and 1.5x (fastest).">
+    <ComboBox Width="100" Classes="Dark" ItemsSource="{Binding SpeechRates, DataType=vm:GeneralConfigViewModel}" SelectedValue="{Binding SelectedSpeechRate, DataType=vm:GeneralConfigViewModel}" IsEnabled="{Binding UseTextToSpeech, DataType=vm:GeneralConfigViewModel, FallbackValue=False}" ToolTip.Tip="{StaticResource SpeechRateTooltip}">
vATIS.Desktop/Ui/ViewModels/AtisConfiguration/GeneralConfigViewModel.cs (3)

29-29: Avoid duplicating speech rate values.

The same speech rate values are defined in both s_allowedSpeechRates and SpeechRates. Consider using the static array to initialize the property to maintain consistency.

-    public ObservableCollection<double> SpeechRates { get; } = [0.5, 0.75, 1.0, 1.25, 1.5];
+    public ObservableCollection<double> SpeechRates { get; } = new(s_allowedSpeechRates);

Also applies to: 255-255


400-407: Consider optimizing speech rate validation.

The current validation uses Array.Exists with floating-point comparison. Consider using LINQ's Contains with a HashSet for more efficient validation.

+    private static readonly HashSet<double> s_allowedSpeechRatesSet = new(s_allowedSpeechRates);
     ...
-            SelectedStation.AtisVoice.SpeechRateMultiplier = Array.Exists(s_allowedSpeechRates,
-                rate => Math.Abs(rate - SelectedSpeechRate) < 0.0001)
+            SelectedStation.AtisVoice.SpeechRateMultiplier = s_allowedSpeechRatesSet.Contains(SelectedSpeechRate)
                 ? SelectedSpeechRate
                 : 1.0; // If not valid, set to 1.0

446-449: Consider optimizing speech rate initialization.

Similar to the validation in ApplyConfig, consider using a HashSet for more efficient initialization of the speech rate.

-        SelectedSpeechRate = Array.Exists(s_allowedSpeechRates,
-            rate => Math.Abs(rate - station.AtisVoice.SpeechRateMultiplier) < 0.0001)
+        SelectedSpeechRate = s_allowedSpeechRatesSet.Contains(station.AtisVoice.SpeechRateMultiplier)
             ? station.AtisVoice.SpeechRateMultiplier
             : 1.0; // Default value if the rate is not allowed
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f201a6 and 790371b.

📒 Files selected for processing (6)
  • vATIS.Desktop/Profiles/Models/AtisVoiceMeta.cs (2 hunks)
  • vATIS.Desktop/TextToSpeech/TextToSpeechRequestDto.cs (1 hunks)
  • vATIS.Desktop/TextToSpeech/TextToSpeechService.cs (1 hunks)
  • vATIS.Desktop/Ui/AtisConfiguration/GeneralConfigView.axaml (3 hunks)
  • vATIS.Desktop/Ui/Converters/SpeechRateMultiplierConverter.cs (1 hunks)
  • vATIS.Desktop/Ui/ViewModels/AtisConfiguration/GeneralConfigViewModel.cs (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Analyze (csharp)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: Analyze (csharp)
🔇 Additional comments (8)
vATIS.Desktop/TextToSpeech/TextToSpeechRequestDto.cs (1)

28-31: LGTM! Well-documented property addition.

The new SpeechRateMultiplier property is appropriately defined as nullable and follows the established documentation pattern.

vATIS.Desktop/Profiles/Models/AtisVoiceMeta.cs (2)

23-26: LGTM! Well-structured property with appropriate default.

The SpeechRateMultiplier property is well-documented and has a sensible default value of 1.0 for normal speed.


38-38: LGTM! Property correctly included in Clone method.

The SpeechRateMultiplier is properly handled in the Clone method, ensuring complete object copying.

vATIS.Desktop/TextToSpeech/TextToSpeechService.cs (2)

77-77: LGTM! Speech rate multiplier properly forwarded.

The speech rate multiplier is correctly forwarded from the station's ATIS voice configuration to the request DTO.


40-40:

❓ Verification inconclusive

Verify C# version compatibility for collection expression syntax.

The code uses collection expression syntax ([]) which requires C# 12.0. Ensure your build environment supports this feature.


🏁 Script executed:

#!/bin/bash
# Check .csproj file for language version
fd -e csproj . --exec grep -l "LangVersion"

Length of output: 43


Confirm Build Environment Supports C# 12.0 Collection Expressions

It appears that no explicit <LangVersion> is set in any of the csproj files. Since the collection expression syntax (VoiceList = [];) requires C# 12.0, please verify manually that your build environment (and the associated .NET SDK) indeed supports C# 12.0 features. If necessary, update the csproj file with an explicit language version (e.g., <LangVersion>12.0</LangVersion>) to eliminate any ambiguity.

vATIS.Desktop/Ui/AtisConfiguration/GeneralConfigView.axaml (2)

14-15: LGTM!

The converter registration is properly added and maintains consistency with existing patterns.


118-127: LGTM! Well-designed UI controls.

The speech rate controls are well-implemented with:

  • Clear tooltips explaining available options
  • Proper binding to ViewModel properties
  • Consistent disabling behavior with text-to-speech toggle
vATIS.Desktop/Ui/ViewModels/AtisConfiguration/GeneralConfigViewModel.cs (1)

260-271: LGTM!

The SelectedSpeechRate property implementation follows the established pattern and correctly handles change notifications and unsaved changes tracking.

@justinshannon justinshannon added this pull request to the merge queue Feb 18, 2025
Merged via the queue into main with commit 10336b1 Feb 18, 2025
9 checks passed
@justinshannon justinshannon deleted the feat/speech-rate-multiplier branch February 18, 2025 00:12
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