Exemple #1
0
  ///<summary>The entry point for the application.</summary>
  ///<param name="argv">A list of arguments</param>
  public static void Main( string[] argv )
  {
   Boolean                  booleanParseCommandLineArguments  =  false;
   string                   exceptionMessage                  =  null;
   UtilitySpeechArgument    utilitySpeechArgument             =  null;
   
   utilitySpeechArgument         =  new UtilitySpeechArgument();
   
   booleanParseCommandLineArguments  =  UtilityParseCommandLineArgument.ParseCommandLineArguments
   ( 
    argv, 
    utilitySpeechArgument
   );

   if ( booleanParseCommandLineArguments == false )
   {
    // error encountered in arguments. Display usage message
    System.Console.Write
    (
     UtilityParseCommandLineArgument.CommandLineArgumentsUsage( typeof ( UtilitySpeechArgument ) )
    );
    return;
   }//if ( booleanParseCommandLineArguments  == false )

   SpVoiceSpeak
   (
    ref utilitySpeechArgument,
    ref exceptionMessage
   );
   
  }//public static void Main()
Exemple #2
0
 ///<summary>SpVoiceSpeak</summary>
 public static void SpVoiceSpeak
 (
  ref UtilitySpeechArgument  utilitySpeechArgument,
  ref string                 exceptionMessage
 )
 {
  object                 voice                  =  null;
  object[]               voiceArgv              =  null;                  
  SpeechVoiceSpeakFlags  speechVoiceSpeakFlags  =  SpeechVoiceSpeakFlagsDefault;
  SpAudioFormatClass     spAudioFormatClass     =  null;
  SpFileStream           spFileStream           =  null;
  SpVoice                spVoice                =  null;
  Type                   typeSAPISpVoice        =  null;
  try
  {
   spVoice                =  new SpVoice();
   typeSAPISpVoice        =  Type.GetTypeFromProgID("SAPI.SpVoice");
   voice                  =  Activator.CreateInstance( typeSAPISpVoice );
   voiceArgv              =  new object[2];
   voiceArgv[1]           =  0;
   speechVoiceSpeakFlags  =  SpeechVoiceSpeakFlagsEnum( false, utilitySpeechArgument.xml );
   if ( string.IsNullOrEmpty( utilitySpeechArgument.pathAudio ) == false )
   {
    spAudioFormatClass         =  new SpAudioFormatClass();
    spAudioFormatClass.Type    =  SpeechAudioFormatType.SAFTGSM610_11kHzMono; //Heavily compressed
    spFileStream               =  new SpFileStream();
    spFileStream.Format        =  spAudioFormatClass;
    spFileStream.Open( utilitySpeechArgument.pathAudio, SpeechStreamFileMode.SSFMCreateForWrite, false );
    spVoice.AudioOutputStream  =  spFileStream;
    spVoice.Rate = -5; //Ranges from -10 to 10 
   }
   foreach( string text in utilitySpeechArgument.text )
   {
    /*
    spVoice.Speak( text, speechVoiceSpeakFlags );
    */
    voiceArgv[0]  =  text;
    typeSAPISpVoice.InvokeMember("Speak", BindingFlags.InvokeMethod, null, voice, voiceArgv);
   }
   speechVoiceSpeakFlags = SpeechVoiceSpeakFlagsEnum( true, utilitySpeechArgument.xml );
   foreach( string pathSource in utilitySpeechArgument.pathSource )
   {
    if ( string.IsNullOrEmpty( pathSource ) ) { continue; }
    if ( File.Exists( pathSource ) == false ) { continue; }     
    spVoice.Speak( pathSource, speechVoiceSpeakFlags );
   }//foreach( string pathSource in utilitySpeechArgument.pathSource )
  }//try
  catch ( Exception exception ) { UtilityException.ExceptionLog( exception, exception.GetType().Name, ref exceptionMessage ); }
  if ( spFileStream != null ) { spFileStream.Close(); }
 }//public static void SpVoiceSpeak()
Exemple #3
0
        }//public void ButtonSubmit_Click()

        /// <summary>SpVoiceSpeak</summary>
        public void SpVoiceSpeak()
        {
            bool   impersonateValidUser = false;
            string exceptionMessage     = null;
            WindowsImpersonationContext windowsImpersonationContext = null;
            UtilitySpeechArgument       utilitySpeechArgument       = null;

            utilitySpeechArgument = new UtilitySpeechArgument
                                    (
                CheckBoxXml.Checked,
                new string[] { FileUploadSource.PostedFile.FileName },
                FileUploadAudio.PostedFile.FileName,
                new string[] { TextBoxText.Text },
                null //voice
                                    );
            try
            {
                impersonateValidUser = UtilityImpersonate.ImpersonateValidUser
                                       (
                    ref ImpersonateDomainName,
                    ref ImpersonatePassword,
                    ref ImpersonateUserName,
                    ref windowsImpersonationContext,
                    ref exceptionMessage
                                       );
                if (exceptionMessage != null)
                {
                    Feedback = exceptionMessage; return;
                }
                if (impersonateValidUser == false)
                {
                    return;
                }
                UtilitySpeech.SpVoiceSpeak
                (
                    ref utilitySpeechArgument,
                    ref exceptionMessage
                );
                UtilityImpersonate.UndoImpersonation
                (
                    ref windowsImpersonationContext,
                    ref exceptionMessage
                );
            }//try
            catch (Exception exception) { exceptionMessage = exception.Message; }
            if (exceptionMessage != null)
            {
                Feedback = exceptionMessage;
            }
        } //public static void SpVoiceSpeak()