Skip to content

Commit

Permalink
Merge pull request #358 from Vonage/language_style
Browse files Browse the repository at this point in the history
Adding Language and style, deprecating voice name
  • Loading branch information
slorello89 authored Dec 17, 2020
2 parents b3651cb + 493f68f commit d4c8532
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [6.1.0]
- Adding Language and Style to the Voice Talk Action and the Talk Request
- Marking VoiceName as Deprecated

## [6.0.0]
## Added
- ASR (Automatic Speech Recognition)
Expand Down
37 changes: 34 additions & 3 deletions src/main/java/com/vonage/client/voice/TalkPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -25,21 +26,44 @@
* <p>
* {@code text}: A string of up to 1500 characters containing the message to be synthesized
* in the Call or Conversation. Each comma in text adds a short pause to the synthesized speech.
* {@link VoiceName}: The name of the voice used to deliver {@code text}.
* {@link VoiceName}: DEPRECATED: The name of the voice used to deliver {@code text}.
* {@code loop}: The number of times the audio file at stream_url is repeated before the stream ends. Set to 0 to loop infinitely.
* {@link TextToSpeechLanguage}: The Language that will be used to convert {@code text} into speech
* {@code style}: The Vocal Style to use (vocal Range, tessitura, timbre to use in the TTS
*/

public class TalkPayload {
private String text;
private VoiceName voiceName;
private int loop;
private TextToSpeechLanguage language;

@JsonInclude(JsonInclude.Include.NON_NULL)
private Integer style = null;

@Deprecated
@JsonInclude(JsonInclude.Include.NON_NULL)
private VoiceName voiceName;

@Deprecated
public TalkPayload(String text, VoiceName voiceName, int loop) {
this.text = text;
this.voiceName = voiceName;
this.loop = loop;
}

public TalkPayload(String text, TextToSpeechLanguage language, int style, int loop){
this.text = text;
this.language = language;
this.style = style;
this.loop = loop;
}

public TalkPayload(String text, TextToSpeechLanguage language, int loop){
this.text = text;
this.language = language;
this.loop = loop;
}

public int getLoop() {
return loop;
}
Expand All @@ -48,11 +72,18 @@ public String getText() {
return text;
}

@JsonProperty("voice_name")
@JsonProperty(value = "voice_name")
@JsonInclude(JsonInclude.Include.NON_NULL)
public VoiceName getVoiceName() {
return voiceName;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
public TextToSpeechLanguage getLanguage() { return language; }

@JsonInclude(JsonInclude.Include.NON_NULL)
public Integer getStyle() { return style; }

public String toJson() {
try {
ObjectMapper mapper = new ObjectMapper();
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/com/vonage/client/voice/TalkRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,39 @@ public class TalkRequest {
private TalkPayload talkPayload;
private String uuid;

@Deprecated
public TalkRequest(String uuid, String text, VoiceName voiceName, int loop) {
talkPayload = new TalkPayload(text, voiceName, loop);
this.uuid = uuid;
}

public TalkRequest(String uuid, String text, TextToSpeechLanguage language, int style, int loop){
talkPayload = new TalkPayload(text, language, style, loop);
this.uuid = uuid;
}

public TalkRequest(String uuid, String text, TextToSpeechLanguage language, int style){
talkPayload = new TalkPayload(text, language, style, 1);
this.uuid = uuid;
}

public TalkRequest(String uuid, String text, TextToSpeechLanguage language){
talkPayload = new TalkPayload(text, language, 1);
this.uuid = uuid;
}

@Deprecated
public TalkRequest(String uuid, String text, VoiceName voiceName) {
this(uuid, text, voiceName, 1);
}


public TalkRequest(String uuid, String text, int loop) {
this(uuid, text, VoiceName.KIMBERLY, loop);
this(uuid, text, TextToSpeechLanguage.AMERICAN_ENGLISH, 3, loop);
}

public TalkRequest(String uuid, String text) {
this(uuid, text, VoiceName.KIMBERLY, 1);
this(uuid, text, TextToSpeechLanguage.AMERICAN_ENGLISH, 3, 1);
}

public String getUuid() {
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/com/vonage/client/voice/TextToSpeechLanguage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
import com.fasterxml.jackson.annotation.JsonValue;

public enum TextToSpeechLanguage {
ARABIC("ar"),
SPANISH_CATALAN("ca-ES"),
CHINESE_MANDARIN("cmn-CN"),
TAIWANESE_MANDARIN("cmn-TW"),
CZECH("cs-CZ"),
WELSH("cy-GB"),
DANISH("da-DK"),
GERMAN("de-DE"),
GREEK("el-GR"),
AUSTRALIAN_ENGLISH("en-AU"),
UNITED_KINGDOM_ENGLISH("en-GB"),
WELSH_ENGLISH("en-GB-WLS"),
INDIAN_ENGLISH("en-IN"),
AMERICAN_ENGLISH("en-US"),
SOUTH_AFRICAN_ENGLISH("en-ZA"),
SPANISH("es-ES"),
MEXICAN_SPANISH("es-MX"),
AMERICAN_SPANISH("es-US"),
BASQUE("eu-ES"),
FINISH("fi-FI"),
FILIPINO("fil-PH"),
CANADIAN_FRENCH("fr-CA"),
FRENCH("fr-FR"),
HEBREW("he-IL"),
HINDI("hi-IN"),
HUNGARIAN("hu-HU"),
INDONESIAN("id-ID"),
ICELANDIC("is-IS"),
ITALIAN("it-IT"),
JAPANESE("ja-JP"),
KOREAN("ko-KR"),
NORWEGIAN("no-NO"),
NORWEGIAN_BOKMAL("nb-NO"),
DUTCH("nl-NL"),
POLISH("pl-PL"),
BRAZILIAN_PORTUGUESE("pt-BR"),
PORTUGUESE("pt-PT"),
ROMANIAN("ro-RO"),
RUSSIAN("ru-RU"),
SLOVAK("sk-SK"),
SWEDISH("sv-SE"),
THAI("th-TH"),
TURKISH("tr-TR"),
UKRAINIAN("uk-UA"),
VIETNAMESE("vi-VN"),
CHINESE_YUE("yue-CN"),
@JsonEnumDefaultValue
UNKNOWN("Unknown");
private final String language;
TextToSpeechLanguage(String language){this.language=language;}
@JsonValue
public String getLanguage(){return this.language;}
}
77 changes: 77 additions & 0 deletions src/main/java/com/vonage/client/voice/VoiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,47 @@ public TalkResponse startTalk(String uuid, String text) throws VonageResponsePar
* @throws VonageClientException if there was a problem with the Vonage request or response objects.
* @throws VonageResponseParseException if the response from the API could not be parsed.
*/
@Deprecated
public TalkResponse startTalk(String uuid, String text, VoiceName voiceName) throws VonageResponseParseException, VonageClientException {
return talk.put(new TalkRequest(uuid, text, voiceName));
}

/**
* @param uuid The UUID of the call, obtained from the object returned by {@link #createCall(Call)}. This value
* can be obtained with {@link CallEvent#getUuid()}
* @param text The message to be spoken to the call participants.
*
* @param language The Language to use when converting text-to-speech
*
* @param style The Style to use for Text-To-Speech
*
* @return The data returned from the Voice API.
*
* @throws VonageClientException if there was a problem with the Vonage request or response objects.
* @throws VonageResponseParseException if the response from the API could not be parsed.
*
*/
public TalkResponse startTalk(String uuid, String text, TextToSpeechLanguage language, Integer style) throws VonageResponseParseException, VonageClientException {
return talk.put(new TalkRequest(uuid, text, language, style));
}

/**
* @param uuid The UUID of the call, obtained from the object returned by {@link #createCall(Call)}. This value
* can be obtained with {@link CallEvent#getUuid()}
* @param text The message to be spoken to the call participants.
*
* @param language The Language to use when converting text-to-speech
*
* @return The data returned from the Voice API.
*
* @throws VonageClientException if there was a problem with the Vonage request or response objects.
* @throws VonageResponseParseException if the response from the API could not be parsed.
*
*/
public TalkResponse startTalk(String uuid, String text, TextToSpeechLanguage language) throws VonageResponseParseException, VonageClientException {
return talk.put(new TalkRequest(uuid, text, language));
}

/**
* Send a synthesized speech message to an ongoing call.
* <p>
Expand Down Expand Up @@ -315,10 +352,50 @@ public TalkResponse startTalk(String uuid, String text, int loop) throws VonageR
* @throws VonageClientException if there was a problem with the Vonage request or response objects.
* @throws VonageResponseParseException if the response from the API could not be parsed.
*/
@Deprecated
public TalkResponse startTalk(String uuid, String text, VoiceName voiceName, int loop) throws VonageResponseParseException, VonageClientException {
return talk.put(new TalkRequest(uuid, text, voiceName, loop));
}

/**
* Send a synthesized speech message to an ongoing call.
*
* @param uuid The UUID of the call, obtained from the object returned by {@link #createCall(Call)}. This value
* can be obtained with {@link CallEvent#getUuid()}
* @param text The message to be spoken to the call participants.
* @param language The language to use for the text-to-speech
* @param style The language style to use for the text-to-speech
* @param loop The number of times to repeat the message. The default value is {@code 1}, or you can use {@code
* 0} to indicate that the message should be repeated indefinitely.
*
* @return The data returned from the Voice API.
*
* @throws VonageClientException if there was a problem with the Vonage request or response objects.
* @throws VonageResponseParseException if the response from the API could not be parsed.
*/
public TalkResponse startTalk(String uuid, String text, TextToSpeechLanguage language, int style, int loop) throws VonageResponseParseException, VonageClientException {
return talk.put(new TalkRequest(uuid, text, language, style, loop));
}

/**
* Send a synthesized speech message to an ongoing call.
*
* @param uuid The UUID of the call, obtained from the object returned by {@link #createCall(Call)}. This value
* can be obtained with {@link CallEvent#getUuid()}
* @param text The message to be spoken to the call participants.
* @param language The language to use for the text-to-speech
* @param style The language style to use for the text-to-speech
*
* @return The data returned from the Voice API.
*
* @throws VonageClientException if there was a problem with the Vonage request or response objects.
* @throws VonageResponseParseException if the response from the API could not be parsed.
*/
public TalkResponse startTalk(String uuid, String text, TextToSpeechLanguage language, int style) throws VonageResponseParseException, VonageClientException {
return talk.put(new TalkRequest(uuid, text, language, style));
}


/**
* Stop the message being spoken into a call.
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/vonage/client/voice/VoiceName.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Voice used to deliver text to a {@link Call} in a {@link TalkRequest}.
*/

@Deprecated
public enum VoiceName {
ADITI("Aditi"),
AGNIESZKA("Agnieszka"),
Expand Down
36 changes: 35 additions & 1 deletion src/main/java/com/vonage/client/voice/ncco/TalkAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.vonage.client.voice.TextToSpeechLanguage;
import com.vonage.client.voice.VoiceName;

/**
Expand All @@ -31,6 +32,10 @@ public class TalkAction implements Action {
private Boolean bargeIn;
private Integer loop;
private Float level;
private TextToSpeechLanguage language;
private Integer style;

@Deprecated
private VoiceName voiceName;

private TalkAction(Builder builder) {
Expand All @@ -39,6 +44,8 @@ private TalkAction(Builder builder) {
this.loop = builder.loop;
this.level = builder.level;
this.voiceName = builder.voiceName;
this.style = builder.style;
this.language = builder.language;
}

@Override
Expand All @@ -62,6 +69,11 @@ public Float getLevel() {
return level;
}

public TextToSpeechLanguage getLanguage() { return language; }

public Integer getStyle() { return style; }

@Deprecated
public VoiceName getVoiceName() {
return voiceName;
}
Expand All @@ -76,7 +88,8 @@ public static class Builder {
private Integer loop = null;
private Float level = null;
private VoiceName voiceName = null;

private TextToSpeechLanguage language = null;
private Integer style = null;
/**
* @param text A string of up to 1,500 characters (excluding SSML tags) containing the message to be
* synthesized in the Call or Conversation. A single comma in text adds a short pause to the
Expand Down Expand Up @@ -137,6 +150,26 @@ public Builder level(Float level) {
return this;
}

/**
* @param language The Language to use when converting the text to speech
*
* @return The {@link Builder} to keep building
*/
public Builder language(TextToSpeechLanguage language){
this.language = language;
return this;
}

/**
* @param style The vocal style to use
*
* @return The {@link Builder} to keep building
*/
public Builder style(Integer style){
this.style = style;
return this;
}

/**
* @param voiceName The name of the voice used to deliver text. You use the voiceName that has the correct
* language, gender and accent for the message you are sending.
Expand All @@ -146,6 +179,7 @@ public Builder level(Float level) {
*
* @return The {@link Builder} to keep building.
*/
@Deprecated
public Builder voiceName(VoiceName voiceName) {
this.voiceName = voiceName;
return this;
Expand Down
Loading

0 comments on commit d4c8532

Please sign in to comment.