C# write wav file




















Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy. In this article, there are several examples showing various ways to write text to a file. The first two examples use static convenience methods on the System. The third example shows how to add text to a file when you have to process each line individually as you write to the file. In the first three examples, you overwrite all existing content in the file.

The final example shows how to append text to an existing file. These examples all write string literals to files.

There's not a lot to say about it, but the code follows:. And of course, as a final test, I double clicked on the file. It opened in Windows Media Player and played the Sine wave. So there you have it, the program works! When I get a chance, I will try to make a version of this in Windows Phone 7. Those of you that have WPDT without the full version of Visual Studio will not be able to compile this program directly. But the binary is included in the source code if you want to run it.

Sign in Email. Forgot your password? Search within: Articles Quick Answers Messages. Technical Blog. View Original. Tagged as C. Stats Writing a Proper Wave File. Joel Ivory Johnson Rate me:. Please Sign up or sign in to vote. Playing back data that was recorded from the Microphone, in Windows Phone 7. Download source Currently one of the recurring questions I see in the Windows Phone 7 forums deals with playing back data that was recorded from the microphone.

Why Won't the File Play The file won't play because none of the components or software which it has, has been given to know anything about the file. Simulating Audio Data I need some data to write to my file. The code I used to do this follows: C.

Copy Code. Trival Fact: Satisficing is a phrase coined by Herbert Simon to mean sufficiently satisfying. A satisficing solution may not be the best solution, but it get's the job done! Joel Ivory Johnson. Software Developer. Write string writes a string that is prefixed with it's length for BinaryReader to read it back.

It is not intended to be used like your case. You need to write the bytes directly instead of using BinaryWriter. Write string. There may also be other problems, like the integers you are writing may not be of the same size as required.

You should check them carefully. As for endianess, the link you put states that data are in little-endian and BinaryWriter uses little-endian, so this should not be a problem. Writing a string in a binary file, it will include the length of the string so that it can be deserialized back into a string later.

In this case you just want the four bytes to be written as four bytes, and converting it to a char array will do just that. I lack the proper WAV data, but try replacing the part of your code where you generate the header with this code replace appropriately :. Alvin-wong answer works perfect. Just wanted to add another suggestion although a few more lines is:. How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Creating a. Asked 8 years, 11 months ago. Active 3 years, 8 months ago. Viewed 22k times. Write "RIFF" ; wr. Write "WAVEfmt " ; wr. Write 16 ; wr. Write ushort 1 ; wr. Write numchannels ; wr. Write samplerate ; wr. Write "data" ; wr. Write byte a. Improve this question.

Flagbug 2, 2 2 gold badges 24 24 silver badges 47 47 bronze badges. What do you mean, 'it won't open correctly'? Please mention the exact error or exception.



0コメント

  • 1000 / 1000