[英]How to generate quality WAVE file using Java
I am trying to generate a quality WAVE
file using the Java Sound API. 我正在尝试使用Java Sound API生成高质量的
WAVE
文件。
First I used the following values with 8kHz
sample rate. 首先,我使用以下值为
8kHz
采样率的值。 And the quality is 128kbps
. 质量为
128kbps
。 But it is not generating quality audio. 但是它不能产生高质量的音频。 Some words are even not clearly pronounced.
有些单词甚至没有清楚地发音。
static AudioFormat.Encoding defaultEncoding = AudioFormat.Encoding.PCM_SIGNED;
static float fDefaultSampleRate = 8000;
static int nDefaultSampleSizeInBits = 16;
static int nDefaultChannels = 1;
static int frameSize = 2;
static float frameRate = 8000;
static boolean bDefaultBigEndian = false;
AudioFormat defaultFormat = new AudioFormat(defaultEncoding, fDefaultSampleRate, nDefaultSampleSizeInBits, nDefaultChannels, frameSize, frameRate, bDefaultBigEndian);
AudioInputStream GeneratedAudio = marytts.generateAudio(text); //generate audio from text
AudioInputStream audio = AudioSystem.getAudioInputStream(defaultFormat, GeneratedAudio);
AudioSystem.write(audio, AudioFileFormat.Type.WAVE, new File("FileName.wav"));
So then I used the following values with 44.1kHz
sample rate. 因此,我在
44.1kHz
采样率下使用了以下值。 Also showing the quality as 705kbps
But the problem is when I generate audio with these values the generated audio is quality but there are some noises like cracking when playing the audio. 还显示质量为
705kbps
但是问题是,当我使用这些值生成音频时,生成的音频就是质量,但是在播放音频时会出现诸如开裂的噪音。
static AudioFormat.Encoding defaultEncoding = AudioFormat.Encoding.PCM_SIGNED;
static float fDefaultSampleRate = 44100;
static int nDefaultSampleSizeInBits = 16;
static int nDefaultChannels = 1;
static int frameSize = 2;
static float frameRate = 44100;
static boolean bDefaultBigEndian = false;
AudioFormat defaultFormat = new AudioFormat(defaultEncoding, fDefaultSampleRate, nDefaultSampleSizeInBits, nDefaultChannels, frameSize, frameRate, bDefaultBigEndian);
AudioInputStream GeneratedAudio = marytts.generateAudio(text); //generate audio from text
AudioInputStream audio = AudioSystem.getAudioInputStream(defaultFormat, GeneratedAudio);
AudioSystem.write(audio, AudioFileFormat.Type.WAVE, new File("FileName.wav"));
So what I need to know is how can I generate quality audio without having some cracking background noises using this Java sound
API? 因此,我需要知道的是,使用此
Java sound
API时,如何在不产生背景噪音的情况下生成高质量的音频? I am very grateful for any help. 我非常感谢您的帮助。 Thanks in advance.
提前致谢。
There are a number of things that could result in crackling: from over-driving the speakers, to overflowing the number of bits to overly large discontinuities in the data. 可能会导致crack啪作响的原因很多:从扬声器的过度驱动到位数的溢出到数据中的不连续性过大。
For 16-bit encoding (standard for "CD Quality audio"), all your PCM data points should lie within the range -32767 to 32767 (fits in a short
) prior to conversion of the PCM values to bytes. 对于16位编码(“ CD质量音频”的标准),在将PCM值转换为字节之前,所有PCM数据点都应在-32767至32767范围内(
short
)。
If they do, then I would look next to make sure I had the byte order correct, and at the algorithm that is producing the PCM values. 如果是这样,那么我接下来将确保我的字节顺序正确无误,并查看生成PCM值的算法。 IDK what to recommend for testing that besides inspection.
IDK除了检查外还建议测试什么。 Maybe try generating a simple sine wave at various volumes and see if the PCM values are as expected, for starters?
也许尝试在各种音量下生成一个简单的正弦波,看看对于初学者来说PCM值是否符合预期?
16-bit, mono, at 44100 fps should sound pretty good. 16位单声道,44100 fps听起来应该不错。 Any chance what you are describing as crackle might be a form of aliasing?
您所描述的le啪声有可能是混叠的一种形式吗? (I don't usually think of that form of distortion as a crackle.)
(我通常不认为这种失真形式是裂纹。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.