Skip to content

Commit 42a83dd

Browse files
authored
Adding custom models for Play/Recognize (#35328)
* Using the latest swagger * Updating files * Removing imports * Moving to official swagger branch * Fixing test * Fixing tests * Updating latest swagger * Updated latest swagger and live tests * Updating swagger location * Adding custom models for Play/Recognize * Fixing SSML prompt for Recognize
1 parent 66660ab commit 42a83dd

File tree

6 files changed

+115
-7
lines changed

6 files changed

+115
-7
lines changed

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallMediaAsync.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,10 @@ PlayRequest getPlayRequest(PlayOptions options) {
278278

279279
private PlaySourceInternal getPlaySourceInternalFromFileSource(FileSource playSource) {
280280
FileSourceInternal fileSourceInternal = new FileSourceInternal().setUri(playSource.getUrl());
281-
PlaySourceInternal playSourceInternal = new PlaySourceInternal()
281+
return new PlaySourceInternal()
282282
.setSourceType(PlaySourceTypeInternal.FILE)
283283
.setFileSource(fileSourceInternal)
284284
.setPlaySourceId(playSource.getPlaySourceId());
285-
return playSourceInternal;
286285
}
287286

288287
private PlaySourceInternal getPlaySourceInternalFromTextSource(TextSource playSource) {
@@ -296,21 +295,27 @@ private PlaySourceInternal getPlaySourceInternalFromTextSource(TextSource playSo
296295
if (playSource.getVoiceName() != null) {
297296
textSourceInternal.setVoiceName(playSource.getVoiceName());
298297
}
298+
if (playSource.getCustomVoiceEndpointId() != null) {
299+
textSourceInternal.setCustomVoiceEndpointId(playSource.getCustomVoiceEndpointId());
300+
}
299301

300-
PlaySourceInternal playSourceInternal = new PlaySourceInternal()
302+
return new PlaySourceInternal()
301303
.setSourceType(PlaySourceTypeInternal.TEXT)
302304
.setTextSource(textSourceInternal)
303305
.setPlaySourceId(playSource.getPlaySourceId());
304-
return playSourceInternal;
305306
}
306307

307308
private PlaySourceInternal getPlaySourceInternalFromSsmlSource(SsmlSource playSource) {
308309
SsmlSourceInternal ssmlSourceInternal = new SsmlSourceInternal().setSsmlText(playSource.getSsmlText());
309-
PlaySourceInternal playSourceInternal = new PlaySourceInternal()
310+
311+
if (playSource.getCustomVoiceEndpointId() != null) {
312+
ssmlSourceInternal.setCustomVoiceEndpointId(playSource.getCustomVoiceEndpointId());
313+
}
314+
315+
return new PlaySourceInternal()
310316
.setSourceType(PlaySourceTypeInternal.SSML)
311317
.setSsmlSource(ssmlSourceInternal)
312318
.setPlaySourceId(playSource.getPlaySourceId());
313-
return playSourceInternal;
314319
}
315320

316321
private PlaySourceInternal convertPlaySourceToPlaySourceInternal(PlaySource playSource) {
@@ -319,6 +324,8 @@ private PlaySourceInternal convertPlaySourceToPlaySourceInternal(PlaySource play
319324
playSourceInternal = getPlaySourceInternalFromFileSource((FileSource) playSource);
320325
} else if (playSource instanceof TextSource) {
321326
playSourceInternal = getPlaySourceInternalFromTextSource((TextSource) playSource);
327+
} else if (playSource instanceof SsmlSource) {
328+
playSourceInternal = getPlaySourceInternalFromSsmlSource((SsmlSource) playSource);
322329
}
323330
return playSourceInternal;
324331
}
@@ -398,6 +405,12 @@ private RecognizeRequest getRecognizeRequestFromChoiceConfiguration(CallMediaRec
398405
}
399406
}
400407

408+
if (choiceRecognizeOptions.getSpeechModelEndpointId() != null) {
409+
if (!choiceRecognizeOptions.getSpeechModelEndpointId().isEmpty()) {
410+
recognizeOptionsInternal.setSpeechRecognitionModelEndpointId(choiceRecognizeOptions.getSpeechModelEndpointId());
411+
}
412+
}
413+
401414
PlaySourceInternal playSourceInternal = getPlaySourceInternalFromRecognizeOptions(recognizeOptions);
402415

403416
RecognizeRequest recognizeRequest = new RecognizeRequest()
@@ -422,6 +435,12 @@ private RecognizeRequest getRecognizeRequestFromSpeechConfiguration(CallMediaRec
422435

423436
recognizeOptionsInternal.setInitialSilenceTimeoutInSeconds((int) speechRecognizeOptions.getInitialSilenceTimeout().getSeconds());
424437

438+
if (speechRecognizeOptions.getSpeechModelEndpointId() != null) {
439+
if (!speechRecognizeOptions.getSpeechModelEndpointId().isEmpty()) {
440+
recognizeOptionsInternal.setSpeechRecognitionModelEndpointId(speechRecognizeOptions.getSpeechModelEndpointId());
441+
}
442+
}
443+
425444
PlaySourceInternal playSourceInternal = getPlaySourceInternalFromRecognizeOptions(recognizeOptions);
426445

427446
RecognizeRequest recognizeRequest = new RecognizeRequest()
@@ -459,6 +478,11 @@ private RecognizeRequest getRecognizeRequestFromSpeechOrDtmfConfiguration(CallMe
459478
.setInterruptPrompt(speechOrDtmfRecognizeOptions.isInterruptPrompt())
460479
.setTargetParticipant(CommunicationIdentifierConverter.convert(speechOrDtmfRecognizeOptions.getTargetParticipant()));
461480

481+
if (speechOrDtmfRecognizeOptions.getSpeechModelEndpointId() != null) {
482+
if (!speechOrDtmfRecognizeOptions.getSpeechModelEndpointId().isEmpty()) {
483+
recognizeOptionsInternal.setSpeechRecognitionModelEndpointId(speechOrDtmfRecognizeOptions.getSpeechModelEndpointId());
484+
}
485+
}
462486
recognizeOptionsInternal.setInitialSilenceTimeoutInSeconds((int) speechOrDtmfRecognizeOptions.getInitialSilenceTimeout().getSeconds());
463487

464488
PlaySourceInternal playSourceInternal = getPlaySourceInternalFromRecognizeOptions(recognizeOptions);

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/models/CallMediaRecognizeOptions.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public abstract class CallMediaRecognizeOptions {
5454
@JsonProperty(value = "initialSilenceTimeout")
5555
private Duration initialSilenceTimeout;
5656

57+
/*
58+
* Endpoint where the custom model was deployed.
59+
*/
60+
@JsonProperty(value = "speechModelEndpointId")
61+
private String speechModelEndpointId;
62+
5763
/*
5864
* Target participant of DTFM tone recognition.
5965
*/
@@ -224,4 +230,24 @@ public CallMediaRecognizeOptions setInitialSilenceTimeout(Duration initialSilenc
224230
public CommunicationIdentifier getTargetParticipant() {
225231
return this.targetParticipant;
226232
}
233+
234+
/**
235+
* Get the speech model endpoint id.
236+
*
237+
* @return the speech model endpoint id.
238+
*/
239+
public String getSpeechModelEndpointId() {
240+
return speechModelEndpointId;
241+
}
242+
243+
/**
244+
* Set the speechModelEndpointId property: Endpoint where the custom model was deployed.
245+
*
246+
* @param speechModelEndpointId the initialSilenceTimeout value to set.
247+
* @return the CallMediaRecognizeSpeechOrDtmfOptions object itself.
248+
*/
249+
public CallMediaRecognizeOptions setSpeechModelEndpointId(String speechModelEndpointId) {
250+
this.speechModelEndpointId = speechModelEndpointId;
251+
return this;
252+
}
227253
}

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/models/SsmlSource.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public final class SsmlSource extends PlaySource {
1515
@JsonProperty(value = "ssmlText", required = true)
1616
private String ssmlText;
1717

18+
/*
19+
* Endpoint where the Custom Voice was deployed.
20+
*/
21+
@JsonProperty(value = "customVoiceEndpointId")
22+
private String customVoiceEndpointId;
23+
1824
/**
1925
* Get the ssmlText property: Ssml string for the cognitive service to be played.
2026
*
@@ -34,4 +40,24 @@ public SsmlSource setSsmlText(String ssmlText) {
3440
this.ssmlText = ssmlText;
3541
return this;
3642
}
43+
44+
/**
45+
* Get the customVoiceEndpointId property: Endpoint where the custom voice was deployed.
46+
*
47+
* @return the customVoiceEndpointId value.
48+
*/
49+
public String getCustomVoiceEndpointId() {
50+
return this.customVoiceEndpointId;
51+
}
52+
53+
/**
54+
* Set the customVoiceEndpointId property: Endpoint where the custom voice was deployed.
55+
*
56+
* @param customVoiceEndpointId the customVoiceEndpointId value to set.
57+
* @return the TextSourceInternal object itself.
58+
*/
59+
public SsmlSource setCustomVoiceEndpointId(String customVoiceEndpointId) {
60+
this.customVoiceEndpointId = customVoiceEndpointId;
61+
return this;
62+
}
3763
}

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/models/TextSource.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public final class TextSource extends PlaySource {
3333
@JsonProperty(value = "voiceName")
3434
private String voiceName;
3535

36+
/*
37+
* Endpoint where the Custom Voice was deployed.
38+
*/
39+
@JsonProperty(value = "customVoiceEndpointId")
40+
private String customVoiceEndpointId;
41+
3642
/**
3743
* Get the text property: Text for the cognitive service to be played.
3844
*
@@ -112,4 +118,24 @@ public TextSource setVoiceName(String voiceName) {
112118
this.voiceName = voiceName;
113119
return this;
114120
}
121+
122+
/**
123+
* Get the customVoiceEndpointId property: Endpoint where the custom voice was deployed.
124+
*
125+
* @return the customVoiceEndpointId value.
126+
*/
127+
public String getCustomVoiceEndpointId() {
128+
return this.customVoiceEndpointId;
129+
}
130+
131+
/**
132+
* Set the customVoiceEndpointId property: Endpoint where the custom voice was deployed.
133+
*
134+
* @param customVoiceEndpointId the customVoiceEndpointId value to set.
135+
* @return the TextSourceInternal object itself.
136+
*/
137+
public TextSource setCustomVoiceEndpointId(String customVoiceEndpointId) {
138+
this.customVoiceEndpointId = customVoiceEndpointId;
139+
return this;
140+
}
115141
}

sdk/communication/azure-communication-callautomation/src/test/java/com/azure/communication/callautomation/CallMediaAsyncUnitTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ public void setup() {
5858
playTextSource.setVoiceGender(GenderType.MALE);
5959
playTextSource.setSourceLocale("en-US");
6060
playTextSource.setVoiceName("LULU");
61+
playTextSource.setCustomVoiceEndpointId("customVoiceEndpointId");
6162

6263
playSsmlSource = new SsmlSource();
63-
playSsmlSource.setSsmlText("<speak></speak>");
64+
playSsmlSource.setSsmlText("<speak><voice name=\"LULU\"></voice></speak>");
65+
playSsmlSource.setCustomVoiceEndpointId("customVoiceEndpointId");
6466
}
6567

6668
@Test
@@ -260,6 +262,7 @@ public void recognizeWithResponseWithFileSourceChoiceOptions() {
260262
recognizeOptions.setInterruptPrompt(true);
261263
recognizeOptions.setInitialSilenceTimeout(Duration.ofSeconds(4));
262264
recognizeOptions.setSpeechLanguage("en-US");
265+
recognizeOptions.setSpeechModelEndpointId("customModelEndpointId");
263266

264267
StepVerifier.create(
265268
callMedia.startRecognizingWithResponse(recognizeOptions))
@@ -306,6 +309,7 @@ public void recognizeWithResponseTextSpeechOptions() {
306309
recognizeOptions.setOperationContext("operationContext");
307310
recognizeOptions.setInterruptPrompt(true);
308311
recognizeOptions.setInitialSilenceTimeout(Duration.ofSeconds(4));
312+
recognizeOptions.setSpeechModelEndpointId("customModelEndpointId");
309313

310314
StepVerifier.create(
311315
callMedia.startRecognizingWithResponse(recognizeOptions))
@@ -325,6 +329,7 @@ public void recognizeWithResponseTextSpeechOrDtmfOptions() {
325329
recognizeOptions.setOperationContext("operationContext");
326330
recognizeOptions.setInterruptPrompt(true);
327331
recognizeOptions.setInitialSilenceTimeout(Duration.ofSeconds(4));
332+
recognizeOptions.setSpeechModelEndpointId("customModelEndpointId");
328333

329334
StepVerifier.create(
330335
callMedia.startRecognizingWithResponse(recognizeOptions))

sdk/communication/azure-communication-callautomation/src/test/java/com/azure/communication/callautomation/CallMediaUnitTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void setup() {
4545
playTextSource.setVoiceGender(GenderType.MALE);
4646
playTextSource.setSourceLocale("en-US");
4747
playTextSource.setVoiceName("LULU");
48+
playTextSource.setCustomVoiceEndpointId("customVoiceEndpointId");
4849
}
4950

5051
@Test

0 commit comments

Comments
 (0)