Skip to content

Commit 6be04a2

Browse files
committed
Make locale
1 parent 734c32f commit 6be04a2

20 files changed

Lines changed: 209 additions & 179 deletions

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>simplexity</groupId>
88
<artifactId>CLI-TTS</artifactId>
9-
<version>1.0.0</version>
9+
<version>2.0.0</version>
1010
<packaging>jar</packaging>
1111

1212
<properties>
@@ -88,7 +88,7 @@
8888
<dependency>
8989
<groupId>ch.qos.logback</groupId>
9090
<artifactId>logback-classic</artifactId>
91-
<version>1.5.6</version>
91+
<version>1.5.16</version>
9292
</dependency>
9393

9494

src/main/java/simplexity/Main.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,31 @@
1313
import simplexity.config.config.AwsConfig;
1414
import simplexity.config.config.ReplaceTextConfig;
1515
import simplexity.config.config.TTSConfig;
16+
import simplexity.config.locale.LocaleConfig;
1617
import simplexity.httpserver.LocalServer;
17-
import simplexity.setup.PollySetup;
18-
import simplexity.util.ColorTags;
19-
import simplexity.util.Util;
18+
import simplexity.amazon.PollySetup;
19+
import simplexity.util.Logging;
2020

2121
import java.util.ArrayList;
2222
import java.util.Scanner;
2323

