📄 osbprompt.cpp
字号:
/****************License************************************************ * * Copyright 2000-2001. SpeechWorks International, Inc. * * Use of this software is subject to notices and obligations set forth * in the SpeechWorks Public License - Software Version 1.1 which is * included with this software. * * SpeechWorks is a registered trademark, and SpeechWorks Here, * DialogModules and the SpeechWorks logo are trademarks of SpeechWorks * International, Inc. in the United States and other countries. * *********************************************************************** * * An implementation of the VXIpromptInterface object designed for scripted * QA of VXI interpreter * ***********************************************************************/#define OSBPROMPT_EXPORTS#include "OSBprompt.h"#include <cstdio>#include <string>#include <cstring>#define VXIstrcmp wcscmp#include "VXIvalue.h"typedef std::basic_string<VXIchar> vxistring;// ------*---------*---------*---------*---------*---------*---------*---------// Global for the base diagnostic tag ID//static VXIunsigned gblDiagLogBase = 0;// Constants for diagnostic logging tags//static const VXIunsigned DIAG_TAG_PROMPTING = 0;// OSBprompt implementation of the VXIprompt interface//extern "C" {struct OSBpromptImpl { // Base interface, must be first VXIpromptInterface intf; // Log interface for this resource VXIlogInterface *log;};}// A few conversion functions...static inline OSBpromptImpl * ToOSBpromptImpl(VXIpromptInterface * i){ return reinterpret_cast<OSBpromptImpl *>(i); }/******************************************************* * * Utility functions * *******************************************************/ /** * Log an error */static VXIlogResult Error(OSBpromptImpl *impl, VXIunsigned errorID, const VXIchar *format, ...){ VXIlogResult rc; va_list arguments; if ((! impl) || (! impl->log)) return VXIlog_RESULT_NON_FATAL_ERROR; if (format) { va_start(arguments, format); rc = (*impl->log->VError)(impl->log, COMPANY_DOMAIN L".OSBprompt", errorID, format, arguments); va_end(arguments); } else { rc = (*impl->log->Error)(impl->log, COMPANY_DOMAIN L".OSBprompt", errorID, NULL); } return rc;}/** * Log a diagnostic message */static VXIlogResult Diag(OSBpromptImpl *impl, VXIunsigned tag, const VXIchar *subtag, const VXIchar *format, ...){ VXIlogResult rc; va_list arguments; if ((! impl) || (! impl->log)) return VXIlog_RESULT_NON_FATAL_ERROR; if (format) { va_start(arguments, format); rc = (*impl->log->VDiagnostic)(impl->log, tag + gblDiagLogBase, subtag, format, arguments); va_end(arguments); } else { rc = (*impl->log->Diagnostic)(impl->log, tag + gblDiagLogBase, subtag, NULL); } return rc;}/******************************************************* * * Method routines for VXIpromptInterface structure * *******************************************************/ // Get the VXIprompt interface version supported//static VXIint32 OSBpromptGetVersion(void){ return VXI_CURRENT_VERSION;}// Get the implementation name//static const VXIchar* OSBpromptGetImplementationName(void){ static const VXIchar IMPLEMENTATION_NAME[] = COMPANY_DOMAIN L".OSBprompt"; return IMPLEMENTATION_NAME;}// Begin a session//static VXIpromptResult OSBpromptBeginSession(VXIpromptInterface * pThis, VXIMap *){ return VXIprompt_RESULT_SUCCESS;}// End a session//staticVXIpromptResult OSBpromptEndSession(VXIpromptInterface *pThis, VXIMap *){ return VXIprompt_RESULT_SUCCESS;}// Start playing queued prompts. This call is non-blocking.//static VXIpromptResult OSBpromptPlay(VXIpromptInterface * vxip){ OSBpromptImpl *impl = ToOSBpromptImpl(vxip); Diag(impl, DIAG_TAG_PROMPTING, NULL, L"Playing queued prompts"); return VXIprompt_RESULT_SUCCESS;}// Start the special play of a filler prompt. This call is non-blocking.//staticVXIpromptResult OSBpromptPlayFiller(VXIpromptInterface * vxip, const VXIchar *type, const VXIchar *src, const VXIchar *text, const VXIMap* properties, VXIlong minPlayMsec){ return VXIprompt_RESULT_SUCCESS;}// Start the special play of a filler prompt. This call is non-blocking.//staticVXIpromptResult OSBpromptPrefetch(VXIpromptInterface * vxip, const VXIchar *type, const VXIchar *src, const VXIchar *text, const VXIMap* properties){ return VXIprompt_RESULT_SUCCESS;}// Queue prompt for playing. This call is non-blocking. The prompt// is not played until OSBpromptPlay( ) is called.// staticVXIpromptResult OSBpromptQueue(VXIpromptInterface* vxip, const VXIchar *raw_type, const VXIchar *raw_src, const VXIchar *raw_text, const VXIMap *properties){ OSBpromptImpl *impl = ToOSBpromptImpl(vxip); const VXIbyte *binaryData = NULL; VXIulong binarySizeBytes = 0; vxistring type, src, text; if (raw_type) type = raw_type; if (raw_src) src = raw_src; if (raw_text) text = raw_text; // Resolve audio references if (src.find(PROMPT_AUDIO_REFS_SCHEME) == 0) { src.erase(0, PROMPT_AUDIO_REFS_SCHEME_LENGTH); // Get audio references from properties. const VXIValue * temp = VXIMapGetProperty(properties, PROMPT_AUDIO_REFS); if (temp == NULL || VXIValueGetType(temp) != VALUE_MAP) return VXIprompt_RESULT_INVALID_ARGUMENT; // Find information for this prompt. temp = VXIMapGetProperty((const VXIMap *) temp, src.c_str()); if (temp == NULL || VXIValueGetType(temp) != VALUE_MAP) return VXIprompt_RESULT_INVALID_ARGUMENT; const VXIMap * ref = (const VXIMap *) temp; type = L""; src = L""; text = L""; // Get the type temp = VXIMapGetProperty(ref, PROMPT_AUDIO_REF_TYPE); if (temp != NULL) { if (VXIValueGetType(temp) == VALUE_STRING) type = VXIStringCStr((const VXIString *) temp); else return VXIprompt_RESULT_INVALID_ARGUMENT; } // Get the URL temp = VXIMapGetProperty(ref, PROMPT_AUDIO_REF_SRC); if (temp != NULL) { if (VXIValueGetType(temp) != VALUE_STRING) return VXIprompt_RESULT_INVALID_ARGUMENT; else src = VXIStringCStr((const VXIString *) temp); } // Get the text or binary data temp = VXIMapGetProperty(ref, PROMPT_AUDIO_REF_DATA); if (temp != NULL) { switch (VXIValueGetType(temp)) { case VALUE_CONTENT: { const VXIchar *contentType; if (VXIContentValue((const VXIContent *) temp, &contentType, &binaryData, &binarySizeBytes) == VXIvalue_RESULT_SUCCESS) type = contentType; else return VXIprompt_RESULT_INVALID_ARGUMENT; } break; case VALUE_STRING: text = VXIStringCStr((const VXIString *) temp); break; default: return VXIprompt_RESULT_INVALID_ARGUMENT; } } } // Handle the resolved information to queue. if (! src.empty()) { Diag(impl, DIAG_TAG_PROMPTING, NULL, L"Queuing AUDIO: %s", src.c_str()); return VXIprompt_RESULT_SUCCESS; } else if (! text.empty()) { if (type == VXI_MIME_TEXT || type == VXI_MIME_UNICODE_TEXT) { // Get the language. const VXIValue * lang = VXIMapGetProperty(properties, PROMPT_LANGUAGE); if (lang != NULL && VXIValueGetType(lang) != VALUE_STRING) return VXIprompt_RESULT_INVALID_ARGUMENT; Diag(impl, DIAG_TAG_PROMPTING, NULL, L"Queuing TTS in %s (%s): %s", (lang == NULL) ? L"" : VXIStringCStr((const VXIString *) lang), type.c_str(), text.c_str()); } else if (type == VXI_MIME_XML || type == VXI_MIME_SSML) { // The language is encoded in the TTS string. Diag(impl, DIAG_TAG_PROMPTING, NULL, L"Queuing TTS (%s): %s", type.c_str(), text.c_str()); } else { Diag(impl, DIAG_TAG_PROMPTING, NULL, L"Queuing Unknown type text (%s): %s" , type.c_str(), text.c_str()); return VXIprompt_RESULT_UNSUPPORTED; } } else if (binarySizeBytes > 0) { if (type.find(L"audio/") == 0) { Diag(impl, DIAG_TAG_PROMPTING, NULL, L"Queueing IN-MEMORY AUDIO: (%s, %lu bytes)", type.c_str(), binarySizeBytes); } else { Diag(impl, DIAG_TAG_PROMPTING, NULL, L"Queueing Unknown type binary data (%s, %lu bytes)", type.c_str(), binarySizeBytes); return VXIprompt_RESULT_UNSUPPORTED; } } else return VXIprompt_RESULT_INVALID_ARGUMENT; return VXIprompt_RESULT_SUCCESS;} // Wait until all queued prompts finish playing.//staticVXIpromptResult OSBpromptWait(VXIpromptInterface* vxip, VXIpromptResult* playResult){ return VXIprompt_RESULT_SUCCESS;}/******************************************************* * Global init and factory methods *******************************************************/ OSBPROMPT_API VXIpromptResult OSBpromptInit (VXIlogInterface *log, VXIunsigned diagLogBase){ if (! log) return VXIprompt_RESULT_INVALID_ARGUMENT; gblDiagLogBase = diagLogBase; return VXIprompt_RESULT_SUCCESS; }OSBPROMPT_API VXIpromptResult OSBpromptShutDown (VXIlogInterface *log){ if (! log) return VXIprompt_RESULT_INVALID_ARGUMENT; return VXIprompt_RESULT_SUCCESS; }OSBPROMPT_API VXIpromptResult OSBpromptCreateResource (VXIlogInterface *log, VXIinetInterface *inet, VXIpromptInterface **prompt){ if ((! log) || (! inet)) return VXIprompt_RESULT_INVALID_ARGUMENT; OSBpromptImpl* pp = new OSBpromptImpl(); if (pp == NULL) return VXIprompt_RESULT_OUT_OF_MEMORY; pp->log = log; pp->intf.GetVersion = OSBpromptGetVersion; pp->intf.GetImplementationName = OSBpromptGetImplementationName; pp->intf.BeginSession = OSBpromptBeginSession; pp->intf.EndSession = OSBpromptEndSession; pp->intf.Play = OSBpromptPlay; pp->intf.PlayFiller = OSBpromptPlayFiller; pp->intf.Prefetch = OSBpromptPrefetch; pp->intf.Queue = OSBpromptQueue; pp->intf.Wait = OSBpromptWait; *prompt = &pp->intf; return VXIprompt_RESULT_SUCCESS;}OSBPROMPT_API VXIpromptResult OSBpromptDestroyResource (VXIpromptInterface **prompt){ if (prompt == NULL || *prompt == NULL) return VXIprompt_RESULT_INVALID_ARGUMENT; OSBpromptImpl* promptImpl = reinterpret_cast<OSBpromptImpl*>(*prompt); delete promptImpl; *prompt = NULL; return VXIprompt_RESULT_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -