⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audio_ostream.aspx.htm

📁 识别语音的C代码! 还有教程说明.大家自己看看吧!
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<p>Deriving from <code>boost::iostreams::stream</code> gives us all the <code>ostream</code> functionality. This stream objects needs to be initialized with a sink object instance. Thus, we also derive from <code>SinkType</code> (the template parameter) and initialize the <code>boost::iostreams::stream</code> with <code>*<span class="code-keyword">this</span></code>. Another advantage of deriving from <code>SinkType</code> is that it allows us direct access to the sink object. Direct access allows us, for example, to access the <code>SetRate()</code> method directly, to change the speech speed.</p>

<h2>Speaking the Text</h2>

<p>The <code>boost::iostreams</code> machinery will take care of all the type conversions and <code>ostream</code> syntax. Eventually, <code>audio_sink::write</code> will be called. Although we provided both narrow and wide character string <code>ostream</code>s, SAPI supports only wide character strings. Also, the Sink's <code>write()</code> methods accept <em>non</em>-null-terminated strings and the number of characters to use from the stream.</p>

<p>To address these two issues, we'll convert the continuous stream + size to a null-terminated (w)string using the appropriate <code>std::(w)<span class="code-SDKkeyword">string</span></code> constructor.</p>

<p>To speak the narrow character string, we call the wide <code>write</code> version with STLSoft's <code>winstl::a2w()</code> to easily convert from narrow to wide. <code>winstl::a2w()</code> will take care of any required allocations and deallocation of temporary buffers, and of the conversion itself.</p>

<h2>Possible Extensions</h2>

<p>Having achieved my the design goals, some possible extensions come to mind.</p>

<p>It might be interesting to extend the <code>ostream</code> support even further by using locales for language selection. Wrapping some of the XML tags as <code>ostream</code>
manipulators, will give a more natural (or, at least, familiar) syntax.
Of course, similar extensions can convert the SAPI Speech Recognition
Interfaces into an <code>istream</code>, but that's a completely different ball game.</p>

<p>It might also be desirable to support synchronous (blocking) speech.</p>

<h2>Revision History</h2>
<ul>
  <li><strong>March 30, 2007</strong> Fixed code to compile and run on MSVS 2005, by using <code><span class="code-keyword">wchar_t</span></code> instead of <code><span class="code-keyword">unsigned</span> <span class="code-keyword">short</span></code>. <br>
    Thanks to Jochen Berteld for pointing out the problem and to Matthew Wilson for pointing out the solution.
  </li>
</ul>



<!-- Article Ends -->


			<!-- Main Page Contents End -->
			
			</div>
			</span>
			
			<form name="aspnetForm" method="post" action="audio_ostream.aspx" id="aspnetForm" style="margin: 0pt; padding: 0pt;">
		<div>
		<input name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMDUyNjYzMjhkZLl/d/bcrtfAkXSCUFdCes5pcDaX" type="hidden">
		</div>
		

			
			<h2>License</h2>
			<div id="ctl00_LicenseTerms"><p>This
article has no explicit license attached to it but may contain usage
terms in the article text or the download files themselves. If in doubt
please contact the author via the discussion board below.</p><p>A list of licenses authors might use can be found <a href="http://www.codeproject.com/info/Licenses.aspx">here</a></p></div>
			
			<h2>About the Author</h2>
			
					
            
<table width="100%" border="0" cellpadding="0" cellspacing="5">
<tbody><tr valign="top">
<td id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberPhotoTable" style="width: 155px;" valign="top">
	<b><a id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberProfileLink" href="http://www.codeproject.com/script/Membership/Profiles.aspx?mid=13410">Adi Shavit</a></b><br><br>
	<center></center><br>
	<span id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberType" class="SmallText"></span>
		
</td>
		
<td>
	<br>	

	<table>
	<tbody><tr id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_jobTitleRow">
			<td class="SmallText" nowrap="nowrap">Occupation: </td>
			<td width="100%"><span id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberJobTitle" class="SmallText">Architect</span></td>
		</tr>
		

	

	<tr id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_locationRow">
			<td class="SmallText">Location: </td>
			<td width="100%"><span id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberLocation" class="SmallText"><img src="audio_ostream.aspx_files/IL.gif" alt="Israel" width="16" height="11"> Israel</span></td>
		</tr>
		
	</tbody></table>
	
</td>
</tr>
</tbody></table>

					<br>
				
			
			<table id="ctl00_PopularArticlesRow" width="100%" border="0" cellpadding="0" cellspacing="0">
			<tbody><tr valign="top">
				<td style="width: 100%;">
					<h2>Other popular Audio and Video articles:</h2><ul><li><a href="http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx">Motion Detection Algorithms</a><div class="SmallText">Some approaches to detect motion in a video stream.</div></li><li><a href="http://www.codeproject.com/KB/audio-video/cameraviewer.aspx">Camera Vision - video surveillance on C#</a><div class="SmallText">A C# video surveillance application, which allows monitoring several IP cameras simultaneously.</div></li><li><a href="http://www.codeproject.com/KB/audio-video/face_detection.aspx">Face Detection C++ Library with Skin and Motion Analysis</a><div class="SmallText">The
