Skip to content

Instantly share code, notes, and snippets.

@imba-tjd
Last active February 14, 2023 01:50
Show Gist options
  • Save imba-tjd/5d76060f25735cd3d6bbe1cc4702fd28 to your computer and use it in GitHub Desktop.
Save imba-tjd/5d76060f25735cd3d6bbe1cc4702fd28 to your computer and use it in GitHub Desktop.
Call UWP / WinRT API from Win32 without installing Windows SDK
// Compile: csc TTS.cs /o /r:Windows.winmd /r:System.Runtime.dll /r:System.Runtime.WindowsRuntime.dll
using System;
using System.IO;
using System.Threading.Tasks;
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
string text = Console.In.ReadToEnd();
var stream = await synth.SynthesizeTextToStreamAsync(text);
var fs = new FileStream("tts.wav", FileMode.Create);
stream.AsStream().CopyTo(fs);
stream.CloneStream();
fs.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment