Fix passing strings from C# to C. (#1701)
See also https://github.com/k2-fsa/sherpa-onnx/issues/1695#issuecomment-2585725190 We need to place a 0 at the end of the buffer.
This commit is contained in:
@@ -16,7 +16,10 @@ namespace SherpaOnnx
|
||||
{
|
||||
Impl impl = (Impl)Marshal.PtrToStructure(Handle, typeof(Impl));
|
||||
byte[] utf8Filename = Encoding.UTF8.GetBytes(filename);
|
||||
int status = SherpaOnnxWriteWave(impl.Samples, impl.NumSamples, impl.SampleRate, utf8Filename);
|
||||
byte[] utf8FilenameWithNull = new byte[utf8Filename.Length + 1]; // +1 for null terminator
|
||||
Array.Copy(utf8Filename, utf8FilenameWithNull, utf8Filename.Length);
|
||||
utf8FilenameWithNull[utf8Filename.Length] = 0; // Null terminator
|
||||
int status = SherpaOnnxWriteWave(impl.Samples, impl.NumSamples, impl.SampleRate, utf8FilenameWithNull);
|
||||
return status == 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user