简体   繁体   English

如何以编程方式组合.wav文件?

[英]How to programmatically combine .wav files?

I would like to play some kind of text-to-speech with only numbers. 我想只用数字播放某种文本到语音转换。 I can record 10 wav files, but how can I combine them programmatically ? 我可以录制10个wav文件,但是如何以编程方式将它们组合在一起?

For instance, the user types 1234, and the text-to-speech combines 1.wav with 2.wav, 3.wav and 4.wav to produce 1234.wav that plays "one two three four". 例如,用户键入1234,并且文本转语音将1.wav与2.wav,3.wav和4.wav组合在一起以产生播放“一二三四”的1234.wav。

1) create a new destination sample buffer (you will want to know the sizes). 1)创建一个新的目标样本缓冲区(您将要知道大小)。

2) read the samples (eg using AudioFile and ExtAudioFile APIs) and write them in sequence to the buffer. 2)读取样本(例如,使用AudioFile和ExtAudioFile API),并将其依次写入缓冲区。 You may want to add silence between the files. 您可能要在文件之间添加静音。

It will help if your files are all the same bit depth (the destination bit depth - 16 should be fine) and sample rate. 如果文件的位深(目标位深-16应该很好)和采样率都相同,则将很有帮助。

Alternatively, if you have fixed, known, sample rates and bit depths for all files, you could just save them as raw sample data and be done in much less time because you could simply append the data as is without writing all the extra audio file reading programs. 另外,如果您对所有文件都有固定的已知采样率和位深,则可以将它们另存为原始采样数据,并用更少的时间完成,因为您可以按原样追加数据而无需编写所有额外的音频文件阅读程序。

The open source project wavtools provides a good reference for this sort of work, if you're ok with perl. 如果您对perl感到满意,那么开源项目wavtools将为此类工作提供很好的参考。 Otherwise there is a similar question with some java examples. 否则,一些Java示例也会有类似的问题

The simplist common .wav (RIFF) file format just has a 44 byte header in front of raw PCM samples. 简易列表常用.wav(RIFF)文件格式在原始PCM样本前面仅具有一个44字节的标头。 So, for these simple types of .wav files, you could just try reading the files as raw bytes, removing the 44 byte header from all but the first file, and concatening the samples. 因此,对于这些简单类型的.wav文件,您可以尝试将文件读取为原始字节,从第一个文件中删除所有文件中的44字节的标头,然后连接示例。 Or just play the concatenated samples directly using the Audio Queue API. 或者只是直接使用Audio Queue API播放串联的样本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM