Skip to content

Commit

Permalink
Adding custom models for Play/Recognize (#35328)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cochi2 committed Jul 6, 2023
1 parent 66660ab commit 42a83dd
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,10 @@ PlayRequest getPlayRequest(PlayOptions options) {

private PlaySourceInternal getPlaySourceInternalFromFileSource(FileSource playSource) {
FileSourceInternal fileSourceInternal = new FileSourceInternal().setUri(playSource.getUrl());
PlaySourceInternal playSourceInternal = new PlaySourceInternal()
return new PlaySourceInternal()
.setSourceType(PlaySourceTypeInternal.FILE)
.setFileSource(fileSourceInternal)
.setPlaySourceId(playSource.getPlaySourceId());
return playSourceInternal;
}

private PlaySourceInternal getPlaySourceInternalFromTextSource(TextSource playSource) {
Expand All @@ -296,21 +295,27 @@ private PlaySourceInternal getPlaySourceInternalFromTextSource(TextSource playSo
if (playSource.getVoiceName() != null) {
textSourceInternal.setVoiceName(playSource.getVoiceName());
}
if (playSource.getCustomVoiceEndpointId() != null) {
textSourceInternal.setCustomVoiceEndpointId(playSource.getCustomVoiceEndpointId());
}

PlaySourceInternal playSourceInternal = new PlaySourceInternal()
return new PlaySourceInternal()
.setSourceType(PlaySourceTypeInternal.TEXT)
.setTextSource(textSourceInternal)
.setPlaySourceId(playSource.getPlaySourceId());
return playSourceInternal;
}

private PlaySourceInternal getPlaySourceInternalFromSsmlSource(SsmlSource playSource) {
SsmlSourceInternal ssmlSourceInternal = new SsmlSourceInternal().setSsmlText(playSource.getSsmlText());
PlaySourceInternal playSourceInternal = new PlaySourceInternal()

if (playSource.getCustomVoiceEndpointId() != null) {
ssmlSourceInternal.setCustomVoiceEndpointId(playSource.getCustomVoiceEndpointId());
}

return new PlaySourceInternal()
.setSourceType(PlaySourceTypeInternal.SSML)
.setSsmlSource(ssmlSourceInternal)
.setPlaySourceId(playSource.getPlaySourceId());
return playSourceInternal;
}

private PlaySourceInternal convertPlaySourceToPlaySourceInternal(PlaySource playSource) {
Expand All @@ -319,6 +324,8 @@ private PlaySourceInternal convertPlaySourceToPlaySourceInternal(PlaySource play
playSourceInternal = getPlaySourceInternalFromFileSource((FileSource) playSource);
} else if (playSource instanceof TextSource) {
playSourceInternal = getPlaySourceInternalFromTextSource((TextSource) playSource);
} else if (playSource instanceof SsmlSource) {
playSourceInternal = getPlaySourceInternalFromSsmlSource((SsmlSource) playSource);
}
return playSourceInternal;
}
Expand Down Expand Up @@ -398,6 +405,12 @@ private RecognizeRequest getRecognizeRequestFromChoiceConfiguration(CallMediaRec
}
}

if (choiceRecognizeOptions.getSpeechModelEndpointId() != null) {
if (!choiceRecognizeOptions.getSpeechModelEndpointId().isEmpty()) {
recognizeOptionsInternal.setSpeechRecognitionModelEndpointId(choiceRecognizeOptions.getSpeechModelEndpointId());
}
}

PlaySourceInternal playSourceInternal = getPlaySourceInternalFromRecognizeOptions(recognizeOptions);

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

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

if (speechRecognizeOptions.getSpeechModelEndpointId() != null) {
if (!speechRecognizeOptions.getSpeechModelEndpointId().isEmpty()) {
recognizeOptionsInternal.setSpeechRecognitionModelEndpointId(speechRecognizeOptions.getSpeechModelEndpointId());
}
}

PlaySourceInternal playSourceInternal = getPlaySourceInternalFromRecognizeOptions(recognizeOptions);

RecognizeRequest recognizeRequest = new RecognizeRequest()
Expand Down Expand Up @@ -459,6 +478,11 @@ private RecognizeRequest getRecognizeRequestFromSpeechOrDtmfConfiguration(CallMe
.setInterruptPrompt(speechOrDtmfRecognizeOptions.isInterruptPrompt())
.setTargetParticipant(CommunicationIdentifierConverter.convert(speechOrDtmfRecognizeOptions.getTargetParticipant()));

if (speechOrDtmfRecognizeOptions.getSpeechModelEndpointId() != null) {
if (!speechOrDtmfRecognizeOptions.getSpeechModelEndpointId().isEmpty()) {
recognizeOptionsInternal.setSpeechRecognitionModelEndpointId(speechOrDtmfRecognizeOptions.getSpeechModelEndpointId());
}
}
recognizeOptionsInternal.setInitialSilenceTimeoutInSeconds((int) speechOrDtmfRecognizeOptions.getInitialSilenceTimeout().getSeconds());

PlaySourceInternal playSourceInternal = getPlaySourceInternalFromRecognizeOptions(recognizeOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public abstract class CallMediaRecognizeOptions {
@JsonProperty(value = "initialSilenceTimeout")
private Duration initialSilenceTimeout;

/*
* Endpoint where the custom model was deployed.
*/
@JsonProperty(value = "speechModelEndpointId")
private String speechModelEndpointId;

/*
* Target participant of DTFM tone recognition.
*/
Expand Down Expand Up @@ -224,4 +230,24 @@ public CallMediaRecognizeOptions setInitialSilenceTimeout(Duration initialSilenc
public CommunicationIdentifier getTargetParticipant() {
return this.targetParticipant;
}

/**
* Get the speech model endpoint id.
*
* @return the speech model endpoint id.
*/
public String getSpeechModelEndpointId() {
return speechModelEndpointId;
}

/**
* Set the speechModelEndpointId property: Endpoint where the custom model was deployed.
*
* @param speechModelEndpointId the initialSilenceTimeout value to set.
* @return the CallMediaRecognizeSpeechOrDtmfOptions object itself.
*/
public CallMediaRecognizeOptions setSpeechModelEndpointId(String speechModelEndpointId) {
this.speechModelEndpointId = speechModelEndpointId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public final class SsmlSource extends PlaySource {
@JsonProperty(value = "ssmlText", required = true)
private String ssmlText;

/*
* Endpoint where the Custom Voice was deployed.
*/
@JsonProperty(value = "customVoiceEndpointId")
private String customVoiceEndpointId;

/**
* Get the ssmlText property: Ssml string for the cognitive service to be played.
*
Expand All @@ -34,4 +40,24 @@ public SsmlSource setSsmlText(String ssmlText) {
this.ssmlText = ssmlText;
return this;
}

/**
* Get the customVoiceEndpointId property: Endpoint where the custom voice was deployed.
*
* @return the customVoiceEndpointId value.
*/
public String getCustomVoiceEndpointId() {
return this.customVoiceEndpointId;
}

/**
* Set the customVoiceEndpointId property: Endpoint where the custom voice was deployed.
*
* @param customVoiceEndpointId the customVoiceEndpointId value to set.
* @return the TextSourceInternal object itself.
*/
public SsmlSource setCustomVoiceEndpointId(String customVoiceEndpointId) {
this.customVoiceEndpointId = customVoiceEndpointId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public final class TextSource extends PlaySource {
@JsonProperty(value = "voiceName")
private String voiceName;

/*
* Endpoint where the Custom Voice was deployed.
*/
@JsonProperty(value = "customVoiceEndpointId")
private String customVoiceEndpointId;

/**
* Get the text property: Text for the cognitive service to be played.
*
Expand Down Expand Up @@ -112,4 +118,24 @@ public TextSource setVoiceName(String voiceName) {
this.voiceName = voiceName;
return this;
}

/**
* Get the customVoiceEndpointId property: Endpoint where the custom voice was deployed.
*
* @return the customVoiceEndpointId value.
*/
public String getCustomVoiceEndpointId() {
return this.customVoiceEndpointId;
}

/**
* Set the customVoiceEndpointId property: Endpoint where the custom voice was deployed.
*
* @param customVoiceEndpointId the customVoiceEndpointId value to set.
* @return the TextSourceInternal object itself.
*/
public TextSource setCustomVoiceEndpointId(String customVoiceEndpointId) {
this.customVoiceEndpointId = customVoiceEndpointId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ public void setup() {
playTextSource.setVoiceGender(GenderType.MALE);
playTextSource.setSourceLocale("en-US");
playTextSource.setVoiceName("LULU");
playTextSource.setCustomVoiceEndpointId("customVoiceEndpointId");

playSsmlSource = new SsmlSource();
playSsmlSource.setSsmlText("<speak></speak>");
playSsmlSource.setSsmlText("<speak><voice name=\"LULU\"></voice></speak>");
playSsmlSource.setCustomVoiceEndpointId("customVoiceEndpointId");
}

@Test
Expand Down Expand Up @@ -260,6 +262,7 @@ public void recognizeWithResponseWithFileSourceChoiceOptions() {
recognizeOptions.setInterruptPrompt(true);
recognizeOptions.setInitialSilenceTimeout(Duration.ofSeconds(4));
recognizeOptions.setSpeechLanguage("en-US");
recognizeOptions.setSpeechModelEndpointId("customModelEndpointId");

StepVerifier.create(
callMedia.startRecognizingWithResponse(recognizeOptions))
Expand Down Expand Up @@ -306,6 +309,7 @@ public void recognizeWithResponseTextSpeechOptions() {
recognizeOptions.setOperationContext("operationContext");
recognizeOptions.setInterruptPrompt(true);
recognizeOptions.setInitialSilenceTimeout(Duration.ofSeconds(4));
recognizeOptions.setSpeechModelEndpointId("customModelEndpointId");

StepVerifier.create(
callMedia.startRecognizingWithResponse(recognizeOptions))
Expand All @@ -325,6 +329,7 @@ public void recognizeWithResponseTextSpeechOrDtmfOptions() {
recognizeOptions.setOperationContext("operationContext");
recognizeOptions.setInterruptPrompt(true);
recognizeOptions.setInitialSilenceTimeout(Duration.ofSeconds(4));
recognizeOptions.setSpeechModelEndpointId("customModelEndpointId");

StepVerifier.create(
callMedia.startRecognizingWithResponse(recognizeOptions))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void setup() {
playTextSource.setVoiceGender(GenderType.MALE);
playTextSource.setSourceLocale("en-US");
playTextSource.setVoiceName("LULU");
playTextSource.setCustomVoiceEndpointId("customVoiceEndpointId");
}

@Test
Expand Down

0 comments on commit 42a83dd

Please sign in to comment.