Skip to content

Speech

Note

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, connect, translator

Properties

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.

Language wrappers

Examples:

A speech object with confidence set:
{
    "text" : "could you tell me my account balance please",
    "confidence" : 0.91
}
A speech object without confidence set:
{
    "text" : "could you tell me my account balance please"
}
A speech object with confidence set and a translation:
{
    "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:

Extract the details from a speech object with confidence set (final result):
var text = speech.Text;
// confidence is double
var confidence = speech.Confidence;
Extract the details from a speech object without confidence set (interim result):
var text = speech.Text;
// confidence is null
var confidence = speech.Confidence;
Extract the details from a speech object with a translation:
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:

Extract the details from a speech object with confidence set (final result):
var text = speech.Text;
// confidence is double
var confidence = speech.Confidence;
Extract the details from a speech object without confidence set (interim result):
var text = speech.Text;
// confidence is null
var confidence = speech.Confidence;
Extract the details from a speech object with a translation:
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:

Extract the details from a speech object with confidence set (final result):
var text = speech.Text;
// confidence is double
var confidence = speech.Confidence;
Extract the details from a speech object without confidence set (interim result):
var text = speech.Text;
// confidence is null
var confidence = speech.Confidence;
Extract the details from a speech object with a translation:
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:

Extract the details from a speech object with confidence set (final result):
Dim text = speech.Text
' confidence Is double
Dim confidence = speech.Confidence
Extract the details from a speech object without confidence set (interim result):
Dim text = speech.Text
' confidence Is null
Dim confidence = speech.Confidence
Extract the details from a speech object with a translation:
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:

Extract the details from a speech object with confidence set (final result):
Dim text = speech.Text
' confidence Is double
Dim confidence = speech.Confidence
Extract the details from a speech object without confidence set (interim result):
Dim text = speech.Text
' confidence Is null
Dim confidence = speech.Confidence
Extract the details from a speech object with a translation:
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:

Extract the details from a speech object with confidence set (final result):
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...
                }
            }
        }
    }
}
Extract the details from a speech object without confidence set (interim result):
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...
                }
            }
        }
    }
}
Extract the details from a speech object with a translation:
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:

Extract the details from a speech object with confidence set (final result):
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))
Extract the details from a speech object without confidence set (interim result):
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))
Extract the details from a speech object with a translation:
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:

Extract the details from a speech object with confidence set (final result)
$text = $speech->getText();
$confidence = $speech->getConfidence();
/* $confidence is float */
Extract the details from a speech object without confidence set (interim result)
$text = $speech->getText();
$confidence = $speech->getConfidence();
/* $confidence is null */
Extract the details from a speech object with a translation
$text = $speech->getText();
$confidence = $speech->getConfidence();
/* $confidence is float */
$translation = $speech->getTranslation();