Skip to content

Commit 6d0965f

Browse files
committed
rename packages, update README
1 parent 5bfb1a7 commit 6d0965f

File tree

17 files changed

+150
-117
lines changed

17 files changed

+150
-117
lines changed

README.md

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
# Command Line TTS
2-
I will keep on accidentally referring to it as CLI TTS - so I just named the repo that to get it out of the way
3-
4-
This is a basic Command Line based Text-To-Speech application.
5-
This application interfaces with Amazon Polly, and requires the use of standard voices.
6-
It has the ability to use [SSML](https://docs.aws.amazon.com/polly/latest/dg/supportedtags.html) (Speech Synthesis
7-
Markup Language), and the configuration has the ability to set up text to replace.
8-
9-
## Replace Text
10-
11-
The replace text section of the configuration allows you to set specific strings that will be replaced by other strings.
12-
This can be very useful for when you want to use SSML and set a shorthand for the beginning tag and ending tag.
13-
This can also be useful for having 'macros'/'commands' with different responses
14-
15-
> **Note**:
16-
> <br>It is advised to only replace specific combinations of characters, and not common combinations/single characters
17-
> <br>For example don't replace `"e"` with `"𝔼"` otherwise the tag `"__"` will break because it will now
18-
> be `<𝔼mphasis l𝔼v𝔼l=\"strong\">` instead of `<emphasis level=\"strong\">`
19-
> <br>You can mitigate this issue by surrounding the letter with a space like this: `" e "`
20-
21-
## Voice Prefixes
22-
23-
The voice prefixes section allows you to set a prefix that will switch the voice to a specific Polly voice.
24-
Then, if you use that prefix at the beginning of a message, the application will switch to that voice until another
25-
prefix is used.
1+
# Console Text To Speech
2+
This program is meant to be an intuitive text-to-speech program that runs on command line.
3+
This was made with streamers who struggle speaking in mind - but is open to use for many other things.
4+
This uses SSML - and uses markdown-esque formatting for the effects.
265

276
### AWS
287
Using this requires an AWS account - https://aws.amazon.com/
@@ -34,47 +13,80 @@ References:
3413
- [Amazon Polly Description of Limits/Price](https://aws.amazon.com/polly/pricing/)
3514
- [Setting up a user and how to use IAM](https://docs.aws.amazon.com/signer/latest/developerguide/iam-setup.html)
3615

16+
## Voice Prefixes
17+
18+
The voice prefixes section allows you to set a prefix that will switch the voice to a specific Polly voice.
19+
Then, if you use that prefix at the beginning of a message, the application will switch to that voice until another prefix is used.
20+
Prefixes will be matched ignoring case and even if there's a `:` or `-` after it.
21+
22+
## Speech Effect Markdown
23+
24+
This is where the marks for the effects are declared. [SSML Tags Can Be Found Here](https://docs.aws.amazon.com/polly/latest/dg/supportedtags.html) - Currently self-closing tags such as 'break' are not supported
25+
Effect declaration in the config looks like this:
26+
27+
```yml
28+
speech-effect-markdown:
29+
"!": //The character(s) that will be on either side of the text you want the effect to be used on
30+
type: tag-name //This is the tag name, might have 'amazon:' before it
31+
attribute: value // Any customization settings go after that, like "volume" and "loud"
32+
```
33+
34+
By default, the markdown will be matched if surrounded by spaces or newlines/end of lines, but not if surrounded by other characters.
35+
So you can have '.' and '..' as effect markdowns if you want
36+
37+
38+
## Text Replacements
39+
40+
This is generic text replacement - it is run through a regex so that things aren't caught in the middle of a sentence.
41+
42+
## Other Settings
43+
44+
**Server Port:**
45+
Used for the HTTP server the amazon requests are being made from. You shouldn't need to change this unless you already know what you're doing
3746
3847
### Default configuration
3948
40-
```HOCON
41-
aws-region= "US_EAST_1"
42-
aws-access-id= ""
43-
aws-secret-key= ""
44-
connect-to-twitch= false
45-
twitch-channel= ""
46-
twitch-app-client-id= ""
47-
twitch-app-client-secret= ""
48-
replace-text {
49-
"**"= "<prosody volume=\"x-loud\" pitch=\"low\" rate=\"slow\">"
50-
"/*"= "</prosody>"
51-
"*/"= "</prosody>"
52-
"~~"= "<amazon:effect name=\"whispered\">"
53-
"/~"= "</amazon:effect>"
54-
"~/"= "</amazon:effect>"
55-
"__"= "<emphasis level=\"strong\">"
56-
"/_"= "</emphasis>"
57-
"_/"= "</emphasis>"
58-
"++"= "<prosody volume=\"x-loud\" rate=\"x-fast\" pitch=\"x-high\">"
59-
"/+"= "</prosody>"
60-
"+/"= "</prosody>"
61-
"!!"= "<say-as interpret-as=\"expletive\">"
62-
"/!"= "</say-as>"
63-
"!/"= "</say-as>"
64-
" - "= "<break time=\"300ms\"/>"
65-
"<3"= "heart emoji"
66-
}
67-
default-voice= "Brian"
68-
voice-prefixes {
69-
"Sal:"= "Salli"
70-
"Kim:"= "Kimberly"
71-
"Bri:"= "Brian"
72-
}
49+
```yml
50+
aws-api:
51+
access-key: ""
52+
secret-key: ""
53+
region: "US_EAST_1"
54+
default-voice: "Brian"
55+
voice-prefixes:
56+
Sal: Salli
57+
Kim: Kimberly
58+
Bri: Brian
59+
speech-effect-markdown:
60+
"**":
61+
type: prosody
62+
volume: x-loud
63+
pitch: low
64+
rate: slow
65+
"~~":
66+
type: amazon:effect
67+
name: whispered
68+
"__":
69+
type: emphasis
70+
level: strong
71+
"*":
72+
type: prosody
73+
volume: x-loud
74+
rate: x-fast
75+
pitch: x-high
76+
"||":
77+
type: say-as
78+
interpret-as: expletive
79+
text-replacements:
80+
"<3": "heart emoji"
81+
internal-settings:
82+
server-port: 3000
83+
7384
```
7485

7586
Todo:
7687

77-
- [ ] Make closing tags less annoying
88+
- [x] Make closing tags less annoying
7889
- [x] Manage exceptions better
7990
- [x] Probably unify the config into one file
8091
- [ ] Add configuration for audio output destination
92+
- [ ] Add more Polly configuration (how dates are said, numbers, etc)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

1212
<properties>

src/main/java/simplexity/Main.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
import simplexity.config.ConfigHandler;
1414
import simplexity.config.LocaleHandler;
1515
import simplexity.config.YmlConfig;
16+
import simplexity.console.InputHandler;
17+
import simplexity.console.Logging;
1618
import simplexity.httpserver.LocalServer;
17-
import simplexity.util.Logging;
1819

1920
import java.io.File;
2021
import java.io.IOException;
21-
import java.util.Scanner;
2222

2323
public class Main {
2424
private static final Logger logger = LoggerFactory.getLogger(Main.class);
@@ -27,15 +27,13 @@ public class Main {
2727
private static CommandManager commandManager;
2828
public static PollyHandler pollyHandler;
2929
private static SpeechHandler speechHandler;
30-
public static Scanner scanner;
30+
private static InputHandler inputHandler;
31+
3132
public static boolean runApp = true;
3233

3334
@SuppressWarnings("CallToPrintStackTrace")
3435
public static void main(String[] args) {
3536
Logging.log(logger, "Starting application", Level.INFO);
36-
scanner = new Scanner(System.in);
37-
commandManager = new CommandManager();
38-
registerCommands(commandManager);
3937
File file = new File("config/config.yml");
4038
File localeFile = new File("config/locale.yml");
4139
try {
@@ -48,15 +46,13 @@ public static void main(String[] args) {
4846
}
4947
LocaleHandler.getInstance().reloadMessages();
5048
ConfigHandler.getInstance().reloadValues();
49+
commandManager = new CommandManager();
50+
speechHandler = new SpeechHandler();
51+
registerCommands(commandManager);
5152
PollySetup.setupPollyAndSpeech();
5253
LocalServer.run();
53-
while (runApp) {
54-
String input = scanner.nextLine();
55-
if (!commandManager.runCommand(input)) {
56-
input = stripInvalidCharacters(input);
57-
speechHandler.processSpeech(input);
58-
}
59-
}
54+
inputHandler = new InputHandler(commandManager, speechHandler);
55+
inputHandler.runLoop();
6056
}
6157

6258
private static void registerCommands(CommandManager commandManager) {
@@ -65,16 +61,15 @@ private static void registerCommands(CommandManager commandManager) {
6561
commandManager.registerCommand(new ReloadCommand("--reload", "Reloads the configuration"));
6662
}
6763

68-
private static String stripInvalidCharacters(String input) {
69-
if (input == null) return null;
70-
return input.replaceAll("\u001B\\[[;\\d]*[ -/]*[@-~]", "")
71-
.replaceAll("\\p{C}", "");
72-
}
7364

7465
public static CommandManager getCommandManager() {
7566
return commandManager;
7667
}
7768

69+
public static InputHandler getInputHandler() {
70+
return inputHandler;
71+
}
72+
7873
public static PollyHandler getPollyHandler() {
7974
return pollyHandler;
8075
}
@@ -87,15 +82,11 @@ public static void setPollyHandler(PollyHandler pollyHandlerToSet) {
8782
pollyHandler = pollyHandlerToSet;
8883
}
8984

90-
public static Scanner getScanner() {
91-
return scanner;
92-
}
93-
94-
public static YmlConfig getConfig(){
85+
public static YmlConfig getConfig() {
9586
return config;
9687
}
9788

98-
public static YmlConfig getLocaleConfig(){
89+
public static YmlConfig getLocaleConfig() {
9990
return localeConfig;
10091
}
10192

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
import simplexity.Main;
88
import simplexity.config.ConfigHandler;
99
import simplexity.config.LocaleHandler;
10-
import simplexity.util.Logging;
11-
12-
import java.util.Scanner;
10+
import simplexity.console.Logging;
1311

1412
public class PollySetup {
1513
private static final Logger logger = LoggerFactory.getLogger(PollySetup.class);
16-
private static final Scanner scanner = Main.getScanner();
1714

1815
public static void setupPollyAndSpeech() {
1916
connectToPolly();
@@ -38,17 +35,11 @@ public static PollyHandler createPollyHandler() {
3835
}
3936

4037
public static void connectToPolly() {
41-
while (true) {
42-
Main.setPollyHandler(createPollyHandler());
43-
if (Main.getPollyHandler() != null) {
44-
return;
45-
}
46-
Logging.logAndPrint(logger, LocaleHandler.getInstance().getSaveAwsInfo(), Level.INFO);
47-
scanner.nextLine();
48-
ConfigHandler.getInstance().reloadValues();
49-
if (Main.getPollyHandler() != null) {
50-
return;
51-
}
38+
Main.setPollyHandler(createPollyHandler());
39+
if (Main.getPollyHandler() != null) {
40+
return;
5241
}
42+
Logging.logAndPrint(logger, LocaleHandler.getInstance().getSaveAwsInfo(), Level.INFO);
43+
System.exit(-1);
5344
}
5445
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import simplexity.config.rules.SpeechEffectRule;
1717
import simplexity.config.rules.TextReplaceRule;
1818
import simplexity.config.rules.VoicePrefixRule;
19-
import simplexity.util.Logging;
19+
import simplexity.console.Logging;
2020

2121
import java.io.InputStream;
2222

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.slf4j.LoggerFactory;
55
import org.slf4j.event.Level;
66
import simplexity.config.LocaleHandler;
7-
import simplexity.util.Logging;
7+
import simplexity.console.Logging;
88

99
import java.util.HashMap;
1010

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import simplexity.Main;
55
import simplexity.config.LocaleHandler;
66
import simplexity.httpserver.LocalServer;
7-
import simplexity.util.Logging;
7+
import simplexity.console.Logging;
88

99
public class ExitCommand extends Command {
1010

src/main/java/simplexity/commands/HelpCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.slf4j.event.Level;
66
import simplexity.Main;
77
import simplexity.config.LocaleHandler;
8-
import simplexity.util.Logging;
8+
import simplexity.console.Logging;
99

1010
public class HelpCommand extends Command {
1111
private static final Logger logger = LoggerFactory.getLogger(HelpCommand.class);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import simplexity.config.ConfigHandler;
88
import simplexity.config.LocaleHandler;
99
import simplexity.httpserver.LocalServer;
10-
import simplexity.util.Logging;
10+
import simplexity.console.Logging;
1111

1212
import java.io.IOException;
13+
import java.util.Arrays;
1314

1415
public class ReloadCommand extends Command {
1516

@@ -29,7 +30,7 @@ public void execute() {
2930
LocaleHandler.getInstance().reloadMessages();
3031
} catch (IOException e) {
3132
Logging.logAndPrint(logger, "Fatal Error Reloading Config Files", Level.WARN);
32-
Logging.logAndPrint(logger, e.getStackTrace().toString(), Level.WARN);
33+
Logging.logAndPrint(logger, Arrays.toString(e.getStackTrace()), Level.WARN);
3334
System.exit(-1);
3435
}
3536
Logging.log(logger, "Stopping local server", Level.INFO);

src/main/java/simplexity/config/ConfigHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import simplexity.config.rules.SpeechEffectRule;
1111
import simplexity.config.rules.TextReplaceRule;
1212
import simplexity.config.rules.VoicePrefixRule;
13-
import simplexity.util.Logging;
13+
import simplexity.console.Logging;
1414

1515
import java.util.HashSet;
1616
import java.util.Map;

0 commit comments

Comments
 (0)