article demonstrates face detection SSE optimized C++ library for color
and gray scale data with skin detection, motion estimation for faster
processing, small sized SVM and NN rough face prefiltering,
PCA/LDA/ICA/any dimensionality reduction/projection and final NN
classification</div></li><li><a href="http://www.codeproject.com/KB/audio-video/avifilewrapper.aspx">A Simple C# Wrapper for the AviFile Library</a><div class="SmallText">Edit AVI files in .NET.</div></li><li><a href="http://www.codeproject.com/KB/audio-video/avicapwrp.aspx">CAviCap and CFrameGrabber - wrappers for AVICap Window</a><div class="SmallText">AVICap wrappers to ease real-time video processing and single frame capture</div></li></ul>
					<h2></h2>				
				</td>
				<td>
					<iframe src="audio_ostream.aspx_files/ServeThirdParty_004.htm" scrolling="no" width="300" frameborder="0" height="250"></iframe>
				</td>
			</tr>
		</tbody></table>
		
		
			<div id="ctl00_AddTo_AddTo" style="margin: 10px;">
<script language="JavaScript" type="text/javascript">
var addtoMethod=1;
var AddURL = document.location.href;
var AddTitle = escape(document.title);
DrawLinks(100, 0, "SmallText Bold", "AddTo") 
</script><span class="SmallText Bold">Add this article to: </span> <a class="AddTo" title="Add this page to Digg" onclick="return addto(0);" href="#"><img src="audio_ostream.aspx_files/AddTo_Digg.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Del.icio.us" onclick="return addto(1);" href="#"><img src="audio_ostream.aspx_files/AddTo_Delicious.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Google" onclick="return addto(2);" href="#"><img src="audio_ostream.aspx_files/AddTo_Google.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Windows Live" onclick="return addto(3);" href="#"><img src="audio_ostream.aspx_files/AddTo_Live.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Yahoo! MyWeb" onclick="return addto(4);" href="#"><img src="audio_ostream.aspx_files/AddTo_Yahoo.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Technorati" onclick="return addto(5);" href="#"><img src="audio_ostream.aspx_files/AddTo_Technorati.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Blink" onclick="return addto(6);" href="#"><img src="audio_ostream.aspx_files/AddTo_Blink.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Facebook" onclick="return addto(7);" href="#"><img src="audio_ostream.aspx_files/AddTo_Facebook.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Furl" onclick="return addto(8);" href="#"><img src="audio_ostream.aspx_files/AddTo_Furl.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Simpy" onclick="return addto(9);" href="#"><img src="audio_ostream.aspx_files/AddTo_Simpy.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Reddit" onclick="return addto(10);" href="#"><img src="audio_ostream.aspx_files/AddTo_Reddit.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Newsvine" onclick="return addto(11);" href="#"><img src="audio_ostream.aspx_files/AddTo_Newsvine.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Stumbleupon" onclick="return addto(12);" href="#"><img src="audio_ostream.aspx_files/AddTo_stumbleupon.png" width="16" align="absmiddle" border="0" height="16"></a>  <a class="AddTo" title="Add this page to Mr. Wong" onclick="return addto(13);" href="#"><img src="audio_ostream.aspx_files/AddTo_MrWong.png" width="16" align="absmiddle" border="0" height="16"></a>  
</div>
			
			<table id="ctl00_RateArticleRow" class="RatingBar" width="100%" border="0" cellpadding="0" cellspacing="0">
			<tbody><tr>
				<td><a href="#_top">Article Top</a></td>
				<td align="right">            
<table width="100%" cellpadding="0" cellspacing="0"><tbody><tr>

	
	
	<td id="voteTbl" style="white-space: nowrap;" class="SmallText" align="right">
	
		<table><tbody><tr>
		<td id="ctl00_RateArticle_SignIn" nowrap="nowrap"><a href="#SignUp">Sign Up</a> to vote for this article</td>
				
		
		
		
		
		<td><span id="ctl00_RateArticle_ErrorMessage"></span></td>
		</tr></tbody></table>
	</td>
</tr></tbody></table>



</td>
			</tr>
		</tbody></table>
		
			</form>
			
			<div style="padding: 10px; overflow: hidden; text-align: center; white-space: nowrap;">
				<iframe src="audio_ostream.aspx_files/ServeThirdParty_005.htm" scrolling="no" width="468" frameborder="0" height="60"></iframe>
									  
			</div>

			<a name="_comments"></a><!-- Forum Start -->
