我正在尝试为eSpeak语音合成库创建一个包装器,到目前为止,我已经设法制作了单个字符合成等简单方法。然而,主要的合成方法对我来说太复杂了。有没有人对这个方法签名的C#映射有一个很好的建议? (特别是第一个变量!)
ESPEAK_API espeak_ERROR espeak_Synth(const void *text,
size_t size,
unsigned int position,
espeak_POSITION_TYPE position_type,
unsigned int end_position,
unsigned int flags,
unsigned int* unique_identifier,
void* user_data);
espeak_POSITION_TYPE我已经映射到枚举,我认为它有效。如果有用,则以下是文本变量的描述:
text: The text to be spoken, terminated by a zero character. It may be either 8-bit characters,
wide characters (wchar_t), or UTF8 encoding. Which of these is determined by the "flags"
parameter.
答案 0 :(得分:1)
取决于。
假设espeak_ERROR和espeak_POSITION_TYPE是整数:
[DllImport("...", CharSet=CharSet.Ansi)
static extern int espeak_Synth(string text,
int text_length,
int position,
int position_type,
int end_position,
int flags,
IntPtr unique_identifier,
IntPtr user_data);
这应该有用,如果你传递给标志,那文本是8位(而不是UTF)。
[DllImport("...")
static extern int espeak_Synth(IntPtr text,
int text_length,
int position,
int position_type,
int end_position,
int flags,
IntPtr unique_identifier,
IntPtr user_data);
// vv this can be some parameter
byte[] dat = Encoding.UTF8.GetBytes("some utf-8 string" + "\0"); // note the trailing '\0'!
IntPtr pnt = Marshal.AllocHGlobal(dat.Length);
try {
Marshal.Copy(dat, 0, pnt, dat.Length);
espeak_Synth(pnt, dat.Length, .....); // assuming the text_length is in bytes. If in octets, pass the string's length
}
finally
{
Marshal.FreeHGlobal(pnt);
}
如果你想传递UTF-8字符串。