Search code examples
c#stringwave

Create wave file from a string


Solved, thanks. It's base64 and this works.

System.Convert.FromBase64String(columns[6]);

Thanks again.

I got a TSV file, and inside this file there're audio stored as original string and related wave info. One wave and its info per line. What I need to do is to read each line, get the audio, and save them as separated wave files. One sample of wave string is like this:

UklGRpgiAABXQVZFZm10ICwAAACUAgEAgD4AAPAKAAA4AAAAGgABAA8AKACOAgEAgD4AANAHAAAoAAAAAgBAAWRhdGFYIgAAQMQKQPQTQTQSQTQSQTQUQYNBVBNBJBJBJBNBJBRBRKFEE0EkE0FEFEE0FEFUFQAAAAAAAAAAAADACOmRY92lbj7+7kGhMFC3V9I3qMyjX2G8vAclkKFxUlD26mS+1qCRMV4OuVCxXf/IxrFBj///9sAG0iRqqUOIIRKT/4vqBtdWJF6pI/mWgPFx6JlUIFUPm6gofbyf93hJ6NCbgja88uTflydp///

And I tried to read this line and use:

byte[] waveContext = Encoding.Default.GetBytes(columns[6]);
File.WriteAllBytes(waveFullPath, waveContext);

But the output file contains just the same string. Does anybody got ideas on how to handle this?

Many thanks.


Solution

  • Looks like a base 64 encoded string.

     byte[] waveBytes = System.Convert.FromBase64String(base64EncodedData);
    

    Don't know how to build up a wave file. This may help you: MSDN: Creating wav files in C#. (10secs lookup with Google.)