def add_tts_span_attributes(
    span: "Span",
    service_name: str,
    model: str,
    voice_id: str,
    text: Optional[str] = None,
    settings: Optional[Dict[str, Any]] = None,
    character_count: Optional[int] = None,
    operation_name: str = "tts",
    ttfb: Optional[float] = None,
    **kwargs,
) -> None:
    """Add TTS-specific attributes to a span.

    Args:
        span: The span to add attributes to
        service_name: Name of the TTS service (e.g., "cartesia")
        model: Model name/identifier
        voice_id: Voice identifier
        text: The text being synthesized
        settings: Service configuration settings
        character_count: Number of characters in the text
        operation_name: Name of the operation (default: "tts")
        ttfb: Time to first byte in seconds
        **kwargs: Additional attributes to add
    """
    # Add standard attributes
    span.set_attribute("gen_ai.system", service_name.replace("TTSService", "").lower())
    span.set_attribute("gen_ai.request.model", model)
    span.set_attribute("gen_ai.operation.name", operation_name)
    span.set_attribute("gen_ai.output.type", "speech")
    span.set_attribute("voice_id", voice_id)

    # Add optional attributes
    if text:
        span.set_attribute("text", text)

    if character_count is not None:
        span.set_attribute("metrics.character_count", character_count)

    if ttfb is not None:
        span.set_attribute("metrics.ttfb", ttfb)

    # Add settings if provided
    if settings:
        for key, value in settings.items():
            if isinstance(value, (str, int, float, bool)):
                span.set_attribute(f"settings.{key}", value)

    # Add any additional keyword arguments as attributes
    for key, value in kwargs.items():
        if isinstance(value, (str, int, float, bool)):
            span.set_attribute(key, value)
Add TTS-specific attributes to a span.

    Args:
        span: The span to add attributes to
        service_name: Name of the TTS service (e.g., "cartesia")
        model: Model name/identifier
        voice_id: Voice identifier
        text: The text being synthesized
        settings: Service configuration settings
        character_count: Number of characters in the text
        operation_name: Name of the operation (default: "tts")
        ttfb: Time to first byte in seconds
        **kwargs: Additional attributes to add
    
src/pipecat/utils/tracing/service_attributes.py