Reputation: 127
I use Azure Speech SDK to convert a set of text files to voice. Successfully all of the texts are converted and an instance of ArrayBuffer is returned for each text. Then I convert each of them to Buffer and concatenate all of the buffers into one with Buffer.concat(). Then I pass the concatenated buffer data to fs.writeFile() to create an mp3 file. However only the first buffer is included in the audio file instead of the concatenated buffer. What should I do?
Upvotes: 0
Views: 312
Reputation: 141
To provide a little background, audio files generally consist of some header data that contains information about the audio (e.g. the sampling rate, how many channels of audio, etc...), followed by the actual audio data. Generally speaking, you should only have one header per audio file.
If you simply concatenate the audio data together, the header from the first file will be read by your media player. Since this doesn't contain any information about the other audio files you've concatenated, you'll get some non deterministic behaviour. It may play the audio from the first file only, it may give you an error, or it may try to play the header section for the remaining audio files as audio data (which is not correct).
For things to work correctly, you'd need to update the header to reflect all of the audio data, and strip out the remaining headers. You'd also need to make sure that the byte alignment, formatting, etc... of all your audio data is consistent.
Your best bet here is to use some software that understands how to read and parse audio files to stitch together your files. Using your search engine of choice for to search for e.g. combine mp3 files should help.
Upvotes: 1