Berikut ini adalah source code untuk membuat program text to speech Predikat nilai ujian menggunakan Microsoft Visual C++ 2010.
#pragma once
namespace Aplikasi {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Speech::Synthesis;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::Button^ button1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
private: System::Windows::Forms::Button^ button2;
private:
int iNilai;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 18);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(41, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Nama :";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(60, 18);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(191, 20);
this->textBox1->TabIndex = 1;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(15, 63);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(33, 13);
this->label2->TabIndex = 2;
this->label2->Text = L"Nilai :";
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(60, 63);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(191, 20);
this->textBox2->TabIndex = 3;
this->textBox2->TextChanged += gcnew System::EventHandler(this, &Form1::textBox2_TextChanged);
//
// button1
//
this->button1->Location = System::Drawing::Point(98, 133);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 4;
this->button1->Text = L"CEK";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(98, 182);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 5;
this->button2->Text = L"EXIT";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->label2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e) {
int iTemp;
if(Int32::TryParse(textBox2->Text, iTemp))
iNilai = Convert::ToInt32(textBox2->Text);
else
textBox2->Text = Convert::ToString(iNilai);
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
SpeechSynthesizer^synth=gcnew SpeechSynthesizer();
if(iNilai>=80 && iNilai<=100){
synth->Speak("Hello "+textBox1->Text+", Nilaimu Sangat Bagus, Pertahankan");
}
else if(iNilai>=70 && iNilai<=79){
synth->Speak("Hello "+textBox1->Text+", Nilaimu Bagus, Tingkatkan");
}
else if(iNilai>=60 && iNilai<=69){
synth->Speak("Hello "+textBox1->Text+", Nilaimu Cukup, Jangan terlalu banyak bermain");
}
else if(iNilai>=50 && iNilai<=59){
synth->Speak("Hello "+textBox1->Text+", Nilaimu Kurang, Kamu Harus Belajar Lebih Giat Lagi");
}
else {
synth->Speak("Hello "+textBox1->Text+", Anda Gagal, Harus diulang Tahun Depan");
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
};
}
Tampilan Output
Jika diklik tombol Cek akan mengeluarkan suara
Selamat Mencoba.
#MicrosoftVisualC++
#TexttoSpeech
#pragma once
namespace Aplikasi {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Speech::Synthesis;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::Button^ button1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
private: System::Windows::Forms::Button^ button2;
private:
int iNilai;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 18);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(41, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Nama :";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(60, 18);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(191, 20);
this->textBox1->TabIndex = 1;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(15, 63);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(33, 13);
this->label2->TabIndex = 2;
this->label2->Text = L"Nilai :";
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(60, 63);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(191, 20);
this->textBox2->TabIndex = 3;
this->textBox2->TextChanged += gcnew System::EventHandler(this, &Form1::textBox2_TextChanged);
//
// button1
//
this->button1->Location = System::Drawing::Point(98, 133);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 4;
this->button1->Text = L"CEK";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(98, 182);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 5;
this->button2->Text = L"EXIT";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->label2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e) {
int iTemp;
if(Int32::TryParse(textBox2->Text, iTemp))
iNilai = Convert::ToInt32(textBox2->Text);
else
textBox2->Text = Convert::ToString(iNilai);
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
SpeechSynthesizer^synth=gcnew SpeechSynthesizer();
if(iNilai>=80 && iNilai<=100){
synth->Speak("Hello "+textBox1->Text+", Nilaimu Sangat Bagus, Pertahankan");
}
else if(iNilai>=70 && iNilai<=79){
synth->Speak("Hello "+textBox1->Text+", Nilaimu Bagus, Tingkatkan");
}
else if(iNilai>=60 && iNilai<=69){
synth->Speak("Hello "+textBox1->Text+", Nilaimu Cukup, Jangan terlalu banyak bermain");
}
else if(iNilai>=50 && iNilai<=59){
synth->Speak("Hello "+textBox1->Text+", Nilaimu Kurang, Kamu Harus Belajar Lebih Giat Lagi");
}
else {
synth->Speak("Hello "+textBox1->Text+", Anda Gagal, Harus diulang Tahun Depan");
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
};
}
Tampilan Output
Jika diklik tombol Cek akan mengeluarkan suara
Selamat Mencoba.
#MicrosoftVisualC++
#TexttoSpeech
Komentar
Posting Komentar