• 用插件弄个语音阅读文本的小程序(托管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();
          }

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

  • 相关阅读:
    Mono项目将继续推动基于Linux的开发
    VS.PHP 在Visual Studio 下的 PHP 开发 IDE 工具
    SQL Server 2008 的代码提示功能
    想做的时候没有机会了
    我的最爱
    双缓冲
    做个好男人!
    再见了,曾经喜欢过的歌手
    看看他是喜欢你还是爱你的~~~
    独家:未来五年程序员应当具备的十项技能
  • 原文地址:https://www.cnblogs.com/jinyuttt/p/1736609.html
Copyright © 2020-2023  润新知