Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good night dear!

Please, as I do to join audios being recorded 1.wav and 2.wav generated by a text for spech API (microsoft azure). I tried a code snippet below it works for two recorded audios, but for this example it does not perform the audio creation 3.wav (WaveFileWriter.CreateWaveFile16 ("3.wav", mixer);).

I believe the problem is a difference in the "bit rate" of the files, could that be? How can I fix it?



C#
using NAudio.Wave;
using NAudio.Wave.SampleProviders;

using (var reader1 = new AudioFileReader("1"))
using (var reader2 = new AudioFileReader("2.wav"))
{
   var mixer = new MixingSampleProvider(new[] { reader1, reader2 });
   WaveFileWriter.CreateWaveFile16("3.wav", mixer);
}


What I have tried:

- Concatenating Wave Files Using C# 2005[^]
Posted
Updated 11-Aug-20 18:00pm
v2

1 solution

A WAV file contains a header plus a lot of audio samples; the header holds some parameters that apply to all the samples, it includes number of channels, number of bits per sample, and sample rate.

You can concatenate audio samples from different files as long as the header information matches (except for the length of course).

When the headers don't match, some conversion is required. I have never done such conversions, however I recommend you read, understand, and possibly use (some of) the code in this article:

C# WAV file class, audio mixing, and some light audio manipulation[^]

And you will have to watch out for volume problems, one file being much louder than another...

:)
 
Share this answer
 
Comments
Garth J Lancaster 11-Aug-20 6:06am    
+5 - nice find (link) Luc
José Madureira 12-Aug-20 0:01am    
Thank you very much for your help!

I tried to run the solution, but it gave error:
"Test2Speech.WAVFileAudioMergeException: 'The sample rates of the audio files differ.' "

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900