javaaudiobluetoothraspberry-pifreetts

FreeTTS voice no output Raspberry PI bluetooth speaker


Have a simple program running on Raspberry PI. When hooked up to monitor with speakers I can get the voice speaking through the HDMI speakers. However, I want the voice to output through bluetooth speakers. The connected bluetooth speakers play when I play some audio files, but when I run FreeTTS program the sound outputs either through HDMI audio or when headless and connected only to bluetooth speakers, there is no output at all. I'm thinking maybe it's trying to play through some default audio, since it plays through HDMI speakers even with bluetooth selected in audio menu... Here's the basic code I started with.

Voice voice;
VoiceManager voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice(voiceName);
voice.allocate();
voice.speak(text);

I've been trying additions, but nothing has worked so far. I was thinking I maybe needed to connect an AudioPlayer of some sort, but I couldn't get the default streaming one working. I need the audio played immediately. Any thoughts?


Solution

  • Turned out it wasn't really a programming issue, just configuration. I needed to have sound.properties setup for Java to use ALSA sound I guess. Once they were set, FreeTTS output to the correct audio as expected (in my case to a bluetooth speaker).

    javax.sound.sampled.Clip=com.sun.media.sound.DirectAudioDeviceProvider
    javax.sound.sampled.Port=com.sun.media.sound.PortMixerProvider
    javax.sound.sampled.SourceDataLine=com.sun.media.sound.DirectAudioDeviceProvider
    javax.sound.sampled.TargetDataLine=com.sun.media.sound.DirectAudioDeviceProvider
    

    Just put that in your sound.properties file (Somewhere in jdk/jvm folder: find / -name sound.properties). Should already be stubbed out in existing file, if not just throw it in there.

    Since I was using bluetooth and needed to do some mixing, I eventually started using pulseaudio as well which led to other difficulties, but this still applied to getting Java sound working in that case as well.