using System;using System.Text.Json;using Agent.Core.ToolCalling;namespace Agent.Addons.Tools;/// <summary>Addon tool — changes the text-to-speech (TTS) voice.</summary>public static class ChangeVoiceTool{ public const string Name = "change_voice"; public static void Register(ToolRegistry registry) { registry.Register(new AgentTool( Name, "Changes the text-to-speech (TTS) voice. Available voices include: af_heart, af_bella, af_sarah, af_nicole, af_sky, am_adam, am_michael, bf_emma, bf_isabella, bm_george, bm_lewis.", args => Invoke(registry, args), ParametersSchema, ToolCategory.Addon)); } private static object ParametersSchema => new { type = "object", properties = new { voice = new { type = "string", description = "The voice ID to switch to, e.g., 'af_bella' or 'bf_emma'." } }, required = new[] { "voice" } }; private static string Invoke(ToolRegistry registry, string argumentsJson) { string voice = ParseVoice(argumentsJson); if (string.IsNullOrWhiteSpace(voice)) { return "Error: Provide a voice ID (JSON property \"voice\")."; } try { registry.InvokeVoiceChanged(voice); return $"Success: TTS voice changed to '{voice}'."; } catch (Exception ex) { return $"Error changing voice: {ex.Message}"; } } private static string ParseVoice(string argumentsJson) { try { using var doc = JsonDocument.Parse(argumentsJson); if (doc.RootElement.TryGetProperty("voice", out var voiceProp)) { return voiceProp.GetString()?.Trim() ?? ""; } } catch (JsonException) { } return ""; }}