首页 > 解决方案 > 如何在树莓派板上使用 java sound api?

问题描述

我在 Raspberry pi board 中使用下面的语音识别器代码。为了传输文件,我将jar文件从 eclipse 导出到 raspberry pi board。

Jar 文件在 Windows 环境中正常工作,但不适用于 Rasbian OS。windows end rasbian 中的 Java 版本是1.8.0_211

Rasbian 见 usb 麦克风。(使用 pulseaudio 音量控制)

错误信息:

CLI 中无法使用麦克风”有什么问题?

代码:

/*
 * Starting a Thread that checks if the resources needed to the 
 * SpeechRecognition library are available
 */

public void startResourcesThread() {

    //Check lock
    if (resourcesThreadRunning)
        logger.log(Level.INFO, "Resources Thread already running...\n");
    else
        //Submit to ExecutorService
        eventsExecutorService.submit(() -> {
            try {

                //Lock
                resourcesThreadRunning = true;

                // Detect if the microphone is available
                while (true) {

                    //Is the Microphone Available
                    if (!AudioSystem.isLineSupported(Port.Info.MICROPHONE))
                        logger.log(Level.INFO, "Microphone is not available.\n");

                    // Sleep some period
                    Thread.sleep(350);
                }

            } catch (InterruptedException ex) {
                logger.log(Level.WARNING, null, ex);
                resourcesThreadRunning = false;
            }
        });
}

标签: javaraspberry-pimicrophone

解决方案


推荐阅读