This commit is contained in:
Zeeshaun
2026-04-23 14:55:13 +00:00
parent ade58260d7
commit 39e0c65671
2 changed files with 12 additions and 64 deletions
@@ -5,8 +5,6 @@ namespace LCU.Webapps.Marketing.SPIT.Model
{
public class SpitConfiguration
{
private const string DefaultSpeechSynthesisPath = "/tts/cognitiveservices/v1";
public string AppName { get; set; }
public string SeqApiKey { get; set; }
public string SeqUrl { get; set; }
@@ -38,7 +36,7 @@ namespace LCU.Webapps.Marketing.SPIT.Model
return new Uri(SpeechEndpoint.Trim(), UriKind.Absolute);
}
public Uri ResolveSpeechSynthesisEndpointUri()
public Uri ResolveSpeechSdkEndpointUri()
{
var endpoint = ResolveSpeechEndpointUri();
if (endpoint == null)
@@ -46,35 +44,13 @@ namespace LCU.Webapps.Marketing.SPIT.Model
return null;
}
var endpointPath = endpoint.AbsolutePath?.Trim() ?? string.Empty;
if (string.IsNullOrWhiteSpace(endpointPath) || endpointPath == "/")
return new UriBuilder(endpoint)
{
return new Uri(endpoint, ResolveSpeechSynthesisPath());
}
if (endpointPath.EndsWith("/websocket/v1", StringComparison.OrdinalIgnoreCase))
{
return new UriBuilder(endpoint)
{
Scheme = Uri.UriSchemeHttps,
Port = -1,
Path = endpointPath.Replace("/websocket/v1", "/v1", StringComparison.OrdinalIgnoreCase),
Query = string.Empty
}.Uri;
}
if (endpointPath.EndsWith("/voices/list", StringComparison.OrdinalIgnoreCase))
{
return new UriBuilder(endpoint)
{
Scheme = Uri.UriSchemeHttps,
Port = -1,
Path = endpointPath.Replace("/voices/list", "/v1", StringComparison.OrdinalIgnoreCase),
Query = string.Empty
}.Uri;
}
return endpoint;
Scheme = "wss",
Port = -1,
Path = string.Empty,
Query = string.Empty
}.Uri;
}
public Uri ResolveSpeechTokenUri()
@@ -86,20 +62,5 @@ namespace LCU.Webapps.Marketing.SPIT.Model
{
return new Uri(ResolveSpeechEndpointUri(), VoicesUrl);
}
private string ResolveSpeechSynthesisPath()
{
if (!string.IsNullOrWhiteSpace(WebsocketUrl))
{
return WebsocketUrl.Replace("/websocket/v1", "/v1", StringComparison.OrdinalIgnoreCase);
}
if (!string.IsNullOrWhiteSpace(VoicesUrl))
{
return VoicesUrl.Replace("/voices/list", "/v1", StringComparison.OrdinalIgnoreCase);
}
return DefaultSpeechSynthesisPath;
}
}
}
@@ -105,28 +105,15 @@ namespace LCU.Webapps.Marketing.SPIT.Services
private SpeechConfig BuildSpeechConfig()
{
var speechEndpoint = _spitConfiguration.ResolveSpeechEndpointUri();
if (speechEndpoint != null)
var sdkEndpoint = _spitConfiguration.ResolveSpeechSdkEndpointUri();
if (sdkEndpoint != null)
{
var endpointPath = speechEndpoint.AbsolutePath?.Trim() ?? string.Empty;
if (string.IsNullOrWhiteSpace(endpointPath) || endpointPath == "/")
{
Log.Information(
"Using speech host {SpeechHost} for file generation.",
speechEndpoint);
return SpeechConfig.FromHost(
speechEndpoint,
_spitConfiguration.SpeechApiKey);
}
var synthesisEndpoint = _spitConfiguration.ResolveSpeechSynthesisEndpointUri();
Log.Information(
"Using explicit speech endpoint {SpeechSynthesisEndpoint} for file generation.",
synthesisEndpoint);
"Using speech SDK endpoint {SpeechSdkEndpoint} for file generation.",
sdkEndpoint);
return SpeechConfig.FromEndpoint(
synthesisEndpoint,
sdkEndpoint,
_spitConfiguration.SpeechApiKey);
}