/// <summary> /// Records the supplied file /// </summary> /// <param name="filename"></param> /// <param name="options"></param> /// <param name="cookies"></param> /// <returns></returns> public static Byte[] Record( String filename, Options options, CookieCollection cookies ) { if (null == filename) throw new ArgumentNullException(filename); return Record(File.ReadAllBytes(filename), options, cookies); }
/// <summary> /// Records the supplied file /// </summary> /// <remarks>See: http://www.spokentext.net/s_record_file.php?.</remarks> /// <param name="file"></param> /// <param name="options"></param> /// <param name="cookies"></param> /// <returns></returns> public static Byte[] Record( Byte[] file, Options options, CookieCollection cookies ) { throw new NotImplementedException( "Implementation succeeds but does not produce a recording." ); if (null == file) throw new ArgumentNullException("file"); if (file.Length == 0) throw new ArgumentException("Unexpected empty file."); if (null == cookies) throw new ArgumentNullException("sessionId"); RestCommand command = CreatePostCommand( RecordServiceUrl, options, cookies ); command.Data.Add("uploadFile", file); HttpWebResponse response = command.Execute(); // (2) TODO: Fetch back the MP3. This takes time anyway. return new Byte[1] { 0x0 }; }
/// <summary> /// Creates RestCommand for POST operations. Most operations share a bunch of RestParameters. /// </summary> /// <param name="cookies"></param> /// <returns></returns> static RestCommand CreatePostCommand( String url, Options options, CookieCollection cookies ) { RestCommand command = new RestCommand(url, RestTransport.Post); command.Transport.HttpContentType = HttpContentType.MultipartFormData; command.RedirectionPolicy = new RestRedirectionPolicy(1); command.Parameters.Add("voice", options.Voice); command.Parameters.Add("wpm", options.Wpm.ToString()); command.Parameters.Add("volume", options.Volume.ToString()); command.Parameters.Add("emailMe", options.EmailMe ? "1" : "0"); command.Parameters.Add("public", options.IsPublic ? "1" : "0"); command.Parameters.Add("submit", "Record"); command.Parameters.Add("specialWords", String.Empty); command.Cookies.Add(cookies); return command; }
/// <summary> /// Records the supplied text /// </summary> /// <remarks> /// For some reason this records URL encoded text, it is not decoded at the other end for some reason. /// </remarks> /// <param name="name"></param> /// <param name="text"></param> /// <param name="options"></param> /// <param name="cookies"></param> public static void RecordText( String name, String text, Options options, CookieCollection cookies ) { if (null == name || null == text) throw new ArgumentNullException( null == name ? "name" : "text" ); RestCommand command = CreatePostCommand( RecordEnteredTextServiceUrl, options, cookies ); command.Parameters.Add("recordingNameEnteredText", name); command.Parameters.Add("text", text); // We should be redirected to the list of recordings. using (StreamReader rdr = command.ExecuteStreamReader()) { #if DEBUG Console.WriteLine("DEBUG: Response from RecordText invocation."); while (rdr.Peek() > -1) { Console.WriteLine(rdr.ReadLine()); } #endif } }