/// <summary> /// Uploads a WAV file indicated as a voice name for the target distribution list referenced by the pObjectID value. /// </summary> /// <param name="pConnectionServer"> /// Reference to the ConnectionServer object that points to the home server where the list is homed. /// </param> /// <param name="pSourceLocalFilePath"> /// Full path on the local file system pointing to a WAV file to be uploaded as a voice name for the list referenced. /// </param> /// <param name="pObjectId"> /// ObjectId of the distribution list to upload the voice name WAV file for. /// </param> /// <param name="pUserObjectId"> /// User that owns the private list to set the voice name for. /// </param> /// <param name="pConvertToPcmFirst"> /// Converts the wav file into a format Connection can handle before uploading /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult SetPrivateListVoiceName(ConnectionServerRest pConnectionServer, string pSourceLocalFilePath, string pObjectId, string pUserObjectId, bool pConvertToPcmFirst = false) { WebCallResult res = new WebCallResult(); res.Success = false; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to SetPrivateListVoiceName"; return(res); } if (string.IsNullOrEmpty(pUserObjectId) || string.IsNullOrEmpty(pObjectId)) { res.ErrorText = "Empty objectId or UserObjectId passed to SetPrivateListVoiceName"; return(res); } //check and make sure a legit folder is referenced in the target path if (String.IsNullOrEmpty(pSourceLocalFilePath) || (File.Exists(pSourceLocalFilePath) == false)) { res = new WebCallResult(); res.Success = false; res.ErrorText = "Invalid local file path passed to SetPrivateListVoiceName: " + pSourceLocalFilePath; return(res); } //if the user wants to try and rip the WAV file into PCM 16/8/1 first before uploading the file, do that conversion here if (pConvertToPcmFirst) { string strConvertedWavFilePath = pConnectionServer.ConvertWavFileToPcm(pSourceLocalFilePath); if (string.IsNullOrEmpty(strConvertedWavFilePath) || File.Exists(strConvertedWavFilePath) == false) { res.ErrorText = "Converted PCM WAV file path not found in SetPrivateListVoiceName: " + strConvertedWavFilePath; return(res); } //point the wav file we'll be uploading to the newly converted G711 WAV format file. pSourceLocalFilePath = strConvertedWavFilePath; } //use the 8.5 and later voice name formatting here which simplifies things a great deal. string strResourcePath = string.Format(@"{0}users/{1}/privatelists/{2}/voicename", pConnectionServer.BaseUrl, pUserObjectId, pObjectId); //upload the WAV file to the server. return(pConnectionServer.UploadWavFile(strResourcePath, pSourceLocalFilePath)); }
/// <summary> /// Sets the post greeting recording for a particular language. The WAV file is uploaded (after optionally being converted /// to a format Conneciton will accept). /// </summary> /// <param name="pConnectionServer"> /// The Connection server that houses the post greeting recording being edited. /// </param> /// <param name="pSourceLocalFilePath"> /// Full path on the local file system to the WAV file to be uploaded as the greeting. /// </param> /// <param name="pPostGreetingRecordingObjectId"> /// The GUID identifying the post greeting recording that owns the greeting being edited. /// </param> /// <param name="pLanguageId"> /// The language ID of the WAV file being uploaded (for US English this is 1033). The LanguageCodes enum defined in the ConnectionTypes /// class can be helpful here. /// </param> /// <param name="pConvertToPcmFirst"> /// Defaults to false, but if passed as true this has the target WAV file first converted PCM, 16 Khz, 8 bit mono before uploading. This /// helps ensure Connection will not complain about the media file format. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult SetPostGreetingRecordingWavFile(ConnectionServerRest pConnectionServer, string pSourceLocalFilePath, string pPostGreetingRecordingObjectId, int pLanguageId, bool pConvertToPcmFirst = false) { WebCallResult res = new WebCallResult(); if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to SetPostGreetingRecordingWavFile"; return(res); } //check and make sure a legit folder is referenced in the target path if (String.IsNullOrEmpty(pSourceLocalFilePath) || (File.Exists(pSourceLocalFilePath) == false)) { res = new WebCallResult(); res.Success = false; res.ErrorText = "Invalid local file path passed to SetPostGreetingRecordingWavFile: " + pSourceLocalFilePath; return(res); } //if the user wants to try and rip the WAV file into G711 first before uploading the file, do that conversion here if (pConvertToPcmFirst) { string strConvertedWavFilePath = pConnectionServer.ConvertWavFileToPcm(pSourceLocalFilePath); if (string.IsNullOrEmpty(strConvertedWavFilePath) || File.Exists(strConvertedWavFilePath) == false) { res.ErrorText = "Converted G711 WAV file path not found in SetPostGreetingRecordingWavFile: " + strConvertedWavFilePath; return(res); } //point the wav file we'll be uploading to the newly converted G711 WAV format file. pSourceLocalFilePath = strConvertedWavFilePath; } //new construction - requires 8.5 or later and is done in one step to send the greeting to the server. string strGreetingStreamUriPath = string.Format("https://{0}:8443/vmrest/postgreetingrecordings/{1}/postgreetingrecordingstreamfiles/{2}/audio", pConnectionServer.ServerName, pPostGreetingRecordingObjectId, pLanguageId); return(pConnectionServer.UploadWavFile(strGreetingStreamUriPath, pSourceLocalFilePath)); }
/// <summary> /// Uploads a WAV file as the target interview handler question referenced by the pObjectID and question number value. /// </summary> /// <param name="pConnectionServer"> /// Reference to the ConnectionServer object that points to the home server where the interview handler is homed. /// </param> /// <param name="pSourceLocalFilePath"> /// Full path on the local file system pointing to a WAV file to be uploaded as an interview handler question /// </param> /// <param name="pObjectId"> /// ObjectId of the interview handler that owns the question to be updated /// </param> /// <param name="pQuestionNumber"> /// Interview question to update (1-20) /// </param> /// <param name="pConvertToPcmFirst"> /// If passed as TRUE the routine will attempt to convert the target WAV file into raw PCM first before uploading it to the Connection /// server. A failure to convert will be considered a failed upload attempt and false is returned. This value defaults to FALSE meaning /// the file will attempt to be uploaded as is. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult SetInterviewHandlerQuestionRecording(ConnectionServerRest pConnectionServer, string pSourceLocalFilePath, string pObjectId, int pQuestionNumber, bool pConvertToPcmFirst = false) { string strConvertedWavFilePath = ""; WebCallResult res = new WebCallResult(); res.Success = false; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to SetInterviewHandlerQuestionRecording"; return(res); } //check and make sure a legit folder is referenced in the target path if (String.IsNullOrEmpty(pSourceLocalFilePath) || (File.Exists(pSourceLocalFilePath) == false)) { res = new WebCallResult(); res.Success = false; res.ErrorText = "Invalid local file path passed to SetInterviewHandlerQuestionRecording: " + pSourceLocalFilePath; return(res); } //if the user wants to try and rip the WAV file into PCM 16/8/1 first before uploading the file, do that conversion here if (pConvertToPcmFirst) { strConvertedWavFilePath = pConnectionServer.ConvertWavFileToPcm(pSourceLocalFilePath); if (string.IsNullOrEmpty(strConvertedWavFilePath)) { res.ErrorText = "Failed converting WAV file into PCM format in SetInterviewHandlerQuestionRecording."; return(res); } if (File.Exists(strConvertedWavFilePath) == false) { res.ErrorText = "Converted PCM WAV file path not found in SetInterviewHandlerQuestionRecording: " + strConvertedWavFilePath; return(res); } //point the wav file we'll be uploading to the newly converted G711 WAV format file. pSourceLocalFilePath = strConvertedWavFilePath; } //string strResourcePath = string.Format(@"{0}handlers/interviewhandlers/{1}/interviewquestions/{2}", pConnectionServer.BaseUrl, // pObjectId, pQuestionNumber); //need to do this via the older "two part" method - upload the file, get the ID back and then do another //update of the object to save the stream file name string strStreamFileName; res = pConnectionServer.UploadWavFileToStreamLibrary(pSourceLocalFilePath, out strStreamFileName); if (res.Success == false) { return(res); } string strBody = "<InterviewQuestion>"; strBody += string.Format("<{0}>{1}</{0}>", "VoiceFile", strStreamFileName); strBody += "</InterviewQuestion>"; string strUri = string.Format("{0}handlers/interviewhandlers/{1}/interviewquestions/{2}", pConnectionServer.BaseUrl, pObjectId, pQuestionNumber); res = pConnectionServer.GetCupiResponse(strUri, MethodType.PUT, strBody, false); //upload the WAV file to the server. //res = RestTransportFunctions.UploadWavFile(strResourcePath, pConnectionServer.LoginName, pConnectionServer.LoginPw, pSourceLocalFilePath); //if we converted a file to G711 in the process clean up after ourselves here. Only delete it if the upload was good - otherwise //keep it around as it may be useful for diagnostic purposes. if (res.Success && !string.IsNullOrEmpty(strConvertedWavFilePath) && File.Exists(strConvertedWavFilePath)) { try { File.Delete(strConvertedWavFilePath); } catch (Exception ex) { //this is not a show stopper error - just report it back but still return success if that's what we got back from the //wav upload routine. res.ErrorText = "(warning) failed to delete temporary PCM wav file in SetInterviewHandlerVoiceName:" + ex.Message; } } return(res); }