-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added load from google speech suport
- Loading branch information
Showing
11 changed files
with
242 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,7 @@ public AWSTranscriptResults(JSONObject resultsJSON) { | |
} | ||
} | ||
} | ||
|
||
public AWSTranscriptResults() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
|
||
public class GoogleSpeechAlternatives { | ||
String transcript; | ||
String confidence; | ||
GoogleSpeechWords words[]; | ||
|
||
GoogleSpeechAlternatives(JSONObject alternativeJSON){ | ||
transcript = (String) alternativeJSON.get("transcript"); | ||
confidence = (String) alternativeJSON.get("confidence").toString(); | ||
|
||
JSONArray wordsJSON = (JSONArray) alternativeJSON.get("words"); | ||
|
||
int words_size = wordsJSON.size(); | ||
|
||
words = new GoogleSpeechWords[words_size]; | ||
for(int i = 0 ; i < words_size; i++) { | ||
words[i] = new GoogleSpeechWords((JSONObject) wordsJSON.get(i)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import org.json.simple.JSONObject; | ||
|
||
public class GoogleSpeechMetaData { | ||
//String @type = null; | ||
String progressPercent; | ||
String startTime; | ||
String lastUpdateTime; | ||
|
||
public GoogleSpeechMetaData(JSONObject metaDataJSON) { | ||
startTime = (String) metaDataJSON.get("startTime"); | ||
progressPercent = (String) metaDataJSON.get("progressPercent").toString(); | ||
lastUpdateTime = (String) metaDataJSON.get("lastUpdateTime"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
|
||
public class GoogleSpeechResponse { | ||
//String @type | ||
GoogleSpeechResult results[]; | ||
|
||
public GoogleSpeechResponse(JSONObject responseJSON) { | ||
|
||
JSONArray resultsJSON = (JSONArray) responseJSON.get("results"); | ||
|
||
int results_size = resultsJSON.size(); | ||
|
||
results = new GoogleSpeechResult[results_size]; | ||
for(int i = 0 ; i < results_size; i++) { | ||
results[i] = new GoogleSpeechResult((JSONObject) resultsJSON.get(i)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
|
||
public class GoogleSpeechResult { | ||
String languageCode; | ||
GoogleSpeechAlternatives alternatives[]; | ||
|
||
GoogleSpeechResult(JSONObject resultJSON){ | ||
languageCode = (String) resultJSON.get("languageCode"); | ||
|
||
JSONArray alternativesJSON = (JSONArray) resultJSON.get("alternatives"); | ||
|
||
int alts_size = alternativesJSON.size(); | ||
|
||
alternatives = new GoogleSpeechAlternatives[alts_size]; | ||
for(int i = 0 ; i < alts_size; i++) { | ||
alternatives[i] = new GoogleSpeechAlternatives((JSONObject) alternativesJSON.get(i)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import org.json.simple.JSONObject; | ||
|
||
public class GoogleSpeechWords { | ||
String startTime; | ||
String endTime; | ||
String word; | ||
String confidence; | ||
|
||
GoogleSpeechWords(JSONObject wordJSON){ | ||
startTime = (String) wordJSON.get("startTime"); | ||
endTime = (String) wordJSON.get("endTime"); | ||
word = (String) wordJSON.get("word"); | ||
confidence = (String) wordJSON.get("confidence").toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//Copyright 2018, Creed Alexander Erickson IV, All rights reserved. | ||
|
||
import java.io.FileReader; | ||
import java.io.IOException; | ||
|
||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
import org.json.simple.parser.ParseException; | ||
|
||
// Google speech API, transcribed object | ||
public class GoogleTranscript{ | ||
String name; | ||
String done; | ||
GoogleSpeechMetaData metadata; | ||
GoogleSpeechResponse response; | ||
|
||
public GoogleTranscript(JSONObject transcriptJSON) { | ||
name = (String) transcriptJSON.get("name"); | ||
done = transcriptJSON.get("done").toString(); | ||
|
||
JSONObject responseJSON = (JSONObject) transcriptJSON.get("response"); | ||
response = new GoogleSpeechResponse(responseJSON); | ||
|
||
JSONObject metaDataJSON = (JSONObject) transcriptJSON.get("metadata"); | ||
metadata = new GoogleSpeechMetaData(metaDataJSON); | ||
} | ||
|
||
/* dont need to create GOOGLe transcript from aws, need other way, just add missing constuctors if wanted | ||
public GoogleTranscript(AWSTranscript awsTranscript) { | ||
name = awsTranscript.jobName; | ||
done = "true"; // maybe handle this buy using aws.status values??? | ||
metadata = GoogleSpeechMetaData(); | ||
response = new GoogleSpeechResponse(); | ||
response.results = new GoogleSpeechResult[1]; // only create one result, with all words | ||
response.results[0] = new GoogleSpeechResult(); | ||
response.results[0].languageCode = "en-us"; | ||
response.results[0].alternatives = new GoogleSpeechAlternatives[1]; | ||
response.results[0].alternatives[0] = GoogleSpeechAlternatives(); | ||
response.results[0].alternatives[0].transcript = awsTranscript.results.transcripts[0].transcript; | ||
AWSTranscriptItem[] awsItems = awsTranscript.results.items; | ||
response.results[0].alternatives[0].words = new GoogleSpeechWords[awsItems.length]; | ||
int i = 0; | ||
for(AWSTranscriptItem awsItem : awsItems) { | ||
response.results[0].alternatives[0].words[i] = new GoogleSpeechWords(); | ||
response.results[0].alternatives[0].words[i].startTime = awsItem.start_time + "s"; | ||
response.results[0].alternatives[0].words[i].endTime = awsItem.end_time + "s"; | ||
response.results[0].alternatives[0].words[i].confidence = awsItem.alternatives[0].confidence; | ||
response.results[0].alternatives[0].words[i].word = awsItem.alternatives[0].content; | ||
} | ||
} | ||
*/ | ||
|
||
// factory constructor from filename | ||
static public GoogleTranscript createFromFile(String filename) { | ||
JSONParser parser = new JSONParser(); | ||
|
||
JSONObject fileAsJSON = null; | ||
try { | ||
fileAsJSON = (JSONObject) parser.parse(new FileReader(filename)); | ||
} catch (IOException | ParseException e) { | ||
e.printStackTrace(); | ||
} | ||
return new GoogleTranscript(fileAsJSON); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters