音频音量控制在Java中(增加或减少) [英] Audio volume control (increase or decrease) in Java

查看:1289
本文介绍了音频音量控制在Java中(增加或减少)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何提高使用Java传出WAV音频流的音量?我在使用各种Java TTS引擎和语音合成的输出音量的问题。有没有一个API调用或斗hickey.jar我可以用它来调节音量?

How do I increase the volume of an outgoing wav audio stream using Java? I'm having issues with various Java TTS engines and the output volume of the synthesized speech. Is there an API call or a doo-hickey.jar I can use to pump up the volume?

推荐答案

如果您正在使用Java API的声音,你可以用<一个音量href=\"http://java.sun.com/javase/6/docs/api/javax/sound/sampled/FloatControl.Type.html#MASTER%5FGAIN\">MASTER_GAIN控制。

If you're using the Java Sound API, you can set the volume with the MASTER_GAIN control.

import javax.sound.sampled.*;

AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(
    new File("some_file.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
FloatControl gainControl = 
    (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(-10.0f); // Reduce volume by 10 decibels.
clip.start();

这篇关于音频音量控制在Java中(增加或减少)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