Skip to content

Commit

Permalink
getWindowsPowerShell
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Mar 17, 2024
1 parent 514293b commit 3569c64
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/org/myrobotlab/service/LocalSpeech.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public AudioData generateAudioData(AudioData audioData, String toSpeak) throws I
args.add("$speak.SelectVoice('" + getVoice().getVoiceProvider().toString() + "');");
args.add("$speak.SetOutputToWaveFile('" + localFileName + "');");
args.add("$speak.speak('" + toSpeak + "')");
String ret = Runtime.execute("%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", args, null, null, true);
String ret = Runtime.execute(getWindowsPowerShell(), args, null, null, true);

log.info("powershell returned : {}", ret);

Expand Down Expand Up @@ -179,6 +179,16 @@ public String getTtsCommand() {
public String getTtsPath() {
return ttsPath;
}

/**
* Powershell is sometimes on the PATH, this will find it hopefully
* @return absolute evaluated path to powershell.exe
*/
public String getWindowsPowerShell() {
String systemRoot = System.getenv("SYSTEMROOT");
String command = systemRoot + "\\system32\\WindowsPowerShell\\v1.0\\powershell.exe";
return command;
}

/**
* one of the few methods a SpeechSynthesis service must implement if derived
Expand Down Expand Up @@ -219,7 +229,7 @@ public void loadVoices() {
args.add("Select-Object -Property * | ");
// args.add("Select-Object -Property Culture, Name, Gender, Age");
args.add("ConvertTo-Json ");
voicesText = Runtime.execute("%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", args, null, null, true);
voicesText = Runtime.execute(getWindowsPowerShell(), args, null, null, true);

// voicesText = Runtime.execute("cmd.exe", "/c", "\"\"" + ttsPath + "\""
// + " -V" + "\"");
Expand Down Expand Up @@ -571,7 +581,7 @@ public static void main(String[] args) {
arguments.add("Add-Type -AssemblyName System.Speech;");
arguments.add("$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;");
arguments.add("$speak.speak('HELLO !!!!');");
Runtime.execute("%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", arguments, null, null, true);
Runtime.execute(mouth.getWindowsPowerShell(), arguments, null, null, true);
// log.info(ret);

mouth.speakBlocking("hello my name is sam, sam i am yet again, how \"are you? do you 'live in a zoo too? ");
Expand Down

0 comments on commit 3569c64

Please sign in to comment.