RoboZhando/Synthesizer.cs
/// <summary>Speaks the text directly to the speaker.</summary>
Speaks the text directly to the speaker.
Speaks the text directly to the speaker .
protected async Task<SpeechSynthesisResult> SythesizeAsync(string text)
        {
            if (string.IsNullOrEmpty(text))
                throw new ArgumentException("text cannot be empty");
            SpeechSynthesisResult result;
            if (text.StartsWith("<speak"))
                 result = await synthesizer.SpeakSsmlAsync(text);
            else
                result = await synthesizer.SpeakTextAsync(text);
            if (result.Reason == ResultReason.SynthesizingAudioCompleted)
            {
                Logger.Log($"Speech synthesized to speaker for text [{text}]");
            }
            else if (result.Reason == ResultReason.Canceled)
            {
                var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
                Logger.LogError($"CANCELED: Reason={cancellation.Reason}");
                if (cancellation.Reason == CancellationReason.Error)
                {
                    Logger.LogError($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                    Logger.LogError($"CANCELED: ErrorDetails=[{cancellation.ErrorDetails}]");
                    Logger.LogError($"CANCELED: Did you update the subscription info?");
                }
            }
            return result;
        }
protected async Task < SpeechSynthesisResult > SythesizeAsync ( string text ) { if ( string . IsNullOrEmpty ( text ) ) throw new ArgumentException ( " " ) ; SpeechSynthesisResult result ; if ( text . StartsWith ( " " ) ) result = await synthesizer . SpeakSsmlAsync ( text ) ; else result = await synthesizer . SpeakTextAsync ( text ) ; if ( result . Reason == ResultReason . SynthesizingAudioCompleted ) { Logger . Log ( $" Speech synthesized to speaker for text [ { text } ] " ) ; } else if ( result . Reason == ResultReason . Canceled ) { var cancellation = SpeechSynthesisCancellationDetails . FromResult ( result ) ; Logger . LogError ( $" CANCELED: Reason= { cancellation . Reason } " ) ; if ( cancellation . Reason == CancellationReason . Error ) { Logger . LogError ( $" CANCELED: ErrorCode= { cancellation . ErrorCode } " ) ; Logger . LogError ( $" CANCELED: ErrorDetails=[ { cancellation . ErrorDetails } ] " ) ; Logger . LogError ( $" CANCELED: Did you update the subscription info? " ) ; } } return result ; }
Speaks the text directly to the speaker.
Speaks the text directly to the speaker .
//Throw if the text is empty
text
string