Speech
REST API Version 2.0 only.
Defines a textual representation of a section of speech obtained during transcription.
Used by actions get input, run speech menu, start transcription and connect with a translator.
language wrappers and examples
It has the following properties:
Property | Availability | Description |
---|---|---|
text | always | A string of text representing a section of speech that was recognised. |
confidence | not guaranteed to be present | A floating point value indicating the confidence that this text matches what was spoken. In the range 0.0 – 1.0 where 1.0 is greatest confidence. This may be present only for final results and for the first alternative speech result object.
|
translation | final results when translation is enabled | A string of text representing a translation of the text . |
Examples:
{
"text" : "could you tell me my account balance please",
"confidence" : 0.91
}
{
"text" : "could you tell me my account balance please"
}
{
"text" : "hello my friend",
"confidence" : 0.91,
"translation" : "bonjour mon ami"
}
Speech Class
Namespace: Aculab.Cloud.RestAPIWrapper
Assembly: Aculab.Cloud.RestAPIWrapper.dll
A class representing a single section of transcribed speech.
public class Speech
{
// Members
public string Text;
public double? Confidence;
public string Translation;
public override string ToString();
}
Examples:
var text = speech.Text;
// confidence is double
var confidence = speech.Confidence;
var text = speech.Text;
// confidence is null
var confidence = speech.Confidence;
var text = speech.Text;
var confidence = speech.Confidence;
var translation = speech.Translation;
public class Speech
{
// Members
public string Text;
public double? Confidence;
public string Translation;
public override string ToString();
}
Examples:
var text = speech.Text;
// confidence is double
var confidence = speech.Confidence;
var text = speech.Text;
// confidence is null
var confidence = speech.Confidence;
var text = speech.Text;
var confidence = speech.Confidence;
var translation = speech.Translation;
public class Speech
{
// Members
public string Text;
public double? Confidence;
public string Translation;
public override string ToString();
}
Examples:
var text = speech.Text;
// confidence is double
var confidence = speech.Confidence;
var text = speech.Text;
// confidence is null
var confidence = speech.Confidence;
var text = speech.Text;
var confidence = speech.Confidence;
var translation = speech.Translation;
Speech Class
Namespace: Aculab.Cloud.RestAPIWrapper
Assembly: Aculab.Cloud.RestAPIWrapper.dll
A class representing a single section of transcribed speech.
Public Class Speech
' Members
Public Property Text As String
Public Property Confidence As Double?
Public Property Translation As String
Public Overrides Function ToString() As String
End Class
Examples:
Dim text = speech.Text
' confidence Is double
Dim confidence = speech.Confidence
Dim text = speech.Text
' confidence Is null
Dim confidence = speech.Confidence
Dim text = speech.Text
Dim confidence = speech.Confidence
Dim translation = speech.Translation
Public Class Speech
' Members
Public Property Text As String
Public Property Confidence As Double?
Public Property Translation As String
Public Overrides Function ToString() As String
End Class
Examples:
Dim text = speech.Text
' confidence Is double
Dim confidence = speech.Confidence
Dim text = speech.Text
' confidence Is null
Dim confidence = speech.Confidence
Dim text = speech.Text
Dim confidence = speech.Confidence
Dim translation = speech.Translation
class Speech
Represents a section of transcribed speech.
Class synopsis:
// Members:
public String getText()
public double getConfidence()
public String getTranslation()
Examples:
TelephonyRequest myRequest = new TelephonyRequest(request);
GetInputResult getInputResult = (GetInputResult)myRequest.getInstanceInfo().getActionResult();
if (getInputResult.getInputType() == "speech")
{
List<Phrase> phrase_list = getInputResult.getSpeechInput();
for (Phrase phrase : phrase_list)
{
if (phrase.getFinal() == true)
{
List<Speech> speech_list = phrase.getAlternatives();
for (Speech speech : speech_list)
{
double confidence = speech.getConfidence();
if (confidence >= 0)
{
String text = speech.getText();
// Your code here...
}
}
}
}
}
TelephonyRequest myRequest = new TelephonyRequest(request);
GetInputResult getInputResult = (GetInputResult)myRequest.getInstanceInfo().getActionResult();
if (getInputResult.getInputType() == "speech")
{
List<Phrase> phrase_list = getInputResult.getSpeechInput();
for (Phrase phrase : phrase_list)
{
if (phrase.getFinal() == true)
{
List<Speech> speech_list = phrase.getAlternatives();
for (Speech speech : speech_list)
{
//Note. getConfidence() returns -1 when
//the confidence element is missing from the result.
double confidence = speech.getConfidence();
if (confidence < 0)
{
String text = speech.getText();
// Your code here...
}
}
}
}
}
TranslatorTranscriptionResult transcriptionResult = (TranslatorTranscriptionResult)ourRequest.getInstanceInfo().getActionResult();
List<Phrase> phrases = transcriptionResult.getTranscription();
for (Phrase phrase : phrases)
{
if (phrase.getFinal() == true)
{
List<Speech> speech_list = phrase.getAlternatives();
Speech speech = speech_list.get(0);
String text = speech.getText();
double confidence = speech.getConfidence();
String translation = speech.getTranslation();
// Your code here...
}
}
TelephonyRequest.get_action_result()
The Speech support class is represented by a dictionary. These may be found within the Action Result.
Examples:
my_request = TelephonyRequest(request)
action_result = my_request.get_action_result()
if action_result.get("action") == "get_input":
result = action_result.get("result")
if result.get("input_type") == "speech":
phrases = result.get("speech_input")
for phrase in phrases:
alternatives = phrase.get("alternatives")
for alternative in alternatives:
if 'confidence' in alternative:
text = alternative.get("text")
confidence = alternative.get("confidence")
print("text={} confidence={}".format(text, confidence))
my_request = TelephonyRequest(request)
action_result = my_request.get_action_result()
if action_result.get("action") == "get_input":
result = action_result.get("result")
if result.get("input_type") == "speech":
phrases = result.get("speech_input")
for phrase in phrases:
alternatives = phrase.get("alternatives")
for alternative in alternatives:
if 'confidence' not in alternative:
text = alternative.get("text")
print("text={} confidence is null".format(text))
my_request = TelephonyRequest(request)
action_result = my_request.get_action_result()
if action_result.get("action") == "connect.translator":
transcription_result = action_result.get("result")
phrases = transcription_result.get("transcription")
for phrase in phrases:
final = phrase.get("final")
if final:
alternatives = phrase.get("alternatives")
speech = alternatives[0]
confidence = speech.get("confidence")
text = speech.get("text")
translation = speech.get("translation")
# Your code here...
The Speech class
Introduction
Represents a section of transcribed speech.
Class synopsis
class Speech extends PropertyHolder {
/* methods */
public float|null getConfidence()
public string getText()
public string|null getTranslation()
}
Examples:
$text = $speech->getText();
$confidence = $speech->getConfidence();
/* $confidence is float */
$text = $speech->getText();
$confidence = $speech->getConfidence();
/* $confidence is null */
$text = $speech->getText();
$confidence = $speech->getConfidence();
/* $confidence is float */
$translation = $speech->getTranslation();