Updating
This commit is contained in:
+7
-46
@@ -5,8 +5,6 @@ namespace LCU.Webapps.Marketing.SPIT.Model
|
|||||||
{
|
{
|
||||||
public class SpitConfiguration
|
public class SpitConfiguration
|
||||||
{
|
{
|
||||||
private const string DefaultSpeechSynthesisPath = "/tts/cognitiveservices/v1";
|
|
||||||
|
|
||||||
public string AppName { get; set; }
|
public string AppName { get; set; }
|
||||||
public string SeqApiKey { get; set; }
|
public string SeqApiKey { get; set; }
|
||||||
public string SeqUrl { get; set; }
|
public string SeqUrl { get; set; }
|
||||||
@@ -38,7 +36,7 @@ namespace LCU.Webapps.Marketing.SPIT.Model
|
|||||||
return new Uri(SpeechEndpoint.Trim(), UriKind.Absolute);
|
return new Uri(SpeechEndpoint.Trim(), UriKind.Absolute);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri ResolveSpeechSynthesisEndpointUri()
|
public Uri ResolveSpeechSdkEndpointUri()
|
||||||
{
|
{
|
||||||
var endpoint = ResolveSpeechEndpointUri();
|
var endpoint = ResolveSpeechEndpointUri();
|
||||||
if (endpoint == null)
|
if (endpoint == null)
|
||||||
@@ -46,35 +44,13 @@ namespace LCU.Webapps.Marketing.SPIT.Model
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var endpointPath = endpoint.AbsolutePath?.Trim() ?? string.Empty;
|
return new UriBuilder(endpoint)
|
||||||
if (string.IsNullOrWhiteSpace(endpointPath) || endpointPath == "/")
|
|
||||||
{
|
{
|
||||||
return new Uri(endpoint, ResolveSpeechSynthesisPath());
|
Scheme = "wss",
|
||||||
}
|
Port = -1,
|
||||||
|
Path = string.Empty,
|
||||||
if (endpointPath.EndsWith("/websocket/v1", StringComparison.OrdinalIgnoreCase))
|
Query = string.Empty
|
||||||
{
|
}.Uri;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri ResolveSpeechTokenUri()
|
public Uri ResolveSpeechTokenUri()
|
||||||
@@ -86,20 +62,5 @@ namespace LCU.Webapps.Marketing.SPIT.Model
|
|||||||
{
|
{
|
||||||
return new Uri(ResolveSpeechEndpointUri(), VoicesUrl);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-18
@@ -105,28 +105,15 @@ namespace LCU.Webapps.Marketing.SPIT.Services
|
|||||||
|
|
||||||
private SpeechConfig BuildSpeechConfig()
|
private SpeechConfig BuildSpeechConfig()
|
||||||
{
|
{
|
||||||
var speechEndpoint = _spitConfiguration.ResolveSpeechEndpointUri();
|
var sdkEndpoint = _spitConfiguration.ResolveSpeechSdkEndpointUri();
|
||||||
if (speechEndpoint != null)
|
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(
|
Log.Information(
|
||||||
"Using explicit speech endpoint {SpeechSynthesisEndpoint} for file generation.",
|
"Using speech SDK endpoint {SpeechSdkEndpoint} for file generation.",
|
||||||
synthesisEndpoint);
|
sdkEndpoint);
|
||||||
|
|
||||||
return SpeechConfig.FromEndpoint(
|
return SpeechConfig.FromEndpoint(
|
||||||
synthesisEndpoint,
|
sdkEndpoint,
|
||||||
_spitConfiguration.SpeechApiKey);
|
_spitConfiguration.SpeechApiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user