Bài viết này Mạng Bình Định sẽ hướng dẫn bạn cách tạo chương trình đọc văn bản (chuyển văn bản thành giọng nói) bằng ngôn ngữ C# . Bạn sẽ sử dụng .Net Framework để máy có thể phát ra tiếng. Bạn thao tác theo hướng dẫn theo từng bước dưới đây:
Bước 1
Mở Microsoft Visual Studio 2015 và tạo một ứng dụng winform mới trong C#

Bước 2
Tạo form như hình bên dưới.

Bước 3
Bạn mở Solution Explorer, click chuột phải vào References và bấm vào Add Reference.

Bước 4
Thêm System.Speech và bấm OK.

Bước 5
Thêm thư viện Speech
1 | using System.Speech.Synthesis; |
Bước 6
Bạn nhấp vào nút Speak và sử dụng mã sau đây để thực hiện hành động “đọc” khi bấm vào nút.
1 2 3 4 5 6 7 8 9 | private void button1_Click(object sender, EventArgs e) { SpeechSynthesizer speaks = new SpeechSynthesizer(); string msg; msg = "Welcome to sourcecodester.com"; speaks.Rate = 1; speaks.Volume = 100; speaks.Speak(msg); } |
- Advertisement -