jinyuttt

导航

用插件弄个语音阅读文本的小程序(托管C++)

突然想了解语音方面的东西,就在网上看了下,开始没有找到,后来看见了几个都是MFC和C#的。不过不是我想要的。我想要的效果还在搜索中。无聊就弄了个和别人差不多的翻版。用托管C++做的。加入插件。建立项目。在窗体上添加一个textbox,一个组合框,几个标签和2个控制音量的控件。代码如下:

SpVoice ^voic;
  bool pasue;
 private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
     SpVoice ^voic=gcnew SpVoice();
 
    
                voic->Voice = voic->GetVoices(String::Empty,String::Empty)->Item(comboBox1->SelectedIndex);              
              
     voic->Rate =rate;              
     voic->Volume =vol;              
     voic->Speak(textBox1->Text, SpeechVoiceSpeakFlags::SVSFDefault);

    }
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
   
             SpVoice ^voic=gcnew SpVoice();
 
     for each (ISpeechObjectToken ^Token in voic->GetVoices(String::Empty, String::Empty))
            {     
       
    this->comboBox1->Items->Add(Token->GetDescription(49));
            }
     this->comboBox1->SelectedIndex=0;
   
    pasue=false;
   }
private: System::Void trackBar2_Scroll(System::Object^  sender, System::EventArgs^  e) {
               rate=   this->trackBar2->Value ;
   }
private: System::Void trackBar1_Scroll(System::Object^  sender, System::EventArgs^  e) {
      vol=this->trackBar1->Value;
   }
private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
             
   }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
              
    this->voic=gcnew SpVoice();
   if(pasue)
    {
   this->voic->Resume();
       pasue=false;
    this->button2->Text="暂停";
  }
   else
   {
   this->voic->Pause();
     pasue=true;
     this->button2->Text ="继续";
    }
  }
   private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
       this->Close();
      }

 不过这个暂停有点问题样。在托管中不允许直接创建实例,但是要用于整个窗体的实例变量又必须在托管类中直接建立。我现在还没有找到好的解决办法。如果有人知道请留言告诉我哈。

posted on 2010-05-16 10:17  代码苦行僧  阅读(488)  评论(1编辑  收藏  举报