Here is the full source code for CreateWaveFile:
public static void CreateWaveFile(string filename, IWaveProvider sourceProvider) { using (WaveFileWriter writer = new WaveFileWriter(filename, sourceProvider.WaveFormat)) { byte[] buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4]; while (true) { int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length); if (bytesRead == 0) break; writer.Write(buffer, 0, bytesRead); } } }
The problem is simply that the size of the buffer ought to be a multiple of 65. Make it 65000 or something. Then it should work.
As for how to insert silence, your way is fine. The only alternative is to create one 65 byte block of GSM silence (don't know what that looks like), and insert those blocks. However, even that may produce artefacts if the GSM codec stores state between consecutive blocks.