kanils_
kanils_

Reputation: 425

How to disable SpeechSynthesizer to produce text through speaker

I'm trying to generate file with text-to-speech approach.

 public AudioResponse GenerateAudio()
{
        _speechConfig.SpeechSynthesisVoiceName = $"{request.Language}-{request.Voice}";
        using SpeechSynthesizer synthesizer = new(_speechConfig);
      
        SpeechSynthesisResult result = await synthesizer.SpeakTextAsync("Test");
        File.WriteAllBytes(@"D:\front-doors-opening.mp3", result.AudioData);
        return new AudioResponse { Audio = result.AudioData };
}

When Generate Audio is executing, file stores and SpeakTextAsync plays my text. Is there any way to configure SpeechSynthesize to generate AudioData without producing it?

Packages:

Microsoft.CognitiveServices.Speech - Version="1.23.0"

.NET 6

Upvotes: 0

Views: 199

Answers (1)

kanils_
kanils_

Reputation: 425

With help Hans Passant, I find right config set up to not produce text generated with SpeechSynthesizer through speaker. You just simple need to add config null as AudioConfig

using var synthesizer = new SpeechSynthesizer(config, null as AudioConfig);

Upvotes: 1

Related Questions