Prototype Definition int WINAPI SsmPlayMem(int ch, int nFormat, LPBYTE pBuf, DWORD dwBufSize, DWORD dwStartOffset, DWORD dwStopOffset) Parameter ch channel number nFormat encoding format of play data, valid value:-1 (default play coding format in hardware channels is adopted, which can be set in configuration file of hardware DLL), 6(A-LAW), 7(μ-LAW), 17( IMA ADPCM) and 85(MP3, only for MP3 record board) pBuf pointer to initial address of record buffer areadwBufSize size of play data buffer area(bytes) dwStartOffset offset of initial play position in play buffer area dwStopOffset offset of ending play position in the buffer area, if the parameter is more than or equal to size of buffer area, the buffer area is circularly played.这个说第三个参数是语音数据的开始地址跟那个函数地址没有关系吧.
Type ty = MessageBox.Show("erererer").GetType(); System.Reflection.MethodInfo[] methods = ty.GetMethods(); MessageBox.Show(methods[0].MethodHandle.Value.ToString());我通过反射找到了该方法的“句柄”,但因为不知道什么是句柄,只好到这里停下了。显示出来得东西会有一串数字,不知道是不是地址。
using System.Reflection;private void button1_Click(object sender, EventArgs e) { MethodInfo mi = typeof(MessageBox).GetMethod("Show", new Type[] { typeof(string) }); Console.WriteLine(mi.MethodHandle.GetFunctionPointer()); }
然后用
Marshal.GetFunctionPointerForDelegate
得到一个函数指针,
通常这个函数指针就是函数地址了.
SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice voice = new SpVoice();
voice.Speak(richTextBox1.Text, spFlags);内存放音函数:函数原型:
int SsmPlayMem(int ch, int nFormat, LPBYTE pBuf, DWORD dwBufSize, DWORD dwStartOffset, DWORD dwStopOffset)第三个参数为 存放语音数据的缓冲区地址。
请问怎么能取到voice.Speak(richTextBox1.Text, spFlags);这句话的地址,然后把地址转成byte[]型代到那个函数里。语言请用C#,有知道的朋友吗?
楼主的"只要取到这句话的地址" 中的"地址"是不是一个函数在代码区的地址呀?
如果是.怎么把它变成byte[] 型,byte[]型只能是对堆区的引用,怎么可能把一个代码区的地址给它呢?
如果不是.那是什么?
int WINAPI SsmPlayMem(int ch, int nFormat, LPBYTE pBuf, DWORD dwBufSize, DWORD dwStartOffset,
DWORD dwStopOffset)
Parameter
ch
channel number
nFormat
encoding format of play data, valid value:-1 (default play coding format in hardware channels is adopted, which
can be set in configuration file of hardware DLL), 6(A-LAW), 7(μ-LAW), 17( IMA ADPCM) and 85(MP3, only for
MP3 record board)
pBuf
pointer to initial address of record buffer areadwBufSize
size of play data buffer area(bytes)
dwStartOffset
offset of initial play position in play buffer area
dwStopOffset
offset of ending play position in the buffer area, if the parameter is more than or equal to size of buffer area, the
buffer area is circularly played.这个说第三个参数是语音数据的开始地址跟那个函数地址没有关系吧.
你应该用SpVoice的AudioOutputStream属性得到输出的音频流然后在放到SsmPlayMem的第三个参数才可以
你就是想用SsmPlayMem来替代voice.Speak来播放声音吧?
但是你不知道怎么把字符串转换为BYTE[],可以用 System.Text.Encoding 类的GetBytes 方法
byte[] bytes = System.Text.Encoding.Unicode.GetBytes( "abcdefg" );
System.Reflection.MethodInfo[] methods = ty.GetMethods();
MessageBox.Show(methods[0].MethodHandle.Value.ToString());我通过反射找到了该方法的“句柄”,但因为不知道什么是句柄,只好到这里停下了。显示出来得东西会有一串数字,不知道是不是地址。
{
MethodInfo mi = typeof(MessageBox).GetMethod("Show", new Type[] { typeof(string) });
Console.WriteLine(mi.MethodHandle.GetFunctionPointer());
}
2032379936,我CPU是32位的,只会出现8位的十六进制数,例如:0x03e0e534, 不会出现你那中数字的.
SsmPlayMem是用C或C++写的吧,
C#引用这个函数是, 修改下函数原型不就可以了?
函数原型:int SsmPlayMem(int ch, int nFormat, LPBYTE pBuf, DWORD dwBufSize, DWORD dwStartOffset, DWORD dwStopOffset) 第三个参数的定义为: typedef BYTE far *LPBYTE;C#引用改为:[DllImport("SHP_A3.dll")]
public static extern int SsmPlayMem(int ch, int nFormat, byte[] pBuf,
uint dwBufSize, uint dwStartOffset, uint dwStopOffset);看在11楼提出的问题.
SsmPlayMem(ch, nFormat, voice.Speak(richTextBox1.Text, spFlags),......)
这样吗?voice.Speak(...) 返回什么值?
而你把voice.Speak(richTextBox1.Text, spFlags);这句话的地址, 传给SsmPlayMem(....), 有什么用, 呢它又不是音频数据?按我的想法, voice.Speak(richTextBox1.Text, spFlags)应该要返回Byte[], 表示文本对应的声音流,
或者, 你返回BOOL或INT, 那么应修改为:voice.Speak(richTextBox1.Text, spFlags, out Byte[] buf)之类的方式,
将音频数据通过参数传出来,
然后, SsmPlayMem(...,buf,...);你始终要求将voicie.Speak的代码地址(可以这样理解吗?)做为Byte[]参数, 实在让人不解你在11楼所说的, 我都看过了, 只是没看明白而已我想请问你, voice.Speak(...), 这个函数将文本转成语音数据吗, 你转完后, 音频数据都放在哪?
IL_XXXX: call int voice.Speak(...);你期望将上面的指令在进程空间中地址传给SsmPlayMem(...)?实在没什么用, 好象?