microsoft/semantic-kernel · error · NotSupportedException
The format '{format}' is not supported.
Error message
The format '{format}' is not supported. What it means
The audio output format string is matched case-insensitively against a fixed set (WAV, MP3, OPUS, FLAC, AAC, PCM). A null format is allowed (returns nulls, letting the API pick its default), but any non-null unrecognized string throws NotSupportedException. This check runs before the HTTP request is made.
Source
Thrown at dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.TextToAudio.cs:71
"FABLE" => GeneratedSpeechVoice.Fable,
"ONYX" => GeneratedSpeechVoice.Onyx,
"NOVA" => GeneratedSpeechVoice.Nova,
"SHIMMER" => GeneratedSpeechVoice.Shimmer,
_ => throw new NotSupportedException($"The voice '{voice}' is not supported."),
};
private static (GeneratedSpeechFormat? Format, string? MimeType) GetGeneratedSpeechFormatAndMimeType(string? format)
{
switch (format?.ToUpperInvariant())
{
case "WAV": return (GeneratedSpeechFormat.Wav, "audio/wav");
case "MP3": return (GeneratedSpeechFormat.Mp3, "audio/mpeg");
case "OPUS": return (GeneratedSpeechFormat.Opus, "audio/opus");
case "FLAC": return (GeneratedSpeechFormat.Flac, "audio/flac");
case "AAC": return (GeneratedSpeechFormat.Aac, "audio/aac");
case "PCM": return (GeneratedSpeechFormat.Pcm, "audio/l16");
case null: return (null, null);
default: throw new NotSupportedException($"The format '{format}' is not supported.");
}
}
}
View on GitHub (pinned to c028a0c7dc)
Solutions
- Use one of: wav, mp3, opus, flac, aac, pcm (case-insensitive).
- Leave the format unset/null to let the API use its default if you don't need a specific container.
- If you need a format outside this set (e.g. OGG), call the underlying OpenAI SDK directly.
Example fix
// before
var settings = new OpenAITextToAudioExecutionSettings { GeneratedSpeechFormat = "audio/mpeg" };
// after
var settings = new OpenAITextToAudioExecutionSettings { GeneratedSpeechFormat = "mp3" }; Defensive patterns
Strategy: validation
Validate before calling
static readonly HashSet<string> SupportedFormats = new(StringComparer.OrdinalIgnoreCase)
{
"wav", "mp3", "opus", "flac", "aac", "pcm"
};
void ValidateFormat(string? format)
{
if (format is not null && !SupportedFormats.Contains(format.Trim()))
throw new ArgumentOutOfRangeException(nameof(format),
$"Format must be one of: {string.Join(", ", SupportedFormats)} (or null for default)");
} Try / catch
try { var audio = await ttsService.GetAudioContentAsync(text, settings); }
catch (NotSupportedException ex) when (ex.Message.Contains("format"))
{
settings.GeneratedSpeechFormat = null; // let API choose default
var audio = await ttsService.GetAudioContentAsync(text, settings);
} Prevention
- Allow null format in configuration so the API default is used when you don't need a specific container.
- Validate the format token at configuration-load time, not at call time.
When it happens
Trigger: Passing OpenAITextToAudioExecutionSettings.GeneratedSpeechFormat (or equivalent) a value like 'ogg', 'webm', or a MIME-type string such as 'audio/mpeg' that does not match the allowed tokens.
Common situations: Confusing the format token with a MIME type or file extension (e.g. 'mp3 ' vs 'mp3'). Requesting a format the connector version doesn't map. Copying a format value from a different SDK's docs.
Related errors
- The voice '{voice}' is not supported.
- {type(self)} service failed to generate audio
- Invalid choice
- Invalid kernel selection. {selectedKernelName} is not a vali
- Unsupported image format.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/ec720c52057a17d7.
Report an issue: GitHub.