2424
public class Main {
2525
private static final Logger logger = LoggerFactory.getLogger(Main.class);
2626
private static CommandManager commandManager;
27-
private static ArrayList<AbstractConfig> configs = new ArrayList<>();
27+
private static final ArrayList<AbstractConfig> configs = new ArrayList<>();
2828
public static PollyHandler pollyHandler;
2929
private static SpeechHandler speechHandler;
3030
public static Scanner scanner;
3131
public static boolean runApp = true;
3232

3333
public static void main(String[] args) {
34-
Util.log(logger, "Starting application", Level.INFO);
34+
Logging.log(logger, "Starting application", Level.INFO);
3535
scanner = new Scanner(System.in);
3636
commandManager = new CommandManager();
3737
registerCommands(commandManager);
3838
setupConfigs();
3939
PollySetup.setupPollyAndSpeech();
4040
LocalServer.run();
41-
System.out.println(ColorTags.parse("<red>TEST</red> <bold> THIS IS A TEST</bold>"));
4241
while (runApp) {
4342
String input = scanner.nextLine();
4443
if (!commandManager.runCommand(input)) {
@@ -60,6 +59,8 @@ private static void setupConfigs(){
6059
configs.add(ttsConfig);
6160
ReplaceTextConfig replaceTextConfig = new ReplaceTextConfig();
6261
configs.add(replaceTextConfig);
62+
LocaleConfig localeConfig = new LocaleConfig();
63+
configs.add(localeConfig);
6364
}
6465

6566
public static CommandManager getCommandManager() {
@@ -82,4 +83,8 @@ public static Scanner getScanner(){
8283
return scanner;
8384
}
8485

86+
public static ArrayList<AbstractConfig> getConfigs() {
87+
return configs;
88+
}
89+
8590
}

src/main/java/simplexity/setup/PollySetup.java renamed to src/main/java/simplexity/amazon/PollySetup.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
package simplexity.setup;
1+
package simplexity.amazon;
22

33
import com.amazonaws.regions.Region;
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
66
import org.slf4j.event.Level;
77
import simplexity.Main;
8-
import simplexity.amazon.PollyHandler;
9-
import simplexity.amazon.SpeechHandler;
108
import simplexity.config.config.AwsConfig;
119
import simplexity.config.config.TTSConfig;
12-
import simplexity.messages.Errors;
13-
import simplexity.messages.Output;
14-
import simplexity.util.Util;
10+
import simplexity.config.locale.Message;
11+
import simplexity.util.Logging;
1512

1613
import java.util.Scanner;
1714

@@ -29,13 +26,13 @@ public static PollyHandler createPollyHandler() {
2926
String awsSecretKey = AwsConfig.getInstance().getAwsSecretKey();
3027
Region awsRegion = AwsConfig.getInstance().getAwsRegion();
3128
if (awsAccessID.isEmpty() || awsSecretKey.isEmpty() || awsRegion == null) {
32-
System.out.println(Errors.NULL_AWS_CREDENTIALS);
29+
System.out.println(Message.NULL_AWS_CREDENTIALS);
3330
return null;
3431
}
3532
try {
3633
pollyHandler = new PollyHandler(awsAccessID, awsSecretKey, awsRegion);
3734
} catch (IllegalArgumentException e) {
38-
System.out.println(Errors.NULL_AWS_CREDENTIALS);
35+
System.out.println(Message.NULL_AWS_CREDENTIALS);
3936
}
4037
return pollyHandler;
4138
}
@@ -46,7 +43,7 @@ public static void connectToPolly(){
4643
if (Main.getPollyHandler() != null) {
4744
return;
4845
}
49-
Util.logAndPrint(logger, Output.PLEASE_SAVE_AWS_INFO_IN_CONFIG, Level.INFO);
46+
Logging.logAndPrint(logger, Message.PLEASE_SAVE_AWS_INFO_IN_CONFIG.getMessage(), Level.INFO);
5047
scanner.nextLine();
5148
TTSConfig.getInstance().reloadConfig();
5249
if (Main.getPollyHandler() != null) {

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import simplexity.config.config.AwsConfig;
1515
import simplexity.config.config.ReplaceTextConfig;
1616
import simplexity.config.config.TTSConfig;
17-
import simplexity.messages.Errors;
18-
import simplexity.util.Util;
17+
import simplexity.config.locale.Message;
18+
import simplexity.util.Logging;
1919

2020
import java.io.InputStream;
2121

@@ -25,7 +25,7 @@ public class SpeechHandler {
2525

2626
public SpeechHandler() {
2727
this.voiceId = AwsConfig.getInstance().getDefaultVoice();
28-
Util.log(logger, "Initialized SpeechHandler with default voice: " + voiceId.toString(), Level.INFO);
28+
Logging.log(logger, "Initialized SpeechHandler with default voice: " + voiceId.toString(), Level.INFO);
2929
}
3030

3131
/**
@@ -45,7 +45,7 @@ public void processSpeech(String text) {
4545
speechStream = synthesizeSpeech(processedText, voiceId);
4646
}
4747
if (speechStream == null) {
48-
Util.logAndPrint(logger, Errors.CAUGHT_EXCEPTION.replace("%error%", "Speech stream is null"), Level.ERROR);
48+
Logging.logAndPrint(logger, Message.GENERAL_ERROR.getMessage().replace("%error%", "Speech stream is null"), Level.ERROR);
4949
return;
5050
}
5151

@@ -58,7 +58,6 @@ public void processSpeech(String text) {
5858
*/
5959

6060
public String replaceText(String text) {
61-
TTSConfig ttsConfig = TTSConfig.getInstance();
6261
for (String key : ReplaceTextConfig.getInstance().getReplaceText().keySet()) {
6362
text = text.replace(key, ReplaceTextConfig.getInstance().getReplaceText().get(key));
6463
}
@@ -103,23 +102,22 @@ public InputStream synthesizeSpeech(String text, VoiceId voice) {
103102

104103
/**
105104
* Plays the text as speech
106-
*
107105
*/
108106
public void playSpeech(InputStream speechStream) {
109107
AdvancedPlayer player;
110108
try {
111109
player = new AdvancedPlayer(speechStream, FactoryRegistry.systemRegistry().createAudioDevice());
112110
player.play();
113111
} catch (Exception exception) {
114-
Util.logAndPrint(logger, Errors.CAUGHT_EXCEPTION.replace("%error%", exception.getMessage()), Level.ERROR);
112+
Logging.logAndPrint(logger, Message.GENERAL_ERROR.getMessage().replace("%error%", exception.getMessage()), Level.ERROR);
115113
}
116114
}
117115

118116
/**
119117
* Logs errors during speech synthesis.
120118
*/
121119
private void logSynthesisError(Exception e, String text) {
122-
Util.logAndPrint(logger, Errors.CAUGHT_EXCEPTION.replace("%error%", e.getMessage()), Level.ERROR);
123-
Util.logAndPrint(logger, Errors.MESSAGE_NOT_PARSABLE.replace("%message%", text), Level.ERROR);
120+
Logging.logAndPrint(logger, Message.GENERAL_ERROR.getMessage().replace("%error%", e.getMessage()), Level.ERROR);
121+
Logging.logAndPrint(logger, Message.MESSAGE_NOT_PARSABLE.getMessage().replace("%message%", text), Level.ERROR);
124122
}
125123
}

src/main/java/simplexity/commands/Command.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ public Command(String name, String usage) {
1717

1818
public abstract void execute();
1919

20-
public String getDescription(){
20+
public String getDescription() {
2121
return description;
2222
}
23-
public String getName(){
23+
24+
public String getName() {
2425
return name;
2526
}
2627
}

src/main/java/simplexity/commands/CommandManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55
import org.slf4j.event.Level;
6-
import simplexity.messages.Errors;
7-
import simplexity.util.Util;
6+
import simplexity.config.locale.Message;
7+
import simplexity.util.Logging;
88

99
import java.util.HashMap;
1010

@@ -13,13 +13,13 @@ public class CommandManager {
1313
private static final Logger logger = LoggerFactory.getLogger(CommandManager.class);
1414

1515
public void registerCommand(Command command) {
16-
Util.log(logger, "Registering command: " + command.name, Level.INFO);
16+
Logging.log(logger, "Registering command: " + command.name, Level.INFO);
1717
commands.put(command.getName(), command);
1818
}
1919

2020
public boolean runCommand(String command) {
2121
if (command.startsWith("--") && !commands.containsKey(command)) {
22-
Util.logAndPrint(logger, Errors.UNKNOWN_COMMAND.replace("%command%", command), Level.ERROR);
22+
Logging.logAndPrint(logger, Message.UNKNOWN_COMMAND.getMessage().replace("%command%", command), Level.ERROR);
2323
return true;
2424
}
2525
if (!commands.containsKey(command)){

src/main/java/simplexity/commands/ExitCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import org.slf4j.event.Level;
44
import simplexity.Main;
5+
import simplexity.config.locale.Message;
56
import simplexity.httpserver.LocalServer;
6-
import simplexity.messages.Output;
7-
import simplexity.util.Util;
7+
import simplexity.util.Logging;
88

99
public class ExitCommand extends Command {
1010

@@ -14,7 +14,7 @@ public ExitCommand(String name, String usage) {
1414

1515
@Override
1616
public void execute() {
17-
Util.logAndPrint(logger, Output.SHUTTING_DOWN, Level.INFO);
17+
Logging.logAndPrint(logger, Message.SHUTTING_DOWN.getMessage(), Level.INFO);
1818
Main.runApp = false;
1919
LocalServer.stop();
2020
System.exit(0);
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
package simplexity.commands;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.slf4j.event.Level;
36
import simplexity.Main;
4-
import simplexity.messages.Output;
7+
import simplexity.config.locale.Message;
8+
import simplexity.util.Logging;
9+
10+
public class HelpCommand extends Command {
11+
private static final Logger logger = LoggerFactory.getLogger(HelpCommand.class);
512

6-
public class HelpCommand extends Command{
713
public HelpCommand(String name, String usage) {
814
super(name, usage);
915
}
1016

1117
@Override
1218
public void execute() {
13-
System.out.println(Output.HELP_HEADER);
19+
Logging.logAndPrint(logger, Message.HELP_HEADER.getMessage(), Level.INFO);
1420
for (Command command : Main.getCommandManager().getCommands().values()) {
15-
System.out.println(Output.HELP_COMMAND_MESSAGE.replace("%command_name%", command.getName())
16-
.replace("%command_description%", command.getDescription()));
21+
String commandHelpMessage = Message.HELP_COMMAND_MESSAGE.getMessage().replace("%command_name%", command.getName())
22+
.replace("%command_description%", command.getDescription());
23+
Logging.logAndPrint(logger, commandHelpMessage, Level.INFO);
1724
}
1825
}
1926
}
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
package simplexity.commands;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
35
import org.slf4j.event.Level;
4-
import simplexity.config.config.TTSConfig;
6+
import simplexity.Main;
7+
import simplexity.config.AbstractConfig;
8+
import simplexity.config.locale.Message;
59
import simplexity.httpserver.LocalServer;
6-
import simplexity.messages.Output;
7-
import simplexity.util.Util;
10+
import simplexity.util.Logging;
11+
12+
import java.util.ArrayList;
813

914
public class ReloadCommand extends Command {
15+
16+
private static final Logger logger = LoggerFactory.getLogger(ReloadCommand.class);
1017
public ReloadCommand(String name, String usage) {
1118
super(name, usage);
1219
}
1320

1421
@Override
1522
public void execute() {
16-
TTSConfig.getInstance().reloadConfig();
23+
Logging.log(logger, "Reloading configs", Level.INFO);
24+
reloadConfigs();
25+
Logging.log(logger, "Stopping local server", Level.INFO);
1726
LocalServer.stop();
27+
Logging.log(logger, "Starting local server", Level.INFO);
1828
LocalServer.run();
19-
Util.logAndPrint(logger, Output.RELOAD_MESSAGE, Level.ERROR);
29+
Logging.logAndPrint(logger, Message.RELOAD_MESSAGE.getMessage(), Level.ERROR);
30+
}
31+
32+
private void reloadConfigs() {
33+
ArrayList<AbstractConfig> configs = Main.getConfigs();
34+
for (AbstractConfig config : configs) {
35+
config.reloadConfig();
36+
}
2037
}
2138
}

src/main/java/simplexity/config/AbstractConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77
import org.slf4j.event.Level;
8-
import simplexity.util.Util;
8+
import simplexity.util.Logging;
99

1010
import java.io.File;
1111

@@ -19,28 +19,28 @@ public AbstractConfig(String configPath, String folderPath) {
1919
}
2020

2121
private void loadConfig(String configPath, String folderPath) {
22-
Util.log(logger, "Loading configuration from directory: " + folderPath + ", file:" + configPath, Level.INFO);
22+
Logging.log(logger, "Loading configuration from directory: " + folderPath + ", file:" + configPath, Level.INFO);
2323
File folder = checkForOrCreateFolder(folderPath);
2424
if (folder == null) {
25-
Util.logAndPrint(logger, "Unable to continue loading: " + configPath, Level.WARN);
25+
Logging.logAndPrint(logger, "Unable to continue loading: " + configPath, Level.WARN);
2626
}
2727
File configFile = new File(folder, configPath);
2828
if (!configFile.exists()) {
29-
Util.log(logger, "Config file does not exist: " + configPath, Level.INFO);
29+
Logging.log(logger, "Config file does not exist: " + configPath, Level.INFO);
3030
createDefaultConfig(configFile);
3131
}
3232
this.config = ConfigFactory.parseFile(configFile).resolve();
33-
Util.log(logger, "Loaded configuration from: " + configPath, Level.INFO);
33+
Logging.log(logger, "Loaded configuration from: " + configPath, Level.INFO);
3434
}
3535

3636
private File checkForOrCreateFolder(String folderPath) {
3737
File directory = new File(folderPath);
3838
if (!directory.exists()) {
3939
if (!directory.mkdirs()) {
40-
Util.logAndPrint(logger, "Failed to create directory: " + folderPath, Level.WARN);
40+
Logging.logAndPrint(logger, "Failed to create directory: " + folderPath, Level.WARN);
4141
return null;
4242
} else {
43-
Util.log(logger, "Successfully created directory: " + folderPath, Level.INFO);
43+
Logging.log(logger, "Successfully created directory: " + folderPath, Level.INFO);
4444
}
4545
}
4646
return directory;

0 commit comments

Comments
 (0)