this is really almost perfect but it still struggles with some particular lengths like "this is a test now baby" should give a range around 6 for duration and 12 for quality and other steps you could take to fill in the gaps please do send back in full

using System;
using System.Text.RegularExpressions;

public class ValuesBasedOnString
{
    // Thresholds tuned to better detect medium vs long inputs
    private const int VeryShortCharMax = 30;  // <=30 chars = very short
    private const int VeryShortWordMax = 5;   // <=5 words = very short
    private const int LongCharMin = 70;       // >=70 chars = long/complex
    private const int LongWordMin = 15;       // >=15 words = long/complex

    private readonly Random _rnd;

    public string Input { get; }

    /// <summary>
    /// Speak text with commas replaced as newlines (for formatting)
    /// </summary>
    public string FormattedSpeak { get; private set; }

    /// <summary>
    /// Quality parameter (mapped 0-30 range usually)
    /// </summary>
    public int Quality { get; private set; }

    /// <summary>
    /// Duration parameter (in seconds or units, usually 5-30)
    /// </summary>
    public int Duration { get; private set; }

    /// <summary>
    /// Mixed text output used downstream
    /// </summary>
    public string MixLine => "[verse]" + Environment.NewLine + FormattedSpeak;

    public ValuesBasedOnString(string input, int? seed = null)
    {
        Input = input ?? string.Empty;
        _rnd = seed.HasValue ? new Random(seed.Value) : new Random();
        ProcessInput();
    }

    private void ProcessInput()
    {
        string cleanedInput = Input.Trim();

        int charLength = cleanedInput.Length;
        int wordCount = CountWords(cleanedInput);

        // Format commas to newlines for output
        if (cleanedInput.Contains(","))
        {
            // When commas present, fixed parameters
            Quality = 20;
            Duration = 27;
            FormattedSpeak = Regex.Replace(cleanedInput, @",\s*", Environment.NewLine);
            return;
        }

        // No commas - analyze length and complexity tiers
        FormattedSpeak = cleanedInput;

        // Very short sentence: low quality & duration
        if (charLength <= VeryShortCharMax || wordCount <= VeryShortWordMax)
        {
            Quality = 11;
            Duration = 5;
            return;
        }

        // Long or complex sentence: randomize quality/duration in a higher range
        if (charLength >= LongCharMin || wordCount >= LongWordMin)
        {
            Quality = _rnd.Next(18, 28);  // 18 to 27 inclusive, tighter and higher than before
            Duration = _rnd.Next(20, 28); // 20 to 27 inclusive, subtle but noticeable increase
            return;
        }

        // Medium length sentence: modest parameters (higher than very short, lower than long)
        Quality = _rnd.Next(12, 18);  // 12 to 17 inclusive
        Duration = _rnd.Next(6, 15);  // 6 to 14 inclusive

        // (Optional) Slightly adjust FormattedSpeak by splitting on periods if medium length for readability
        if (wordCount > 8 && cleanedInput.Contains('.'))
        {
            FormattedSpeak = Regex.Replace(cleanedInput, @"\.\s*", Environment.NewLine);
        }
    }

    private int CountWords(string input)
    {
        if (string.IsNullOrWhiteSpace(input))
            return 0;
        return input.Split(new[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries).Length;
    }
}