Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.ibm.watson.developer_cloud.speech_to_text.v1.model;

import com.google.gson.annotations.SerializedName;
import com.ibm.watson.developer_cloud.service.model.GenericModel;

import java.util.List;

/**
* Created by Focuson on 16-7-13.
*/
public class SpeechWordAlternative extends GenericModel {
@SerializedName("start_time")
private Double startTime;

/*
* alternative in word_alternatives
*/
List<WordAlternative> alternatives;

@SerializedName("end_time")
private Double endTime;

public Double getStartTime() {
return startTime;
}

public void setStartTime(Double startTime) {
this.startTime = startTime;
}

public List<WordAlternative> getAlternatives() {
return alternatives;
}

public void setAlternatives(List<WordAlternative> alternatives) {
this.alternatives = alternatives;
}

public Double getEndTime() {
return endTime;
}

public void setEndTime(Double endTime) {
this.endTime = endTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

package com.ibm.watson.developer_cloud.speech_to_text.v1.model;

import java.util.List;
import java.util.Map;

import com.google.gson.annotations.SerializedName;
import com.ibm.watson.developer_cloud.service.model.GenericModel;

import java.util.List;
import java.util.Map;

/**
* Encapsulates a transcription along with the alternatives.
*/
Expand All @@ -31,6 +31,12 @@ public class Transcript extends GenericModel {
@SerializedName("keywords_result")
private Map<String, List<KeywordsResult>> keywordsResult;

/**
* The word_alternatives. Add by Focuson
*/
@SerializedName("word_alternatives")
private List<SpeechWordAlternative> wordAlternatives;

/**
* Gets the alternatives.
*
Expand Down Expand Up @@ -84,4 +90,12 @@ public Map<String, List<KeywordsResult>> getKeywordsResult() {
public void setKeywordsResult(Map<String, List<KeywordsResult>> keywordsResult) {
this.keywordsResult = keywordsResult;
}

public List<SpeechWordAlternative> getWordAlternatives() {
return wordAlternatives;
}

public void setWordAlternatives(List<SpeechWordAlternative> wordAlternatives) {
this.wordAlternatives = wordAlternatives;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.ibm.watson.developer_cloud.speech_to_text.v1.model;

import com.google.gson.annotations.JsonAdapter;
import com.ibm.watson.developer_cloud.service.model.GenericModel;

/**
* Created by Focuson on 16-7-13.
*/
@JsonAdapter(WordAlternativeTypeAdapter.class)
public class WordAlternative extends GenericModel {

private Double confidence;
private String word;

public WordAlternative(Double confidence, String word) {
this.confidence = confidence;
this.word = word;
}

public Double getConfidence() {
return confidence;
}

public void setConfidence(Double confidence) {
this.confidence = confidence;
}

public String getWord() {
return word;
}

public void setWord(String word) {
this.word = word;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.ibm.watson.developer_cloud.speech_to_text.v1.model;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

/**
* Created by Focuson on 16-7-13.
*/
public class WordAlternativeTypeAdapter extends TypeAdapter<WordAlternative> {
@Override
public void write(JsonWriter writer, WordAlternative value) throws IOException {
writer.beginObject();

writer.name("confidence");
writer.value(value.getConfidence());
writer.name("word");
writer.value(value.getWord());

writer.endObject();
writer.flush();
}

@Override
public WordAlternative read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}

Double confidence = null;
String word = null;

List<WordAlternative> alternatives = new LinkedList<WordAlternative>();

reader.beginObject();

if(reader.nextName().equals("confidence")) {
confidence = reader.nextDouble();
}
if (reader.nextName().equals("word")) {
word = reader.nextString();
}

reader.endObject();

WordAlternative wordAlternative = new WordAlternative(confidence, word);
return wordAlternative;
}
}