录音时出现问题

发布于 2024-11-11 17:30:53 字数 628 浏览 7 评论 0原文

我有一个程序,首先播放:“请说出你的名字”。然后它会记录该名称。

我的部分代码是:

try {
    AudioInputStream audio = AudioSystem.getAudioInputStream(new File("sth.wav"));
    Clip clip = AudioSystem.getClip();
    clip.open(audio);
    clip.start();
}
catch(UnsupportedAudioFileException uae) {
    System.out.println(uae);
}
catch(IOException ioe) {
    System.out.println(ioe);
}
catch(LineUnavailableException lua) {
    System.out.println(lua);
}

r.captureAudio();

这里 r 是主类的一个实例。

问题是录音是这样的:
它首先播放“请输入您的名字”,然后播放我用麦克风录制的内容。


我是一个初学者,对 Java 没有太多经验。

我应该进行哪些更改,以便录音仅包含麦克风输入而不是“请输入您的姓名”?

I have a program that first plays: "please say your name". It then records the name.

Part of my code is:

try {
    AudioInputStream audio = AudioSystem.getAudioInputStream(new File("sth.wav"));
    Clip clip = AudioSystem.getClip();
    clip.open(audio);
    clip.start();
}
catch(UnsupportedAudioFileException uae) {
    System.out.println(uae);
}
catch(IOException ioe) {
    System.out.println(ioe);
}
catch(LineUnavailableException lua) {
    System.out.println(lua);
}

r.captureAudio();

Here r is an instance of the main class.

The problem is that the recording goes like this:
It first plays "please enter your name" and then plays what I record with mic.


I am a beginner and don't have much experience with Java.

What changes should I make so that the recording contains only the microphone input and not "please enter your name"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哎呦我呸! 2024-11-18 17:30:53

我不确定我完全理解你的问题。

弹出 JOptionPane(或模态 JDialog)将阻止 GUI,直到关闭为止。

如果你弹出一个说“开始录制”,关闭后直接开始录制并弹出一个新的“停止录制”,第二个将停止其余的程序语句(但不会停止录制本身,只要它是在线程中完成的)。

I am not sure I completely understand your question.

Popping a JOptionPane (or modal JDialog) will block the GUI until dismissed.

If you pop one to say 'start recording', start the recording directly after that is closed and pop a new one with 'stop recording', the second will stop the rest of the program statements (but not the recording itself, as long as it is done in a Thread).

深海少女心 2024-11-18 17:30:53

尝试调用clip.drain(),这将阻塞当前线程,直到剪辑播放完毕。之后就可以开始捕捉了。

Try calling clip.drain(), this will block current thread until the clip has finished playing. After that you can start capturing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文