Phrase
REST API Version 2.0 only.
Defines one or more alternative transcriptions from a single section of speech.
Used by actions get input, start transcription and connect with a translator.
language wrappers and examples
It contains the following properties:
Property | Availability | Description |
---|---|---|
alternatives | always | An array of 1 or more speech objects up to a maximum of max alternatives starting with the most confident. |
direction | not available if the transcription is running in mixed mode. | inbound or outbound . Whether this phrase was recognised from the inbound or outbound direction on the call. This will be inbound for a result generated by a get input action or a translator. |
call | only for translator generated results. | primary or secondary . Whether this phrase was recognised from the primary or secondary call. |
stability | only for interim results (final = false) | An estimate of how stable this interim result is and therefore a representation of how likely the speech recognition will change this result. Valid range is from 0.0 (unstable) to 1.0 (completely stable). |
final | always | If true, the speech recognition has recognised this distinct phrase and finished analysing it. If false, this phrase object contains an interim result that may change in subsequent results. |
Examples:
{
"alternatives" :
[
{
"text" : "could you tell me my account balance please",
"confidence" : 0.91
}
],
"direction" : "inbound",
"final" : true
}
{
"alternatives" :
[
{
"text" : "could you tell me my account balance please"
}
],
"direction" : "inbound",
"stability" : 0.24,
"final" : false
}
{
"alternatives" :
[
{
"text" : "hello my friend",
"confidence" : 0.91,
"translation" : "bonjour mon ami"
}
],
"call" : "primary",
"direction" : "inbound",
"final" : true
}
Phrase Class
Namespace: Aculab.Cloud.RestAPIWrapper
Assembly: Aculab.Cloud.RestAPIWrapper.dll
The direction of transcribed audio on a call.
public class Phrase
{
// Members
public List<Speech> Alternatives;
public AudioDirection Direction;
public double? Stability;
public bool Final;
public string Call;
public override string ToString();
}
Examples:
if (phrase.Final)
{
var direction = phrase.Direction;
var firstAlternative = phrase.Alternatives[0];
var text = firstAlternative.Text;
var confidence = firstAlternative.Confidence;
}
if (!phrase.Final)
{
var direction = phrase.Direction;
var stability = phrase.Stability;
var firstAlternative = phrase.Alternatives[0];
var text = firstAlternative.Text;
}
var call = phrase.Call;
var alternatives = phrase.Alternatives;
var speech = alternatives.First();
var translation = speech.Translation;
public class Phrase
{
// Members
public List<Speech> Alternatives;
public AudioDirection Direction;
public double? Stability;
public bool Final;
public string Call;
public override string ToString();
}
Examples:
if (phrase.Final)
{
var direction = phrase.Direction;
var firstAlternative = phrase.Alternatives[0];
var text = firstAlternative.Text;
var confidence = firstAlternative.Confidence;
}
if (!phrase.Final)
{
var direction = phrase.Direction;
var stability = phrase.Stability;
var firstAlternative = phrase.Alternatives[0];
var text = firstAlternative.Text;
}
var call = phrase.Call;
var alternatives = phrase.Alternatives;
var speech = alternatives.First();
var translation = speech.Translation;
public class Phrase
{
// Members
public List<Speech> Alternatives;
public AudioDirection Direction;
public double? Stability;
public bool Final;
public string Call;
public override string ToString();
}
Examples:
if (phrase.Final)
{
var direction = phrase.Direction;
var firstAlternative = phrase.Alternatives[0];
var text = firstAlternative.Text;
var confidence = firstAlternative.Confidence;
}
if (!phrase.Final)
{
var direction = phrase.Direction;
var stability = phrase.Stability;
var firstAlternative = phrase.Alternatives[0];
var text = firstAlternative.Text;
}
var call = phrase.Call;
var alternatives = phrase.Alternatives;
var speech = alternatives.First();
var translation = speech.Translation;
Phrase Class
Namespace: Aculab.Cloud.RestAPIWrapper
Assembly: Aculab.Cloud.RestAPIWrapper.dll
The direction of transcribed audio on a call.
Public Class Phrase
' Members
Public Property Alternatives As List(Of Speech)
Public Property Direction As Audiodirection
Public Property Stability As Double?
Public Property Final As Bool
Public Property Call As String
Public Overrides Function ToString() As String
End Class
Examples:
If phrase.Final Then
Dim direction = phrase.Direction
Dim firstAlternative = phrase.Alternatives(0)
Dim text = firstAlternative.Text
Dim confidence = firstAlternative.Confidence
End If
If Not phrase.Final Then
Dim direction = phrase.Direction
Dim stability = phrase.Stability
Dim firstAlternative = phrase.Alternatives(0)
Dim text = firstAlternative.Text
End If
Dim thisCall = phrase.Call
Dim alternatives = phrase.Alternatives
Dim speech = alternatives.First
Dim translation = speech.Translation
Public Class Phrase
' Members
Public Property Alternatives As List(Of Speech)
Public Property Direction As Audiodirection
Public Property Stability As Double?
Public Property Final As Bool
Public Property Call As String
Public Overrides Function ToString() As String
End Class
Examples:
If phrase.Final Then
Dim direction = phrase.Direction
Dim firstAlternative = phrase.Alternatives(0)
Dim text = firstAlternative.Text
Dim confidence = firstAlternative.Confidence
End If
If Not phrase.Final Then
Dim direction = phrase.Direction
Dim stability = phrase.Stability
Dim firstAlternative = phrase.Alternatives(0)
Dim text = firstAlternative.Text
End If
Dim thisCall = phrase.Call
Dim alternatives = phrase.Alternatives
Dim speech = alternatives.First
Dim translation = speech.Translation
class Phrase
A class representing a single spoken phrase that is in the process of being transcribed from a call.
Class synopsis:
// Members:
public List<Speech> getAlternatives()
public String getDirection()
public String getCall()
public double getStability()
public boolean getFinal()
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)
{
String direction = phrase.getDirection();
if (phrase.getFinal() == true)
{
List<Speech> speech_list = phrase.getAlternatives();
Speech speech = speech_list.get(0);
String text = speech.getText();
double confidence = speech.getConfidence();
// 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)
{
String direction = phrase.getDirection();
if (phrase.getFinal() == false)
{
List<Speech> speech_list = phrase.getAlternatives();
Speech speech = speech_list.get(0);
double stability = phrase.getStability();
String text = speech.getText();
// Your code here...
}
}
}
TranslatorTranscriptionResult transcriptionResult = (TranslatorTranscriptionResult)ourRequest.getInstanceInfo().getActionResult();
List<Phrase> phrases = transcriptionResult.getTranscription();
for (Phrase phrase : phrases)
{
String call = phrase.getCall();
String direction = phrase.getDirection();
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 Phrase 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:
direction = phrase.get("direction")
final = phrase.get("final")
if final:
alternatives = phrase.get("alternatives")
speech = alternatives[0]
confidence = speech.get("confidence")
text = speech.get("text")
# Your code here...
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:
final = phrase.get("final")
direction = phrase.get("direction")
if not final:
alternatives = phrase.get("alternatives")
speech = alternatives[0]
stability = phrase.get("stability")
text = speech.get("text")
# Your code here...
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:
call = phrase.get("call")
direction = phrase.get("direction")
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 Phrase class
Introduction
Represents a single spoken phrase.
Class synopsis
class Phrase extends PropertyHolder {
/* methods */
public array[Speech] getAlternatives()
public string|null getDirection()
public float|null getStability()
public boolean getFinal()
public string|null getCall()
}
Examples:
if ($phrase->getFinal()) {
$dir = $phrase->getDirection();
$alternatives = $phrase->getAlternatives();
$speech = array_shift($alternatives);
if ($speech) {
$text = $speech->getText();
$confidence = $speech->getConfidence();
}
}
if (!$phrase->getFinal()) {
$dir = $phrase->getDirection();
$stability = $phrase->getStability();
$alternatives = $phrase->getAlternatives();
$speech = array_shift($alternatives);
if ($speech) {
$text = $speech->getText();
}
}
$call = $phrase->getCall();
$alternatives = $phrase->getAlternatives();
$speech = array_shift($alternatives);
if ($speech) {
$translation = $speech->getTranslation();
}