- YouTube สอน C#: การแปลงข้อความให้เป็นเสียงพูด (Text to Speech)
- docs.microsoft.com System.Speech.Synthesis Namespace
1.ตรวจสอบเสียงที่ติดตั้งมาในเครื่อง
เปิด Control Panel แล้วเลือก Speech Recognition

เลือก Text to Speech

ที่หน้าต่าง Speech Properties จะแสดงเสียงที่ติดตั้งอยู่ในเครื่อง
2.เขียน C# ด้วย .Net Framework 4.8
สร้างโปรเจ็กส์แบบ Console
Add Reference ชื่อ System.Speech Version 4.0.0.0
เพิ่มโค๊ด C#
using System.Speech.Synthesis;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer syn = new SpeechSynthesizer();
syn.Speak("I love Thailand.");
}
}
}
เมื่อรันจะได้ยินเสียงละ
เปลี่ยนเสียงพูดเป็นของ Microsoft Zira Desktop
using System.Speech.Synthesis;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer syn = new SpeechSynthesizer();
syn.SelectVoice("Microsoft Zira Desktop");
syn.Speak("I love Thailand.");
}
}
}
ปรับความเร็วของเสียงพูด ค่าบวกยิ่งมากยิ่งพูดเร็ว ค่าลบยิ่งลดมากยิ่งพูดช้า
using System.Speech.Synthesis;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer syn = new SpeechSynthesizer();
syn.SelectVoice("Microsoft Zira Desktop");
syn.Rate = 1; // -10 to 10
syn.Speak("I love Thailand.");
}
}
}