Skip to content

Commit

Permalink
Merge pull request #353 from Vonage/asr
Browse files Browse the repository at this point in the history
Add ASR
  • Loading branch information
yallen011 authored Nov 16, 2020
2 parents 4a94bbd + 0470540 commit 7c230e8
Show file tree
Hide file tree
Showing 13 changed files with 767 additions and 91 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.0.0]
## Added
- ASR (Automatic Speech Recognition)

## [5.6.0]
### Added
- NotifyEvent structure for Notify Actions
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/vonage/client/incoming/DtmfResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2020 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vonage.client.incoming;

import com.fasterxml.jackson.annotation.JsonProperty;

public class DtmfResult {

private String digits;
private boolean timedOut;

/**
*
* @return
*/
public String getDigits() {
return digits;
}

@JsonProperty("timed_out")
public boolean isTimedOut() {
return timedOut;
}
}
48 changes: 40 additions & 8 deletions src/main/java/com/vonage/client/incoming/InputEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,68 @@
import java.io.IOException;
import java.util.Date;


@JsonIgnoreProperties(ignoreUnknown = true)
public class InputEvent {
private String uuid;
private String conversationUuid;
private boolean timedOut;
private String dtmf;
private DtmfResult dtmf;
private Date timestamp;
private String to;
private String from;
private SpeechResults speech;

/**
* @return The unique identifier for this call
*/
public String getUuid() {
return uuid;
}

/**
* @return The unique identifier for this conversation
*/
@JsonProperty("conversation_uuid")
public String getConversationUuid() {
return conversationUuid;
}

@JsonProperty("timed_out")
public boolean isTimedOut() {
return timedOut;
}

public String getDtmf() {
/**
* @return DTMF capturing retults.
*/
public DtmfResult getDtmf() {
return dtmf;
}

/**
* @return Timestamp (ISO 8601 format)
*/
public Date getTimestamp() {
return timestamp;
}

/**
* @return The number the call was made to
*/
public String getTo(){
return to;
}

/**
* @return The number the call came from
*/
public String getFrom(){
return from;
}

/**
* @return Speech recognition results
* @since 6.0.0
*/
public SpeechResults getSpeech() {
return speech;
}

public static InputEvent fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/vonage/client/incoming/Result.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2020 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vonage.client.incoming;

public class Result {
private String text;
private String confidence;

/**
*
* @return transcript text
*/
public String getText() {
return text;
}

/**
* @param text transcript text representing the words the user spoke.
*/
public void setText(String text) {
this.text = text;
}

/**
*
* @return The confidence estimate between 0.0 and 1.0
*/
public String getConfidence() {
return confidence;
}

/**
* @param confidence The confidence estimate between 0.0 and 1.0. A higher number indicates an estimated greater
* likelihood that the recognized words are correct.
*/
public void setConfidence(String confidence) {
this.confidence = confidence;
}
}
69 changes: 69 additions & 0 deletions src/main/java/com/vonage/client/incoming/SpeechResults.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2020 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vonage.client.incoming;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;


import java.util.Collection;

@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class SpeechResults {
@JsonProperty("timeout_reason")
private TimeoutReason timeoutReason;
private Collection<Result> results;
private String error;

public String getError() {
return error;
}

public TimeoutReason getTimeoutReason() {
return timeoutReason;
}

/**
* @param timeoutReason Indicates whether the input ended when the user stopped speaking, by the max duration
* timeout, or if the user didn't say anything
*/
public void setTimeoutReason(TimeoutReason timeoutReason) {
this.timeoutReason = timeoutReason;
}


public Collection<Result> getResults() {
return results;
}

/**
* @param results list of speech recognition results that displays the words(s) that the user spoke and the
* likelihood that the recognized word(s) in the list where the actual word(s) that the user spoke.
*/
public void setResults(Collection<Result> results) {
this.results = results;
}

public enum TimeoutReason {
@JsonProperty("end_on_silence_timeout")
END_ON_SILENCE_TIMEOUT,
@JsonProperty("max_duration")
MAX_DURATION,
@JsonProperty("start_timeout")
START_TIMEOUT
}
}
67 changes: 67 additions & 0 deletions src/main/java/com/vonage/client/voice/ncco/DtmfSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2020 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vonage.client.voice.ncco;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
* DTMF(Dial Tone Multi Frequency) settings for Input Actions that will be added to a NCCO object.
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class DtmfSettings {
private Integer timeOut;
private Integer maxDigits;
private Boolean submitOnHash;

public Integer getTimeOut() {
return timeOut;
}

/**
* @param timeOut The result of the callee's activity is sent to the eventUrl webhook endpoint timeOut seconds
* after the last action. The default value is 3. Max is 10.
*/
public void setTimeOut(Integer timeOut) {
this.timeOut = timeOut;
}


public Integer getMaxDigits() {
return maxDigits;
}

/**
* @param maxDigits The number of digits the user can press. The maximum value is 20, the default is 4 digits.
*/
public void setMaxDigits(Integer maxDigits) {
this.maxDigits = maxDigits;
}

public Boolean isSubmitOnHash() {
return submitOnHash;
}

/**
* @param submitOnHash Set to true so the callee's activity is sent to your webhook endpoint at eventUrl after
* he or she presses #. If # is not pressed the result is submitted after timeOut seconds.
* The default value is false. That is, the result is sent to your webhook endpoint after
* timeOut seconds.
*/
public void setSubmitOnHash(Boolean submitOnHash) {
this.submitOnHash = submitOnHash;
}
}
Loading

0 comments on commit 7c230e8

Please sign in to comment.