C# - A way to add sound effect on TTS programmatically

1,033 views
Skip to first unread message

LIENARD Julien

unread,
Nov 28, 2015, 12:07:27 PM11/28/15
to VoiceAttack
Hello,

i found a way to add sound effects on Text To Speech programmatically in C#.
Just want to share this, because it would be great if it could be implemented in VA (or provide stream externally for custom sound effects)

I'm using NAudio library for WaveFileReader
and a custom EffectStream where i put the magic of filtering an audio stream (like Chorus, Delay, Flanger, ...)

My main focus here was just to show it is possible to catch TTS audio and apply a custom thing before it is send to you're speaker :)



using NAudio.Wave; // for wave stream
using MyTestProject1.Audio.Effects; // for effects like EffectStream



SpeechSynthesizer ss = new SpeechSynthesizer();
...

var stream = new MemoryStream();
ss
.SetOutputToWaveStream(stream);
ss
.Speak(builder);

stream
.Seek(0, SeekOrigin.Begin);
var reader = new WaveFileReader(stream);
var waveOut = new WaveOut();


EffectStream effectStream = new EffectStream(effects, reader);
waveOut
.Init(effectStream);
waveOut
.Play();



I hope i could see some day a check box for "TTS Say something" and "Apply Filter" and choose/customize effects to add echo or a robot-like effect ;)



Nanard

Gary

unread,
Nov 28, 2015, 3:20:29 PM11/28/15
to VoiceAttack
Thanks for that!

I've actually got NAudio on deck for other things... I'll check this out, too ;)

Gary
Reply all
Reply to author
Forward
0 new messages