# Convert AudioRawData to WAVE

**URL:** <https://devforum.zoom.us/t/convert-audiorawdata-to-wave/68004>\
**Category:** Windows\
**Created:** [April 23, 2022, 7:52pm UTC](https://devforum.zoom.us/t/convert-audiorawdata-to-wave/68004 "2022-04-23T19:52:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samwestby](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@samwestby](https://devforum.zoom.us/u/samwestby)\
**Post date:** [April 23, 2022, 7:52pm UTC](https://devforum.zoom.us/t/convert-audiorawdata-to-wave/68004/1 "2022-04-23T19:52:19Z")

</div>

**Description**  
I’m having trouble converting the written AudioRawData to a .wav file. After I convert from raw PCM to WAVE the audio plays random static. The static also is a different length than my original recording. Here’s my code:

In onMixedAudioRawDataReceived

```auto
ofstream f;

```

…

```auto
f.open("example.pcm", ios::out | ios::binary | ios::app);

```

…

```auto
char* buf = data_->GetBuffer();
f.write(buf, strlen(buf));

```

Then I have tried to convert the file using ffmpeg:

```auto
ffmpeg -f s16le -ar 32k -ac 1 -i example.pcm example.wav

```

and using sox:

```auto
sox -t raw -r 32000 -e signed --endian little -b 16 -c 1 example.pcm -r 32000 example.wav 

```

But example.wav just plays static. I can’t figure out where my code is going wrong and would appreciate any help.

**Which Windows Meeting SDK version?**  
v5.10.3.4873.

I figured I’d also add that I get the following two errors when I run the ffmpeg command:

```auto
Invalid PCM packet, data has size 1 but at least a size of 2 was expected
Error while decoding stream #0:0: Invalid data found when processing input

```

---

<div class="post-metadata">

**Author:** ![samwestby](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@samwestby](https://devforum.zoom.us/u/samwestby)\
**Post date:** [April 24, 2022, 2:11am UTC](https://devforum.zoom.us/t/convert-audiorawdata-to-wave/68004/2 "2022-04-24T02:11:14Z")

</div>

SOLVED! For anyone who stumbles across this, the error is with this line

> [@samwestby](#):
>
> `f.write(buf, strlen(buf));`

Here, buf is a variable size, and is 0 when there is no audio. The static I was hearing in my wav file was my original audio with every bit of silence removed. That is also why I was getting an error from ffmpeg, because the size of the audio file was not nicely divisible. Instead the line of code should be:

```auto
f.write(buf, data_->GetBufferLen());

```

This writes a fixed buffer size of 640.

---

<div class="post-metadata">

**Author:** ![jon.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jon.zoom/32/13495_2.png) [@jon.zoom](https://devforum.zoom.us/u/jon.zoom)\
**Post date:** [April 25, 2022, 7:12pm UTC](https://devforum.zoom.us/t/convert-audiorawdata-to-wave/68004/3 "2022-04-25T19:12:57Z")

</div>

That’s great that you were able to resolve this, thanks for sharing the solution!

---

<div class="post-metadata">

**Author:** ![jon.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jon.zoom/32/13495_2.png) [@jon.zoom](https://devforum.zoom.us/u/jon.zoom)\
**Post date:** [April 25, 2022, 7:13pm UTC](https://devforum.zoom.us/t/convert-audiorawdata-to-wave/68004/4 "2022-04-25T19:13:01Z")

</div>

Closed on April 25, 2022, 7:13pm UTC


