I'm trying to do some basic app, with System.Speech.Synthesis in c#
It's just a basic form with a text input and after pressing enter it reads the text using ss.SpeakAsync();
The goal is to play that sound on a exact audio output device on Windows but I can't achieve that.
I'm setting the correct device, but it plays on the "default" anyways, no matter what I do. It works with any other application correctly (like browser for example) bit with mine it doesn't. It works when I change all system audio to that device, but the main goal is that i want only this app to use "cable input".
So maybe I'm able to set in the code the correct audio output device? Or how do I fix those previous errors? maybe I need to add some privileges or something? I'm mainly web developer, this is my first time with windows app.
//edit -> it works, when i change all my system audio to cable input, play some sound, and then go back to my main device. It seems like a windows bug?
you may use a 3rd lib Naudio; the example below shows how to return to current position in case the player was playing a song. The key code is player.DeviceNumber = deviceNum; in which deviceNum is 0, 1, 2... depending how many speakers are available in your PC. A disadvantage of Naudio is that it loads completely the song before playing, and quite slow.
var playback = player.PlaybackState;
if (playback == PlaybackState.Stopped) // change and exit
{
player.DeviceNumber = deviceNum;
return;
}
var currentTime = reader.CurrentTime;
player.Stop(); // must stop to change output
player.DeviceNumber = deviceNum;
player.Init(reader);
reader.CurrentTime = currentTime;
if (playback == PlaybackState.Playing)
player.Play();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.