Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8cf2c5e
Prepare for a Annuncitor based on SPI
shroffk Mar 11, 2024
c3016c8
Cleanup dependencies, freetts needed by impl of annunciator only
shroffk Mar 11, 2024
114eaa3
Create a new module for an annunciator based on freetts
shroffk Mar 11, 2024
fc0f8c7
Use the annunciator SPI
shroffk Mar 11, 2024
48f4e89
Add freetts annunciator as a optional dep to the common product
shroffk Mar 12, 2024
0edf629
Annunciator interface changes: Remove initialize, pass the entire msg
shroffk Mar 12, 2024
50a648a
Use the new Annunciator interface
shroffk Mar 12, 2024
9b99fee
Creating a new annunciator which plays audio files
shroffk Mar 15, 2024
430b8f4
Adding the new audio annunciator to the default product
shroffk Mar 15, 2024
c372093
fixing typos in the audio annunciator preferences
shroffk Mar 15, 2024
576472e
Add some documentation for the audio annunciator preferences
shroffk Mar 15, 2024
cceba59
Stop all annunciation sounds when closing the Annunciator
shroffk Mar 27, 2024
a57579a
Call the shutdown before the thread join
shroffk Mar 27, 2024
7bcc02c
Add a preference for the max duration of the alarm sound clip
shroffk Mar 28, 2024
f1d79c0
use the media player to handle longer audio files ( stop time, memory,
shroffk Mar 28, 2024
7274d62
Revert to the old cleanup/processor thread should be closed first
shroffk Mar 28, 2024
9560446
Trying to avoid parallel plays of the annunciator audio
shroffk Apr 2, 2024
cb5574a
Remove multiple Annunciator SPI impl, use tts for backward compatibility
shroffk Apr 11, 2024
f829f3d
Fixing the loading of SPI contributions for Annunciators
shroffk Apr 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/alarm/audio-annunciator/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/phoebus-target"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-framework"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-types"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-util"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-security"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-ui"/>
<classpathentry combineaccessrules="false" kind="src" path="/app-alarm-model"/>
<classpathentry combineaccessrules="false" kind="src" path="/app-alarm-ui"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
20 changes: 20 additions & 0 deletions app/alarm/audio-annunciator/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<project default="app-alarm-ui">
<import file="../../../dependencies/ant_settings.xml"/>

<target name="app-alarm-audio-annunciator">
<mkdir dir="${classes}"/>
<javac destdir="${classes}" debug="${debug}">
<src path="${src}"/>
<classpath>
<path refid="app-classpath"/>
<pathelement path="../model/${build}/app-alarm-ui-${version}.jar"/>
</classpath>
</javac>

<jar destfile="${build}/app-alarm-audio-annunciator-${version}.jar">
<fileset dir="${classes}"/>
<fileset dir="${resources}"/>
</jar>
</target>

</project>
31 changes: 31 additions & 0 deletions app/alarm/audio-annunciator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.phoebus</groupId>
<artifactId>app-alarm</artifactId>
<version>4.7.4-SNAPSHOT</version>
</parent>
<artifactId>app-alarm-audio-annunciator</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.phoebus</groupId>
<artifactId>app-alarm-ui</artifactId>
<version>4.7.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>${openjfx.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*******************************************************************************
* Copyright (c) 2018 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.phoebus.applications.alarm.audio.annunciator;

import javafx.scene.media.AudioClip;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.util.Duration;
import org.phoebus.applications.alarm.ui.annunciator.Annunciator;
import org.phoebus.applications.alarm.ui.annunciator.AnnunciatorMessage;

import java.util.List;

/**
* Annunciator class. Uses Audio files to annunciate passed messages.
*
* @author Kunal Shroff
*/
@SuppressWarnings("nls")
public class AudioAnnunciator implements Annunciator {
private final MediaPlayer alarmSound;
private final MediaPlayer minorAlarmSound;
private final MediaPlayer majorAlarmSound;
private final MediaPlayer invalidAlarmSound;
private final MediaPlayer undefinedAlarmSound;

/**
* Constructor
*/
public AudioAnnunciator() {
alarmSound = new MediaPlayer(new Media(Preferences.alarm_sound_url));
minorAlarmSound = new MediaPlayer(new Media(Preferences.minor_alarm_sound_url));
majorAlarmSound = new MediaPlayer(new Media(Preferences.major_alarm_sound_url));
invalidAlarmSound = new MediaPlayer(new Media(Preferences.invalid_alarm_sound_url));
undefinedAlarmSound = new MediaPlayer(new Media(Preferences.undefined_alarm_sound_url));
// configure the media players for the different alarm sounds
List.of(alarmSound, minorAlarmSound, majorAlarmSound, invalidAlarmSound, undefinedAlarmSound)
.forEach(sound -> {
sound.setStopTime(Duration.seconds(Preferences.max_alarm_duration));
sound.setVolume(Preferences.volume);
});
}

/**
* Annunciate the message.
*
* @param message Message text
*/
@Override
public void speak(final AnnunciatorMessage message) {
switch (message.severity) {
case MINOR -> speakAlone(minorAlarmSound);
case MAJOR -> speakAlone(majorAlarmSound);
case INVALID -> speakAlone(invalidAlarmSound);
case UNDEFINED -> speakAlone(undefinedAlarmSound);
default -> speakAlone(alarmSound);
}
}

synchronized private void speakAlone(MediaPlayer alarm) {
List.of(alarmSound, minorAlarmSound, majorAlarmSound, invalidAlarmSound, undefinedAlarmSound)
.forEach(sound -> {
sound.stop();
});
alarm.play();
}

/**
* Deallocates the voice.
*/
@Override
public void shutdown() {
List.of(alarmSound, minorAlarmSound, majorAlarmSound, invalidAlarmSound, undefinedAlarmSound)
.forEach(sound -> {
sound.stop();
sound.dispose();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2010-2022 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package org.phoebus.applications.alarm.audio.annunciator;


import org.phoebus.framework.preferences.AnnotatedPreferences;
import org.phoebus.framework.preferences.Preference;
import org.phoebus.framework.preferences.PreferencesReader;

/**
* Helper for reading preference settings
*
* @author Kunal Shroff
*/
@SuppressWarnings("nls")
public class Preferences {

/**
* Setting
*/
@Preference
public static String alarm_sound_url;
@Preference
public static String minor_alarm_sound_url;
@Preference
public static String major_alarm_sound_url;
@Preference
public static String invalid_alarm_sound_url;
@Preference
public static String undefined_alarm_sound_url;
@Preference
public static int volume;
@Preference
public static int max_alarm_duration;

static {
final PreferencesReader prefs = AnnotatedPreferences.initialize(AudioAnnunciator.class, Preferences.class, "/audio_annunciator_preferences.properties");
alarm_sound_url = useLocalResourceIfUnspecified(alarm_sound_url);
minor_alarm_sound_url = useLocalResourceIfUnspecified(minor_alarm_sound_url);
major_alarm_sound_url = useLocalResourceIfUnspecified(major_alarm_sound_url);
invalid_alarm_sound_url = useLocalResourceIfUnspecified(invalid_alarm_sound_url);
undefined_alarm_sound_url = useLocalResourceIfUnspecified(undefined_alarm_sound_url);
}

private static String useLocalResourceIfUnspecified(String alarmResource) {
if (alarmResource == null || alarmResource.isEmpty()) {
// If only the alarm sound url is set, in a case where we want to use the same alarm sound for all severties
if (!alarm_sound_url.isEmpty()) {
return alarm_sound_url;
} else {
return Preferences.class.getResource("/sounds/mixkit-classic-alarm-995.wav").toString();
}
} else {
return alarmResource;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.phoebus.applications.alarm.audio.annunciator.AudioAnnunciator
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ----------------------------------------
# Package org.phoebus.applications.alarm.audio.annunciator
# ----------------------------------------

# The audio annunciator will play the audio files specified for the associated alarm severity levels.
# Currently supported formats are AIFF and WAV files.
# examples of audio file URL's, they can be local or remote files.
# file:/C:/tmp/audio/AudioFileWithWavFormat.wav
# https://wavlist.com/wav/brass1.wav

# default alarm sound, if we don't want severity specific sounds only setting this one preference is enough
alarm_sound_url=

minor_alarm_sound_url=
major_alarm_sound_url=
invalid_alarm_sound_url=
undefined_alarm_sound_url=

# audio clip volume (0-100)
volume=100

# max alarm Duration in seconds.
max_alarm_duration=10
Binary file not shown.
21 changes: 21 additions & 0 deletions app/alarm/freetts-annunciator/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/phoebus-target"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-framework"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-types"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-util"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-security"/>
<classpathentry combineaccessrules="false" kind="src" path="/core-ui"/>
<classpathentry combineaccessrules="false" kind="src" path="/app-alarm-model"/>
<classpathentry combineaccessrules="false" kind="src" path="/app-alarm-ui"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
20 changes: 20 additions & 0 deletions app/alarm/freetts-annunciator/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<project default="app-alarm-ui">
<import file="../../../dependencies/ant_settings.xml"/>

<target name="app-alarm-freetts-annunciator">
<mkdir dir="${classes}"/>
<javac destdir="${classes}" debug="${debug}">
<src path="${src}"/>
<classpath>
<path refid="app-classpath"/>
<pathelement path="../model/${build}/app-alarm-ui-${version}.jar"/>
</classpath>
</javac>

<jar destfile="${build}/app-alarm-freetts-annunciator-${version}.jar">
<fileset dir="${classes}"/>
<fileset dir="${resources}"/>
</jar>
</target>

</project>
32 changes: 32 additions & 0 deletions app/alarm/freetts-annunciator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.phoebus</groupId>
<artifactId>app-alarm</artifactId>
<version>4.7.4-SNAPSHOT</version>
</parent>
<artifactId>app-alarm-freetts-annunciator</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>net.sf.sociaal</groupId>
<artifactId>freetts</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.phoebus</groupId>
<artifactId>app-alarm-ui</artifactId>
<version>4.7.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2018 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.phoebus.applications.alarm.freetts.annunciator;

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import org.phoebus.applications.alarm.ui.annunciator.Annunciator;
import org.phoebus.applications.alarm.ui.annunciator.AnnunciatorMessage;

/**
* Annunciator class. Uses freeTTS to annunciate passed messages.
* @author Evan Smith, Kunal Shroff
*/
@SuppressWarnings("nls")
public class FreeTTSAnnunciator implements Annunciator
{
private final VoiceManager voiceManager;
private final Voice voice;
private static final String voice_name = "kevin16";

/** Constructor */
public FreeTTSAnnunciator()
{
// Define the voices directory.
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice(voice_name);
voice.allocate();
}

/**
* Annunciate the message. Only returns once speaking finishes.
* @param message Message text
*/
@Override
public void speak(final AnnunciatorMessage message)
{
if (null != message)
voice.speak(message.message);
}

/**
* Deallocates the voice.
*/
@Override
public void shutdown()
{
voice.deallocate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.phoebus.applications.alarm.freetts.annunciator.FreeTTSAnnunciator
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package org.phoebus.applications.alarm;
package org.phoebus.applications.alarm.freetts.annunciator;

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
Expand Down
Loading