<div id="_MessageBoard" onclick="return SwitchMessage(event, null)">
	<table id="ForumTable" class="Frm_MainTable" cellpadding="0" cellspacing="0">
		<tbody><tr>
			<td class="Frm_MsgAlert"><b>You must <a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fKB%2faudio-video%2faudio_ostream.aspx%3ffid%3d393985">Sign In</a> to use this message board.</b></td>
		</tr><tr>
			<td><form action="/script/Forums/SetOptions.aspx?floc=%2fKB%2faudio-video%2faudio_ostream.aspx&amp;fid=393985" method="get" style="margin: 0pt; padding: 0pt;">
				<input name="fid" value="393985" type="hidden"><input name="currentQS" value="?floc=%2fKB%2faudio-video%2faudio_ostream.aspx&amp;fid=393985" type="hidden"><input name="floc" value="/KB/audio-video/audio_ostream.aspx" type="hidden"><table width="100%" border="0" cellpadding="3" cellspacing="0">
					<tbody><tr class="Frm_HeaderRow1">
						<td style="white-space: nowrap;"><img src="audio_ostream.aspx_files/forum_faq.gif" alt="FAQ" width="16" align="middle" border="0" height="16">&nbsp;<a href="http://www.codeproject.com/script/Forums/FAQ.aspx"><b>FAQ</b></a>&nbsp;</td><td style="white-space: nowrap; text-align: right;">Noise Tolerance<select size="1" class="Frm_DropDown" name="noise">
							<option value="1">Very High</option><option value="2">High</option><option selected="selected" value="3">Medium</option><option value="4">Low</option><option value="5">Very Low</option>
						</select></td><td colspan="2" style="white-space: nowrap; text-align: right;"><img src="audio_ostream.aspx_files/forum_search.gif" alt="Search" width="16" align="top" border="0" height="15">&nbsp;<a href="http://www.codeproject.com/script/Forums/Search.aspx?fid=393985">Search Messages</a>&nbsp;</td><td style="text-align: right;"><input value="Set Options" name="submit" class="Frm_Button" type="submit"></td>
					</tr><tr class="Frm_HeaderRow2">
						<td style="width: 100%;">&nbsp;</td><td style="white-space: nowrap; text-align: right;">Layout<select size="1" class="Frm_DropDown" name="view">
							<option selected="selected" value="Quick">Normal</option><option value="Topic">Expand Root Messages</option><option value="Expanded">Expand All Messages</option><option value="Thread">Thread View</option><option value="Normal">No Javascript (slow)</option><option value="Preview">No Javascript Preview</option>
						</select>&nbsp;&nbsp;</td><td style="white-space: nowrap;">Per page<select size="1" class="Frm_DropDown" name="mpp">
							<option value="10">10</option><option selected="selected" value="25">25</option><option value="50">50</option>
						</select>&nbsp;&nbsp;</td><td colspan="2">&nbsp;</td>
					</tr>
				</tbody></table>
			</form></td>
		</tr><tr>
			<td><a name="xx0xx"></a><table width="100%" border="0" cellpadding="2" cellspacing="0">
				<tbody><tr class="Frm_NavigationBar">
					<td>&nbsp;</td><td>Msgs 1 to 25 of 33 (Total in Forum: 33) (<a href="http://www.codeproject.com/KB/audio-video/audio_ostream.aspx?fid=393985">Refresh</a>)</td><td style="text-align: right; white-space: nowrap;"><span class="Frm_HL">First</span><span class="Frm_HL">Prev</span><a class="Frm_HL" name="Frm_HoverNL" href="http://www.codeproject.com/KB/audio-video/audio_ostream.aspx?fid=393985&amp;fr=26#xx0xx">Next</a></td>
				</tr>
			</tbody></table></td>
		</tr><tr>
			<td><table class="Frm_MsgTable" width="100%" border="0" cellpadding="0" cellspacing="0">
				

<!-- Column Headers -->

				<tbody><tr class="Frm_ColumnHeaders">
					<td style="width: 100%;"><table width="100%" border="0" cellpadding="2" cellspacing="0">
						<tbody><tr>
							<td>Subject&nbsp;</td><td class="Frm_MsgAuthor">&nbsp;Author&nbsp;</td><td class="Frm_MsgDate">Date&nbsp;</td>
						</tr>
					</tbody></table></td>
				</tr><tr>
					<td><img src="audio_ostream.aspx_files/t_002.gif" alt="" width="1" border="0" height="5"></td>
				</tr>
<!-- Start Message head -->

				<tr class="MsgHd Rt HdUnSel" id="F2440886_h0">
					<td width="100%"><table class="QuickHd" width="100%" border="0" cellpadding="0" cellspacing="0">
						<tbody><tr>
							<td class="Frm_MsgIndent" width="16"><a name="xx2440886xx"></a><img src="audio_ostream.aspx_files/msg_general.gif" alt="General" width="16" align="top" height="16"></td><td class="Frm_MsgSubject"><a id="DynMessLink" name="2440886" href="http://www.codeproject.com/KB/audio-video/audio_ostream.aspx?fid=393985&amp;select=2440886#xx2440886xx">Idea for a feature</a></td><td style="width: 20px; white-space: nowrap

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -