Skip to content

Commit 98ae6ce

Browse files
committed
Fix up config, update speech effects to be more dynamic and better detected
1 parent 31ca984 commit 98ae6ce

18 files changed

Lines changed: 627 additions & 359 deletions

pom.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,17 @@
9090
<artifactId>logback-classic</artifactId>
9191
<version>1.5.16</version>
9292
</dependency>
93-
94-
93+
<dependency>
94+
<groupId>org.jetbrains</groupId>
95+
<artifactId>annotations</artifactId>
96+
<version>26.0.2</version>
97+
<scope>compile</scope>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.yaml</groupId>
101+
<artifactId>snakeyaml</artifactId>
102+
<version>2.4</version>
103+
</dependency>
95104
</dependencies>
96105

97-
</project>
106+
</project>

src/main/java/simplexity/Main.java

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,25 @@
44
import org.slf4j.LoggerFactory;
55
import org.slf4j.event.Level;
66
import simplexity.amazon.PollyHandler;
7+
import simplexity.amazon.PollySetup;
78
import simplexity.amazon.SpeechHandler;
89
import simplexity.commands.CommandManager;
910
import simplexity.commands.ExitCommand;
1011
import simplexity.commands.HelpCommand;
1112
import simplexity.commands.ReloadCommand;
12-
import simplexity.config.AbstractConfig;
13-
import simplexity.config.config.AwsConfig;
14-
import simplexity.config.config.ReplaceTextConfig;
15-
import simplexity.config.config.TtsConfig;
16-
import simplexity.config.locale.LocaleConfig;
13+
import simplexity.config.config.ConfigHandler;
14+
import simplexity.config.config.YmlConfig;
1715
import simplexity.httpserver.LocalServer;
18-
import simplexity.amazon.PollySetup;
1916
import simplexity.util.Logging;
2017

21-
import java.util.ArrayList;
18+
import java.io.File;
19+
import java.io.IOException;
2220
import java.util.Scanner;
2321

2422
public class Main {
2523
private static final Logger logger = LoggerFactory.getLogger(Main.class);
24+
private static YmlConfig ymlConfig;
2625
private static CommandManager commandManager;
27-
private static final ArrayList<AbstractConfig> configs = new ArrayList<>();
2826
public static PollyHandler pollyHandler;
2927
private static SpeechHandler speechHandler;
3028
public static Scanner scanner;
@@ -35,7 +33,15 @@ public static void main(String[] args) {
3533
scanner = new Scanner(System.in);
3634
commandManager = new CommandManager();
3735
registerCommands(commandManager);
38-
setupConfigs();
36+
File file = new File("config/config.yml");
37+
try {
38+
ymlConfig = new YmlConfig(file, "config.yml");
39+
} catch (IOException e) {
40+
System.out.println("Fatal Error: Config was unable to be generated.");
41+
e.printStackTrace();
42+
return;
43+
}
44+
ConfigHandler.getInstance().reloadValues(ymlConfig);
3945
PollySetup.setupPollyAndSpeech();
4046
LocalServer.run();
4147
while (runApp) {
@@ -52,17 +58,6 @@ private static void registerCommands(CommandManager commandManager) {
5258
commandManager.registerCommand(new ReloadCommand("--reload", "Reloads the configuration"));
5359
}
5460

55-
private static void setupConfigs(){
56-
AwsConfig awsConfig = new AwsConfig();
57-
configs.add(awsConfig);
58-
TtsConfig ttsConfig = new TtsConfig();
59-
configs.add(ttsConfig);
60-
ReplaceTextConfig replaceTextConfig = new ReplaceTextConfig();
61-
configs.add(replaceTextConfig);
62-
LocaleConfig localeConfig = new LocaleConfig();
63-
configs.add(localeConfig);
64-
}
65-
6661
public static CommandManager getCommandManager() {
6762
return commandManager;
6863
}
@@ -71,20 +66,20 @@ public static PollyHandler getPollyHandler() {
7166
return pollyHandler;
7267
}
7368

74-
public static void setSpeechHandler(SpeechHandler speechHandlerToSet){
69+
public static void setSpeechHandler(SpeechHandler speechHandlerToSet) {
7570
speechHandler = speechHandlerToSet;
7671
}
7772

78-
public static void setPollyHandler(PollyHandler pollyHandlerToSet){
73+
public static void setPollyHandler(PollyHandler pollyHandlerToSet) {
7974
pollyHandler = pollyHandlerToSet;
8075
}
8176

82-
public static Scanner getScanner(){
77+
public static Scanner getScanner() {
8378
return scanner;
8479
}
8580

86-
public static ArrayList<AbstractConfig> getConfigs() {
87-
return configs;
81+
public static YmlConfig getYmlConfig(){
82+
return ymlConfig;
8883
}
8984

90-
}
85+
}

src/main/java/simplexity/amazon/PollySetup.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import org.slf4j.LoggerFactory;
66
import org.slf4j.event.Level;
77
import simplexity.Main;
8-
import simplexity.config.config.AwsConfig;
9-
import simplexity.config.config.TtsConfig;
8+
import simplexity.config.config.ConfigHandler;
109
import simplexity.config.locale.Message;
1110
import simplexity.util.Logging;
1211

@@ -16,15 +15,16 @@ public class PollySetup {
1615
private static final Logger logger = LoggerFactory.getLogger(PollySetup.class);
1716
private static final Scanner scanner = Main.getScanner();
1817

19-
public static void setupPollyAndSpeech(){
18+
public static void setupPollyAndSpeech() {
2019
connectToPolly();
2120
Main.setSpeechHandler(new SpeechHandler());
2221
}
22+
2323
public static PollyHandler createPollyHandler() {
2424
PollyHandler pollyHandler = null;
25-
String awsAccessID = AwsConfig.getInstance().getAwsAccessID();
26-
String awsSecretKey = AwsConfig.getInstance().getAwsSecretKey();
27-
Region awsRegion = AwsConfig.getInstance().getAwsRegion();
25+
String awsAccessID = ConfigHandler.getInstance().getAwsAccessID();
26+
String awsSecretKey = ConfigHandler.getInstance().getAwsSecretKey();
27+
Region awsRegion = ConfigHandler.getInstance().getAwsRegion();
2828
if (awsAccessID.isEmpty() || awsSecretKey.isEmpty() || awsRegion == null) {
2929
System.out.println(Message.NULL_AWS_CREDENTIALS);
3030
return null;
@@ -37,15 +37,15 @@ public static PollyHandler createPollyHandler() {
3737
return pollyHandler;
3838
}
3939

40-
public static void connectToPolly(){
40+
public static void connectToPolly() {
4141
while (true) {
4242
Main.setPollyHandler(createPollyHandler());
4343
if (Main.getPollyHandler() != null) {
4444
return;
4545
}
4646
Logging.logAndPrint(logger, Message.PLEASE_SAVE_AWS_INFO_IN_CONFIG.getMessage(), Level.INFO);
4747
scanner.nextLine();
48-
TtsConfig.getInstance().reloadConfig();
48+
ConfigHandler.getInstance().reloadValues(Main.getYmlConfig());
4949
if (Main.getPollyHandler() != null) {
5050
return;
5151
}

src/main/java/simplexity/amazon/SpeechHandler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import org.slf4j.LoggerFactory;
1212
import org.slf4j.event.Level;
1313
import simplexity.Main;
14-
import simplexity.config.config.AwsConfig;
15-
import simplexity.config.config.ReplaceTextConfig;
14+
import simplexity.config.config.ConfigHandler;
15+
import simplexity.config.config.SpeechEffectRule;
1616
import simplexity.config.locale.Message;
1717
import simplexity.util.Logging;
1818

@@ -23,7 +23,7 @@ public class SpeechHandler {
2323
private VoiceId voiceId;
2424

2525
public SpeechHandler() {
26-
this.voiceId = AwsConfig.getInstance().getDefaultVoice();
26+
this.voiceId = ConfigHandler.getInstance().getDefaultVoice();
2727
Logging.log(logger, "Initialized SpeechHandler with default voice: " + voiceId.toString(), Level.INFO);
2828
}
2929

@@ -57,13 +57,13 @@ public void processSpeech(String text) {
5757
*/
5858

5959
public String replaceText(String text) {
60-
for (String key : ReplaceTextConfig.getInstance().getReplaceText().keySet()) {
61-
text = text.replace(key, ReplaceTextConfig.getInstance().getReplaceText().get(key));
60+
for (SpeechEffectRule effectRule : ConfigHandler.getInstance().getEffectRules()) {
61+
text = effectRule.applyRule(text);
6262
}
63-
for (String key : AwsConfig.getInstance().getVoicePrefixes().keySet()) {
63+
for (String key : ConfigHandler.getInstance().getVoicePrefixes().keySet()) {
6464
if (text.startsWith(key)) {
6565
text = text.replace(key, "");
66-
voiceId = AwsConfig.getInstance().getVoicePrefixes().get(key);
66+
voiceId = ConfigHandler.getInstance().getVoicePrefixes().get(key);
6767
}
6868
}
6969
return text;

src/main/java/simplexity/commands/ReloadCommand.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,34 @@
44
import org.slf4j.LoggerFactory;
55
import org.slf4j.event.Level;
66
import simplexity.Main;
7-
import simplexity.config.AbstractConfig;
87
import simplexity.config.locale.Message;
98
import simplexity.httpserver.LocalServer;
109
import simplexity.util.Logging;
1110

12-
import java.util.ArrayList;
11+
import java.io.IOException;
1312

1413
public class ReloadCommand extends Command {
1514

1615
private static final Logger logger = LoggerFactory.getLogger(ReloadCommand.class);
16+
1717
public ReloadCommand(String name, String usage) {
1818
super(name, usage);
1919
}
2020

2121
@Override
2222
public void execute() {
2323
Logging.log(logger, "Reloading configs", Level.INFO);
24-
reloadConfigs();
24+
try {
25+
Main.getYmlConfig().reloadConfig();
26+
} catch (IOException e) {
27+
Logging.logAndPrint(logger, "Fatal Error Reloading Config Files", Level.WARN);
28+
Logging.logAndPrint(logger, e.getStackTrace().toString(), Level.WARN);
29+
System.exit(-1);
30+
}
2531
Logging.log(logger, "Stopping local server", Level.INFO);
2632
LocalServer.stop();
2733
Logging.log(logger, "Starting local server", Level.INFO);
2834
LocalServer.run();
2935
Logging.logAndPrint(logger, Message.RELOAD_MESSAGE.getMessage(), Level.ERROR);
3036
}
31-
32-
private void reloadConfigs() {
33-
ArrayList<AbstractConfig> configs = Main.getConfigs();
34-
for (AbstractConfig config : configs) {
35-
config.reloadConfig();
36-
}
37-
}
3837
}

src/main/java/simplexity/config/config/AwsConfig.java

Lines changed: 0 additions & 138 deletions
This file was deleted.

0 commit comments

Comments
 (0)