Skip to content

Instantly share code, notes, and snippets.

@DartPower
Created December 31, 2025 10:27
Show Gist options
  • Select an option

  • Save DartPower/a52743c9e3858b4713738914732928f1 to your computer and use it in GitHub Desktop.

Select an option

Save DartPower/a52743c9e3858b4713738914732928f1 to your computer and use it in GitHub Desktop.
SpeechLib C#
Сперва нужна SAPI DLL совместимая с .NET
SpeechLib.dll был сделан так (на ошибки не обращаем внимание)
"C:\Program Files\Microsoft.NET\SDK\v2.0\bin\tlbimp.exe" "C:\Program Files\Common Files\Microsoft Shared\Speech\sapi.dll" /out:SpeechLib.dll /namespace:SpeechLib
Делаю в C# Project -> Add Reference... и кликаю по DLL.
Ниже пример голоса на английском. Код using... заносим на шапку программы, а 2 строки в код вызывающийся по клику кнопки.
using SpeechLib;
....
SpVoice sp2 = new SpVoice();
sp2.Speak("Hello user!", SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync);
=========дополнительные документы==========
Buliding Text to Speech Applications using SAPI 5.1 and C#
https://www.c-sharpcorner.com/article/buliding-text-to-speech-applications-using-sapi-5-1-and-C-Sharp/
Примеры использования SAPI
https://mshforfun.blogspot.com/2006/02/give-monad-voice-out-voice-cmdlet.html
Описаны иные моменты, получение списка говорящих движкой установленных в системе.
http://coderszone.info/articles/net/246-nauchi-programmu-govorit.html
Движки для подключения к Speech API(откуда их ставить).
https://www.vector-ski.ru/vecs/govorilka/engines.html
Т.е. там есть русский движок.
// .NET 4.8 (Winm 10/11)
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\TlbImp.exe" "C:\Windows\System32\Speech\Common\sapi.dll" /out:SpeechLib.dll /namespace:SpeechLib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment