Skip to content

Commit 886b2e9

Browse files
committed
update remote speech and test
- update the input to become more flexible. - create test cases.
1 parent 15463b5 commit 886b2e9

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

core/com.intellijava.core/src/main/java/com/intellijava/core/controller/RemoteSpeechModel.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.HashMap;
55
import java.util.List;
66
import java.util.Map;
7-
87
import com.intellijava.core.model.AudioResponse;
98
import com.intellijava.core.model.SpeechModels;
109
import com.intellijava.core.model.input.SpeechInput;

core/com.intellijava.core/src/main/java/com/intellijava/core/model/input/SpeechInput.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ private SpeechInput(Builder builder) {
1010
this.gender = builder.gender;
1111
}
1212

13+
public SpeechInput(String text, Gender gender) {
14+
this.text = text;
15+
this.gender = gender;
16+
}
17+
1318
public static class Builder {
1419

1520
private String text;
@@ -42,7 +47,17 @@ public Gender getGender() {
4247
return gender;
4348
}
4449

45-
public enum Gender {
50+
public void setText(String text) {
51+
this.text = text;
52+
}
53+
54+
public void setGender(Gender gender) {
55+
this.gender = gender;
56+
}
57+
58+
59+
60+
public enum Gender {
4661
MALE, FEMALE;
4762
}
4863
}

core/com.intellijava.core/src/test/java/com/intellijava/core/GoogleSpeechTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
import org.junit.Test;
1010

11+
import com.intellijava.core.controller.RemoteSpeechModel;
1112
import com.intellijava.core.model.AudioResponse;
13+
import com.intellijava.core.model.SpeechModels;
14+
import com.intellijava.core.model.input.SpeechInput;
15+
import com.intellijava.core.model.input.SpeechInput.Gender;
1216
import com.intellijava.core.utils.AudioHelper;
1317
import com.intellijava.core.utils.Config2;
1418
import com.intellijava.core.wrappers.GoogleAIWrapper;
@@ -76,4 +80,24 @@ public void testText2FemaleSpeechWrapper() {
7680
}
7781
}
7882
}
83+
84+
@Test
85+
public void testText2FemaleRemoteSpeecModel() {
86+
SpeechInput input = new SpeechInput.Builder("Hi, I am Intelligent Java.").
87+
setGender(Gender.FEMALE).build();
88+
89+
RemoteSpeechModel model = new RemoteSpeechModel(apiKey, SpeechModels.google);
90+
91+
try {
92+
byte[] decodedAudio = model.generateEnglishText(input);
93+
assert AudioHelper.saveTempAudio(decodedAudio) == true;
94+
AudioHelper.deleteTempAudio();
95+
} catch (IOException e) {
96+
if (apiKey.isBlank()) {
97+
System.out.print("testRemoteSpeech set the API key to run the test case.");
98+
} else {
99+
fail("testRemoteSpeech failed with exception: " + e.getMessage());
100+
}
101+
}
102+
}
79103
}

0 commit comments

Comments
 (0)