Updating
This commit is contained in:
+19
-8
@@ -11,20 +11,18 @@ namespace LCU.Webapps.Marketing.SPIT.Services
|
||||
{
|
||||
private readonly SpitConfiguration _spitConfiguration;
|
||||
private readonly IFileOperationsApiService _fileOperationsApiService;
|
||||
private SpeechConfig _speechConfig;
|
||||
|
||||
public TextToSpeechService(SpitConfiguration spitConfiguration, IFileOperationsApiService fileOperationsApiService)
|
||||
{
|
||||
_spitConfiguration = spitConfiguration;
|
||||
_fileOperationsApiService = fileOperationsApiService;
|
||||
_speechConfig = BuildSpeechConfig();
|
||||
}
|
||||
|
||||
public async Task<string> SpeechToFile(TextToSpeech textToSpeech)
|
||||
{
|
||||
try
|
||||
{
|
||||
_speechConfig.SpeechSynthesisVoiceName = textToSpeech.SelectedVoiceShortName;
|
||||
var speechConfig = BuildSpeechConfig();
|
||||
speechConfig.SpeechSynthesisVoiceName = textToSpeech.SelectedVoiceShortName;
|
||||
var finalDestination = (_spitConfiguration.FileDestination ?? string.Empty).Trim();
|
||||
if (string.IsNullOrWhiteSpace(finalDestination))
|
||||
{
|
||||
@@ -41,7 +39,7 @@ namespace LCU.Webapps.Marketing.SPIT.Services
|
||||
finalDestination,
|
||||
textToSpeech.Ssml?.Length ?? 0);
|
||||
|
||||
using var synth = new SpeechSynthesizer(_speechConfig);
|
||||
using var synth = new SpeechSynthesizer(speechConfig, audioConfig: null);
|
||||
using var result = await synth.SpeakSsmlAsync(textToSpeech.Ssml);
|
||||
if (result.Reason != ResultReason.SynthesizingAudioCompleted)
|
||||
{
|
||||
@@ -107,11 +105,24 @@ namespace LCU.Webapps.Marketing.SPIT.Services
|
||||
|
||||
private SpeechConfig BuildSpeechConfig()
|
||||
{
|
||||
var synthesisEndpoint = _spitConfiguration.ResolveSpeechSynthesisEndpointUri();
|
||||
if (synthesisEndpoint != null)
|
||||
var speechEndpoint = _spitConfiguration.ResolveSpeechEndpointUri();
|
||||
if (speechEndpoint != null)
|
||||
{
|
||||
var endpointPath = speechEndpoint.AbsolutePath?.Trim() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(endpointPath) || endpointPath == "/")
|
||||
{
|
||||
Log.Information(
|
||||
"Using speech synthesis endpoint {SpeechSynthesisEndpoint} for file generation.",
|
||||
"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);
|
||||
|
||||
return SpeechConfig.FromEndpoint(
|
||||
|
||||
Reference in New Issue
Block a user