RoboZhando/Synthesizer.cs
/// <summary>Speaks the message to the given voice next connection</summary>
Speaks the message to the given voice next connection
Speaks the message to the given voice next connection
public async Task SpeakAsync(DiscordMessage message, VoiceNextConnection connection, CancellationToken cancellationToken = default)
        {
            var result = await SythesizeAsync(message);
            if (result.Reason == ResultReason.Canceled)
            {
                var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
                if (cancellation.Reason == CancellationReason.Error)
                {
                    Logger.LogError("Failed to parse the given message.");
                    return;
                }
            }
            if (UseFileIntermStrategy)
            {
                var tempFileName = Path.GetTempFileName();
                try
                {
                    using var stream = AudioDataStream.FromResult(result);
                    await stream.SaveToWaveFileAsync(tempFileName);
                    var transmit = connection.GetTransmitSink();
                    var pcm = ConvertAudioToPcm(tempFileName);
                    await pcm.CopyToAsync(transmit, cancellationToken: cancellationToken);
                    await pcm.DisposeAsync();
                }
                finally
                {
                    if (File.Exists(tempFileName))
                        File.Delete(tempFileName);
                }
            }
            else
            {
                var transmit = connection.GetTransmitSink();
                await transmit.WriteAsync(result.AudioData, cancellationToken);
            }
        }
public async Task SpeakAsync ( DiscordMessage message , VoiceNextConnection connection , CancellationToken cancellationToken = default ) { var result = await SythesizeAsync ( message ) ; if ( result . Reason == ResultReason . Canceled ) { var cancellation = SpeechSynthesisCancellationDetails . FromResult ( result ) ; if ( cancellation . Reason == CancellationReason . Error ) { Logger . LogError ( " " ) ; return ; } } if ( UseFileIntermStrategy ) { var tempFileName = Path . GetTempFileName ( ) ; try { using var stream = AudioDataStream . FromResult ( result ) ; await stream . SaveToWaveFileAsync ( tempFileName ) ; var transmit = connection . GetTransmitSink ( ) ; var pcm = ConvertAudioToPcm ( tempFileName ) ; await pcm . CopyToAsync ( transmit , cancellationToken : cancellationToken ) ; await pcm . DisposeAsync ( ) ; } finally { if ( File . Exists ( tempFileName ) ) File . Delete ( tempFileName ) ; } } else { var transmit = connection . GetTransmitSink ( ) ; await transmit . WriteAsync ( result . AudioData , cancellationToken ) ; } }
Speaks the message to the given voice next connection
Speaks the message to the given voice next connection
// Get the result // Save the data // TODO: Make this a queue // Transmit it away
message
DiscordMessage
connection
VoiceNextConnection
cancellationToken
CancellationToken