闲的无聊,锻炼一下托管c++,
看代码
#pragma once
#include "Window1.g.h"
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Text;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Data;
using namespace System::Windows::Documents;
using namespace System::Windows::Input;
using namespace System::Windows::Media;
using namespace System::Windows::Media::Imaging;
using namespace System::Windows::Shapes;
using namespace System::Collections::ObjectModel;
using namespace System::Xml;
using namespace System::Speech::Synthesis;
namespace speechSynth
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
//ORIGINAL LINE: public partial class Window1 : System.Windows.Window
//INSTANT C++ TODO TASK: C++ does not support 'partial' types. You must manually combine the entire Window1 type in one place.
public ref class Window1 : System::Windows::Window
{
private:
SpeechSynthesizer ^synth;
public:
Window1()
{
InitializeComponent();
synth = gcnew SpeechSynthesizer();
synth->StateChanged += gcnew EventHandler<StateChangedEventArgs^>(this, &Window1::synth_StateChanged);
synth->BookmarkReached += gcnew EventHandler<BookmarkReachedEventArgs^>(this, &Window1::synth_BookmarkReached);
synth->PhonemeReached += gcnew EventHandler<PhonemeReachedEventArgs^>(this, &Window1::synth_PhonemeReached);
synth->SpeakCompleted += gcnew EventHandler<SpeakCompletedEventArgs^>(this, &Window1::synth_SpeakCompleted);
synth->SpeakProgress += gcnew EventHandler<SpeakProgressEventArgs^>(this, &Window1::synth_SpeakProgress);
synth->SpeakStarted += gcnew EventHandler<SpeakStartedEventArgs^>(this, &Window1::synth_SpeakStarted);
synth->VisemeReached += gcnew EventHandler<VisemeReachedEventArgs^>(this, &Window1::synth_VisemeReached);
synth->VoiceChange += gcnew EventHandler<VoiceChangeEventArgs^>(this, &Window1::synth_VoiceChange);
this->btnSpeakText->Click += gcnew RoutedEventHandler(this, &Window1::btnSpeakText_Click);
this->btnWavFile->Click += gcnew RoutedEventHandler(this, &Window1::btnWavFile_Click);
this->btnVoices->Click += gcnew RoutedEventHandler(this, &Window1::btnVoices_Click);
this->btnSpeakSsml->Click += gcnew RoutedEventHandler(this, &Window1::btnSpeakSsml_Click);
this->btnPause->Click += gcnew RoutedEventHandler(this, &Window1::btnPause_Click);
this->btnResume->Click += gcnew RoutedEventHandler(this, &Window1::btnResume_Click);
this->btnPromptBuilder->Click += gcnew RoutedEventHandler(this, &Window1::btnPromptBuilder_Click);
this->btnToXml->Click += gcnew RoutedEventHandler(this, &Window1::btnToXml_Click);
this->btnSsmlPitch->Click += gcnew RoutedEventHandler(this, &Window1::btnSsmlPitch_Click);
this->btnCutIn->Click += gcnew RoutedEventHandler(this, &Window1::btnCutIn_Click);
this->sliderRate->ValueChanged += gcnew RoutedPropertyChangedEventHandler<double>(this, &Window1::sliderRate_ValueChanged);
this->sliderVolume->ValueChanged += gcnew RoutedPropertyChangedEventHandler<double>(this, &Window1::sliderVolume_ValueChanged);
}
private:
void btnCutIn_Click(System::Object ^sender, RoutedEventArgs ^e)
{
synth->SpeakAsyncCancelAll(); //stops current async call
synth->SpeakAsync("this is some interrupting text"); //just appends, unless AsyncCancelAll() called first
//synth.Speak("this is some interrupting text"); //does not interrupt async call
}
void btnSsmlPitch_Click(System::Object ^sender, RoutedEventArgs ^e)
{
XmlDocument ^xd = gcnew XmlDocument();
xd->Load("ssmlPitch.xml");
synth->SpeakSsmlAsync(xd->OuterXml);
}
#pragma region SYNTHESIZER_EVENTS
void synth_VoiceChange(System::Object ^sender, VoiceChangeEventArgs ^e)
{
System::Diagnostics::Debug::WriteLine("VoiceChange : " + e->Voice->Name);
}
void synth_VisemeReached(System::Object ^sender, VisemeReachedEventArgs ^e)
{
System::Diagnostics::Debug::WriteLine("VisemeReached : " + e->Viseme.ToString());
}
void synth_SpeakStarted(System::Object ^sender, SpeakStartedEventArgs ^e)
{
System::Diagnostics::Debug::WriteLine("SpeakStarted");
}
void synth_SpeakProgress(System::Object ^sender, SpeakProgressEventArgs ^e)
{
System::Diagnostics::Debug::WriteLine("SpeakProgress : " + e->AudioPosition.TotalSeconds.ToString());
}
void synth_SpeakCompleted(System::Object ^sender, SpeakCompletedEventArgs ^e)
{
System::Diagnostics::Debug::WriteLine("SpeakCompleted");
}
void synth_PhonemeReached(System::Object ^sender, PhonemeReachedEventArgs ^e)
{
System::Diagnostics::Debug::WriteLine("PhonemeReached : " + e->Phoneme->ToString());
}
void synth_BookmarkReached(System::Object ^sender, BookmarkReachedEventArgs ^e)
{
System::Diagnostics::Debug::WriteLine("BookmarkReached : " + e->Bookmark);
}
void synth_StateChanged(System::Object ^sender, StateChangedEventArgs ^e)
{
System::Diagnostics::Debug::WriteLine("StateChanged : " + e->State.ToString());
lblState->Content = e->State.ToString();
}
#pragma endregion
void btnToXml_Click(System::Object ^sender, RoutedEventArgs ^e)
{
PromptBuilder ^myPrompt = GetBuiltPrompt();
MessageBox::Show(myPrompt->ToXml());
}
void btnPromptBuilder_Click(System::Object ^sender, RoutedEventArgs ^e)
{
PromptBuilder ^pb = GetBuiltPrompt();
//Now let's get the synthesizer to render this message
//SpeechSynthesizer synth = new SpeechSynthesizer();
synth->SetOutputToDefaultAudioDevice();
synth->SpeakAsync(pb);
}
PromptBuilder ^GetBuiltPrompt()
{
//from http://msdn.microsoft.com/msdnmag/issues/06/01/speechinWindowsVista/
//This prompt is quite complicated
//So I'm going to build it first, and then render it.
PromptBuilder ^myPrompt = gcnew PromptBuilder();
//Start the main speaking style
PromptStyle ^mainStyle = gcnew PromptStyle();
mainStyle->Rate = PromptRate::Medium;
mainStyle->Volume = PromptVolume::Loud;
myPrompt->StartStyle(mainStyle);
//Alert the listener
myPrompt->AppendAudio(gcnew Uri("file://c://windows//media//notify.wav"), "Attention!");
myPrompt->AppendText("Here are some important messages.");
//Here's the first important message
myPrompt->AppendTextWithPronunciation("WinFX", "w?n?f?ks");
myPrompt->AppendText("is a great platform.");
//And the second one
myPrompt->AppendTextWithHint("ASP", SayAs::SpellOut);
myPrompt->AppendText("is an acronym for Active Server Pages. Whereas an ASP is a snake.");
myPrompt->AppendBreak();
//Let's emphasise how important these messages are
PromptStyle ^interimStyle = gcnew PromptStyle();
interimStyle->Emphasis = PromptEmphasis::Strong;
myPrompt->StartStyle(interimStyle);
myPrompt->AppendText("Please remember these two things.");
myPrompt->EndStyle();
//Then we can revert to the main speaking style
myPrompt->AppendBreak();
myPrompt->AppendText("Thank you");
myPrompt->EndStyle();
return myPrompt;
}
void btnResume_Click(System::Object ^sender, RoutedEventArgs ^e)
{
synth->Resume();
}
void btnPause_Click(System::Object ^sender, RoutedEventArgs ^e)
{
synth->Pause();
}
void btnSpeakSsml_Click(System::Object ^sender, RoutedEventArgs ^e)
{
//http://www.w3.org/TR/speech-synthesis/
synth->SetOutputToDefaultAudioDevice();
//XmlDocument xd = new XmlDocument();
////xd.Load("sampleSSML.xml"); //works
//xd.Load("ssmlPitch.xml"); //works
//synth.SpeakSsmlAsync(xd.OuterXml);
//XmlDocument xd = new XmlDocument();
////xd.Load("sampleSSML.xml"); //TODO doesn't work?
//xd.Load("ssmlPitch.xml"); //TODO doesn't work?
//PromptBuilder pb = new PromptBuilder();
//pb.AppendSsmlMarkup(xd.DocumentElement.OuterXml);
//synth.SpeakAsync(pb);
PromptBuilder ^pb = gcnew PromptBuilder();
pb->AppendText("blah");
pb->AppendSsml("sampleSSML.xml"); //works
//pb.AppendSsml("ssmlPitch.xml"); //TODO doesn't work
synth->SpeakAsync(pb);
}
void sliderVolume_ValueChanged(System::Object ^sender, RoutedPropertyChangedEventArgs<double> ^e)
{
synth->Volume = safe_cast<int>(sliderVolume->Value);
}
void sliderRate_ValueChanged(System::Object ^sender, RoutedPropertyChangedEventArgs<double> ^e)
{
synth->Rate = safe_cast<int>(sliderRate->Value);
}
void btnVoices_Click(System::Object ^sender, RoutedEventArgs ^e)
{
ReadOnlyCollection<InstalledVoice^> ^voices = synth->GetInstalledVoices();
System::String ^retVal = System::String::Empty;
for each (InstalledVoice ^iv in voices)
{
retVal += iv->VoiceInfo->Name + "/r/n";
}
MessageBox::Show(retVal);
}
void btnWavFile_Click(System::Object ^sender, RoutedEventArgs ^e)
{
synth->SetOutputToWaveFile("spoken.wav");
synth->Speak(GetText());
synth->SetOutputToNull();
MessageBox::Show("done");
}
void btnSpeakText_Click(System::Object ^sender, RoutedEventArgs ^e)
{
synth->SetOutputToDefaultAudioDevice();
synth->SpeakAsync(GetText());
}
System::String ^GetText()
{
return txtToSpeak->Text->Trim();
}
};
}
需要的留下EMAIL,我给大家发
分享到:
相关推荐
现在很多人都使用C#来开发windows mobile上的应用程序,因此,有必要给出这个“使用托管代码开发WINCE自带数据库”的例子。这篇文章参考了Joao Paulo Figueira在2005年写的文章《CEDB .NET》,并对作者给出的代码...
Microsoft中间语言与Java字节代码共享一种理念:它们都是一种低级语言 语法很简单 使用数字代码 而不是文本代码 可以非常快速地转换为内部机器码 对于代码来说 这种精心设计的通用语法 有很大的优点 ">托管代码的...
这是一个不错的,讲托管代码非托管代码的 ppt
C#托管代码与C++非托管代码互相调用实例
CLR 完全介绍 托管代码与非托管代码之间的封送处理
C#调用非托管代码
详细解析托管代码与非托管代码以及dll调用.
可以实现利用非托管代码来访问由.NET生成的托管代码。
复制到猛犸代码助手 根目录下的 Template 文件夹里 覆盖掉原先的旧版本。 然后运行 猛犸代码助手 ,在工具栏 点击“向导”按钮打开项目向导, 点击 “C++”模板类型,及可以看到最新安装版本的 模板了。 欢迎大家...
对于非托管代码API函数中如何使用委托实现回调方法!
这是大三上学期我们学校暑期软件工程课的时候小组做的windows GUI 软件,资源内为源程序及可执行文件。还有一个说明文件readme.txt。 软件功能介绍入下: 支持标准的流程图图形,如矩形、菱形等元素 支持在不同的...
介绍了在C#下,系统怎样与非托管代码交互操作
基于GitGithub的代码托管及版本控制《游戏开发技术实践》课程设计实验报告
Git代码托管管理工具安装包 Git代码托管管理工具安装包 Git代码托管管理工具安装包 Git代码托管管理工具安装包 Git代码托管管理工具安装包 Git代码托管管理工具安装包 Git代码托管管理工具安装包 Git代码托管管理...
通过本文你可以学习到:将一般的dll文件,导入到.net托管的环境中;开发一个简单的文本朗读系统.里面有源代码和语音库.
详细介绍了托管代码的机制 方便更深入的了解原理
vc++2005视频教程!想学习vc++2005的可以看看!
C#托管代码与C++非托管代码互相调使用.pdf
视频,简单介绍.net和托管代码之间的关系,方便大家了解.net框架
1)新建项目empty,必要可github托管。 2)先写页面在res->layout目录下新建两个layout xml file activity_main作为主页面,msg_item为附在其上的消息页面。(具体代码见文末) 这里再acitvity_main采用的不是...