语音Api求助.(100分)

  • 主题发起人 主题发起人 GanQuan
  • 开始时间 开始时间
G

GanQuan

Unregistered / Unconfirmed
GUEST, unregistred user!
  不知那位大虾有使用语音Api的经验(Acm*******函数),能对小弟指点一二.
 
tts我用过,只不过仅仅是英文的。中文的 tts还没出呢.
 
有好多人问过类似的问题了。<br>不知道你具体需要问什么问题?其实就是几个API地调用啊。
 
以前做过net中语音传输,录,放,<br>wave api(音频流播放等处理)<br>acm api(音频压缩处理)<br>时间有限,Multium@263.net
 
To Multium &amp;&amp;<br>To steve:<br>&nbsp; &nbsp;1. 在编程中发现虽然系统提供了很多CODEC,但在实际应用中,有些是不能用的,<br>&nbsp; 如: G.723不能用,G.711可以使用.(win98).如何得到这方面的信息?且如何能够<br>&nbsp; 用系统提供的所有CODEC; &nbsp; <br>&nbsp; &nbsp;2. CODEC有异步/同步方式,而且有些CODEC只支持解压不支持压缩,如何得到某个<br>&nbsp; 特定CODEC的这些方面的信息?<br>&nbsp; &nbsp;3. 在何种情况下要用到ACM中的filter功能?你有不有filter方面的技术文档或<br>&nbsp; 关于它的DEMO?<br>&nbsp; &nbsp;Email: xiang51235@263.net<br>
 
我建议你买《Windows多媒体编程》这本书,上边讲的很详细。<br>或者装一套MSDN来查一查。<br>在Windows中,所有的CODEC都用Audio Compression Manager (ACM)来管理,<br>利用ACM的一系列函数你可以找出系统都安装了哪些CODEC,并且可以查出<br>他们都支持什么格式。这一段话是MSDN中的原话。<br>我没用Delphi做过,我想Delphi中对这些API都已经声明了,如果没有,自己声明一下也<br>没什么的。<br>不过在VC中需要包括如下头文件:<br>#include &lt;windows.h&gt;<br>#include &lt;mmsystem.h&gt;<br>#include &lt;mmreg.h&gt; &nbsp;// Multimedia registration<br>#include &lt;msacm.h&gt; &nbsp; &nbsp;// Audio Compression Manager<br>#include &lt;stdio.h&gt;<br><br>在使用之前,现查一下ACM的版本号,然后再查一下系统装了几个CODEC:<br>&nbsp; &nbsp; // Get the ACM version.<br>&nbsp; &nbsp; DWORD dwACMVer = acmGetVersion();<br>&nbsp; &nbsp; printf("ACM version %u.%.02u build %u",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HIWORD(dwACMVer) &gt;&gt; 8,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HIWORD(dwACMVer) &amp; 0x00FF,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOWORD(dwACMVer));<br>&nbsp; &nbsp; if (LOWORD(dwACMVer) == 0) printf(" (Retail)");<br>&nbsp; &nbsp; printf("/n");<br><br>&nbsp; &nbsp; // Show some ACM metrics.<br>&nbsp; &nbsp; printf("ACM metrics:/n");<br><br>&nbsp; &nbsp; DWORD dwCodecs = 0;<br>&nbsp; &nbsp; MMRESULT mmr = acmMetrics(NULL, ACM_METRIC_COUNT_CODECS, &amp;dwCodecs);<br>&nbsp; &nbsp; if (mmr) {<br>&nbsp; &nbsp; &nbsp; &nbsp; show_error(mmr);<br>&nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("%lu codecs installed/n", dwCodecs);<br>&nbsp; &nbsp; }<br><br>然后找到系统已安装得所有CODEC和他们的详细信息:<br><br>&nbsp; &nbsp; // Enumerate the set of enabled drivers.<br>&nbsp; &nbsp; printf("Enabled drivers:/n");<br>&nbsp; &nbsp; mmr = acmDriverEnum(DriverEnumProc, 0, 0); <br>&nbsp; &nbsp; if (mmr) show_error(mmr);<br><br>&nbsp; &nbsp;DriverEnumProc是一个回调函数。<br>BOOL CALLBACK DriverEnumProc(HACMDRIVERID hadid, DWORD dwInstance, DWORD fdwSupport)<br>{<br>&nbsp; &nbsp; printf(" id: %8.8lxH", hadid);<br>&nbsp; &nbsp; printf(" &nbsp;supports:/n");<br>&nbsp; &nbsp; if (fdwSupport &amp; ACMDRIVERDETAILS_SUPPORTF_ASYNC) printf(" &nbsp; async conversions/n");<br>&nbsp; &nbsp; if (fdwSupport &amp; ACMDRIVERDETAILS_SUPPORTF_CODEC) printf(" &nbsp; different format conversions/n");<br>&nbsp; &nbsp; if (fdwSupport &amp; ACMDRIVERDETAILS_SUPPORTF_CONVERTER) printf(" &nbsp; same format conversions/n");<br>&nbsp; &nbsp; if (fdwSupport &amp; ACMDRIVERDETAILS_SUPPORTF_FILTER) printf(" &nbsp; filtering/n");<br><br>&nbsp; &nbsp; // Get some details.<br>&nbsp; &nbsp; ACMDRIVERDETAILS dd;<br>&nbsp; &nbsp; dd.cbStruct = sizeof(dd);<br>&nbsp; &nbsp; MMRESULT mmr = acmDriverDetails(hadid, &amp;dd, 0);<br>&nbsp; &nbsp; if (mmr) {<br>&nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; "); show_error(mmr);<br>&nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; Short name: %s/n", dd.szShortName);<br>&nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; Long name: &nbsp;%s/n", dd.szLongName);<br>&nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; Copyright: &nbsp;%s/n", dd.szCopyright);<br>&nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; Licensing: &nbsp;%s/n", dd.szLicensing);<br>&nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; Features: &nbsp; %s/n", dd.szFeatures);<br>&nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; Supports %u formats/n", dd.cFormatTags);<br>&nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; Supports %u filter formats/n", dd.cFilterTags);<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; return TRUE; // Continue enumeration.<br>}<br><br><br>
 
To:steve<br>&nbsp; &nbsp; &nbsp; &nbsp;你说的这些我已经做过(我也使用vc),得到了关于每个驱动程序的信息 <br>&nbsp; &nbsp; &nbsp;(比如G.723).但我用G.723压缩音频,结果acmStreamOpen返回正确,<br>&nbsp; &nbsp; &nbsp;acmStreamConvert却返回系统不支持信息,换用G.711却一切通过,且声音解压出来,<br>&nbsp; &nbsp; &nbsp;效果很好.缓冲区应该不会错,我根据WAVEFORMAT的 nAvgBytesPerSec分配空间,<br>&nbsp; &nbsp; &nbsp;且在此基础上还多分了足够的空间;因此我很疑惑?<br><br>另: 我查了一下系统驱动程序信息,很多都不支持filter功能,是不是再安装什么东西?<br>&nbsp; &nbsp; <br><br><br><br><br><br><br><br>
 
FormatTag用的是那个?<br>用没用acmFormatSuggest函数?nAvgBytesPerSec是平均传输输率,你不是改变它了吧?<br>最好你能把相关部分的代码贴出来看一下,这么说很笼统,不好分析。<br>或者你把你的相关部分截取下来发给我,我帮你看一下?
 
To:steve<br>&nbsp; &nbsp; &nbsp;我刚刚注册到大富翁,以前我一直用同学(GanQuan)的账号;<br>&nbsp; &nbsp; &nbsp;我用acm压缩语音的过程如下;<br><br>&nbsp; &nbsp; &nbsp;说明: 我是先采集一段语音数据到what.bin文件,为方便起见,我直接用<br>&nbsp; &nbsp; &nbsp;某个CODEC所支持的pcm格式采集,这样就不需要acmFormatSuggest了吧!<br>&nbsp;<br>&nbsp;压缩过程:<br>&nbsp; &nbsp; &nbsp; &nbsp;HACMDRIVER hadforUse; <br>&nbsp; &nbsp; &nbsp; &nbsp;acmDriverOpen(&amp;hadforUse, hadidUse, 0); &nbsp;<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp;acmStreamOpen(&amp;hstr, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hadforUse,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pwfPcm, &nbsp;//与我的采集格式一样;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pwfDst,  <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL,<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ACM_STREAMOPENF_NONREALTIME);<br><br>&nbsp; <br>&nbsp; &nbsp; DWORD dwRes21Bytes=pwfPcm-&gt;nAvgBytesPerSec;<br><br>&nbsp; &nbsp; BYTE *pRes21Data=new BYTE[dwRes21Bytes];<br>&nbsp; <br>&nbsp; &nbsp; DWORD dwDst21Bytes = pwfDst-&gt;nAvgBytesPerSec;<br><br>&nbsp; &nbsp; dwDst21Bytes = dwDst21Bytes * 3 / 2;<br>&nbsp; &nbsp;<br>&nbsp; &nbsp; BYTE* pDst21Data = new BYTE [dwDst21Bytes]; &nbsp; &nbsp;<br>&nbsp; &nbsp;<br>&nbsp; &nbsp; FILE *fp1,*fp2;<br>&nbsp; &nbsp; fp1=fopen("what.bin","rb");<br>&nbsp; &nbsp; fp2=fopen("what1.bin","wb");<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; //开始转换;<br>&nbsp; &nbsp; &nbsp; while(!feof(fp1))<br> {<br>&nbsp; &nbsp; <br> &nbsp; memset(pRes21Data,0,dwRes21Bytes); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset(pDst21Data,0,dwDst21Bytes);<br>&nbsp; &nbsp; &nbsp; <br><br> &nbsp; fread(pRes21Data,1,dwRes21Bytes,fp1);<br> &nbsp; <br> &nbsp; ACMSTREAMHEADER strhdr; &nbsp; &nbsp;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset(&amp;strhdr, 0, sizeof(strhdr));<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strhdr.cbStruct = sizeof(strhdr);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strhdr.pbSrc = pRes21Data; <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strhdr.cbSrcLength =dwRes21Bytes;<br>&nbsp; &nbsp; &nbsp; <br> &nbsp;strhdr.pbDst = pDst21Data;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strhdr.cbDstLength = dwDst21Bytes; &nbsp; &nbsp;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; acmStreamPrepareHeader(hstr, &amp;strhdr, 0); &nbsp; &nbsp; <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;acmStreamConvert(hstr, &amp;strhdr, 0); &nbsp; &nbsp;<br>&nbsp; <br> &nbsp;double f=((double)dwRes21Bytes)/((double)strhdr.cbDstLength); <br>&nbsp; &nbsp; &nbsp; <br> &nbsp;char buf5[100];<br> &nbsp;sprintf(buf5,"the ratio is &nbsp;%f",f);<br> &nbsp;AfxMessageBox(buf5);<br> &nbsp;<br><br> &nbsp;fwrite(pDst21Data,1,strhdr.cbDstLength,fp2);<br><br><br> acmStreamUnprepareHeader(hstr, &amp;strhdr, 0); &nbsp; &nbsp; <br><br> }<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; acmStreamClose(hstr, 0);<br>&nbsp; <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;acmDriverClose(hadforUse, 0);<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fclose(fp1);<br> fclose(fp2);<br> fp1=NULL;<br> fp2=NULL;<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delete pRes21Data;<br> delete &nbsp; pDst21Data;<br><br>
 
to:Steve &amp;&amp;Multium<br>&nbsp; &nbsp;你们还在看吗?
 
To:steve<br>&nbsp; &nbsp;你说的&lt;&lt;windows多媒体编程&gt;&gt;是本新书,还是旧书?那个出版社的?我咋没看到呀?
 
多人接受答案了。
 
后退
顶部