Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 7893dbd

Browse files
Updates to SetSpeakMiddleware (#1123)
1 parent 0314f4e commit 7893dbd

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/SetSpeakMiddleware.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,17 @@ public class SetSpeakMiddleware implements Middleware {
2525

2626
private final String voiceName;
2727
private final boolean fallbackToTextForSpeak;
28-
private final String lang;
2928

3029
/**
3130
* Initializes a new instance of the {@link SetSpeakMiddleware} class.
3231
*
3332
* @param voiceName The SSML voice name attribute value.
34-
* @param lang The xml:lang value.
3533
* @param fallbackToTextForSpeak true if an empt Activity.Speak is populated
3634
* with Activity.getText().
3735
*/
38-
public SetSpeakMiddleware(String voiceName, String lang, boolean fallbackToTextForSpeak) {
36+
public SetSpeakMiddleware(String voiceName, boolean fallbackToTextForSpeak) {
3937
this.voiceName = voiceName;
4038
this.fallbackToTextForSpeak = fallbackToTextForSpeak;
41-
if (lang == null) {
42-
throw new IllegalArgumentException("lang cannot be null.");
43-
} else {
44-
this.lang = lang;
45-
}
4639
}
4740

4841
/**
@@ -73,10 +66,11 @@ public CompletableFuture<Void> onTurn(TurnContext turnContext, NextDelegate next
7366
activity.setSpeak(
7467
String.format("<voice name='%s'>%s</voice>", voiceName, activity.getSpeak()));
7568
}
76-
7769
activity.setSpeak(String
7870
.format("<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' "
79-
+ "xml:lang='%s'>%s</speak>", lang, activity.getSpeak()));
71+
+ "xml:lang='%s'>%s</speak>",
72+
activity.getLocale() != null ? activity.getLocale() : "en-US",
73+
activity.getSpeak()));
8074
}
8175
}
8276
}

libraries/bot-builder/src/test/java/com/microsoft/bot/builder/SetSpeakMiddlewareTests.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@
1616

1717
public class SetSpeakMiddlewareTests {
1818

19-
@Test
20-
public void ConstructorValidation() {
21-
// no 'lang'
22-
Assert.assertThrows(IllegalArgumentException.class, () -> new SetSpeakMiddleware("voice", null, false));
23-
}
24-
2519
@Test
2620
public void NoFallback() {
2721
TestAdapter adapter = new TestAdapter(createConversation("NoFallback"))
28-
.use(new SetSpeakMiddleware("male", "en-us", false));
22+
.use(new SetSpeakMiddleware("male", false));
2923

3024
new TestFlow(adapter, turnContext -> {
3125
Activity activity = MessageFactory.text("OK");
@@ -43,7 +37,7 @@ public void NoFallback() {
4337
@Test
4438
public void FallbackNullSpeak() {
4539
TestAdapter adapter = new TestAdapter(createConversation("NoFallback"))
46-
.use(new SetSpeakMiddleware("male", "en-us", true));
40+
.use(new SetSpeakMiddleware("male", true));
4741

4842
new TestFlow(adapter, turnContext -> {
4943
Activity activity = MessageFactory.text("OK");
@@ -61,7 +55,7 @@ public void FallbackNullSpeak() {
6155
@Test
6256
public void FallbackWithSpeak() {
6357
TestAdapter adapter = new TestAdapter(createConversation("Fallback"))
64-
.use(new SetSpeakMiddleware("male", "en-us", true));
58+
.use(new SetSpeakMiddleware("male", true));
6559

6660
new TestFlow(adapter, turnContext -> {
6761
Activity activity = MessageFactory.text("OK");
@@ -93,7 +87,7 @@ public void AddVoiceTelephony() {
9387
// Voice instanceof added to Speak property.
9488
public void AddVoice(String channelId) {
9589
TestAdapter adapter = new TestAdapter(createConversation("Fallback", channelId))
96-
.use(new SetSpeakMiddleware("male", "en-us", true));
90+
.use(new SetSpeakMiddleware("male", true));
9791

9892
new TestFlow(adapter, turnContext -> {
9993
Activity activity = MessageFactory.text("OK");
@@ -119,14 +113,14 @@ public void AddNoVoiceDirectlineSpeech() {
119113

120114
@Test
121115
public void AddNoVoiceTelephony() {
122-
AddNoVoice("telephony");
116+
AddNoVoice(Channels.TELEPHONY);
123117
}
124118

125119

126120
// With no 'voice' specified, the Speak property instanceof unchanged.
127121
public void AddNoVoice(String channelId) {
128122
TestAdapter adapter = new TestAdapter(createConversation("Fallback", channelId))
129-
.use(new SetSpeakMiddleware(null, "en-us", true));
123+
.use(new SetSpeakMiddleware(null, true));
130124

131125
new TestFlow(adapter, turnContext -> {
132126
Activity activity = MessageFactory.text("OK");

libraries/bot-connector/src/main/java/com/microsoft/bot/connector/Channels.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,9 @@ private Channels() {
100100
* Test channel.
101101
*/
102102
public static final String TEST = "test";
103+
104+
/**
105+
* Telephony channel.
106+
*/
107+
public static final String TELEPHONY = "telephony";
103108
}

0 commit comments

Comments
 (0)