phrase

  Available in REST API Version 2 and later.

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:

PropertyAvailabilityDescription
alternativesalwaysAn array of 1 or more speech objects up to a maximum of max alternatives starting with the most confident.
directionnot 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.
callonly for translator generated results.primary or secondary. Whether this phrase was recognised from the primary or secondary call.
stabilityonly 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).
finalalwaysIf 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:


    • The final analysis of a phrase:

          {
      		"alternatives" :
      		[
      			{
      				"text" : "could you tell me my account balance please",
      				"confidence" : 0.91
      			}
      		],
      		"direction" : "inbound",
      		"final" : true
          }
      
    • The interim analysis of a phrase:

          {
      		"alternatives" :
      		[
      			{
      				"text" : "could you tell me my account balance please"
      			}
      		],
      		"direction" : "inbound",
      		"stability" : 0.24,
      		"final" : false
          }
      
    • The final analysis of a phrase from a translator:

          {
      		"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:

      • Extract the first final speech from a phrase:

        if (phrase.Final)
        {
            var direction = phrase.Direction;
            var firstAlternative = phrase.Alternatives[0];
            var text = firstAlternative.Text;
            var confidence = firstAlternative.Confidence;
        }
        
      • Extract the first interim speech from a phrase:

        if (!phrase.Final)
        {
            var direction = phrase.Direction;
            var stability = phrase.Stability;
            var firstAlternative = phrase.Alternatives[0];
            var text = firstAlternative.Text;
        }
        
      • Extract the call and translation from a phrase:

        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:

      • Extract the first final speech from a phrase:

        if (phrase.Final)
        {
            var direction = phrase.Direction;
            var firstAlternative = phrase.Alternatives[0];
            var text = firstAlternative.Text;
            var confidence = firstAlternative.Confidence;
        }
        
      • Extract the first interim speech from a phrase:

        if (!phrase.Final)
        {
            var direction = phrase.Direction;
            var stability = phrase.Stability;
            var firstAlternative = phrase.Alternatives[0];
            var text = firstAlternative.Text;
        }
        
      • Extract the call and translation from a phrase:

        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:

      • Extract the first final speech from a phrase:

        if (phrase.Final)
        {
            var direction = phrase.Direction;
            var firstAlternative = phrase.Alternatives[0];
            var text = firstAlternative.Text;
            var confidence = firstAlternative.Confidence;
        }
        
      • Extract the first interim speech from a phrase:

        if (!phrase.Final)
        {
            var direction = phrase.Direction;
            var stability = phrase.Stability;
            var firstAlternative = phrase.Alternatives[0];
            var text = firstAlternative.Text;
        }
        
      • Extract the call and translation from a phrase:

        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:

      • Extract the first final speech from a phrase:

        If phrase.Final Then
            Dim direction = phrase.Direction
            Dim firstAlternative = phrase.Alternatives(0)
            Dim text = firstAlternative.Text
            Dim confidence = firstAlternative.Confidence
        End If
        
      • Extract the first interim speech from a phrase:

        If Not phrase.Final Then
            Dim direction = phrase.Direction
            Dim stability = phrase.Stability
            Dim firstAlternative = phrase.Alternatives(0)
            Dim text = firstAlternative.Text
        End If
        
      • Extract the call and translation from a phrase

        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:

      • Extract the first final speech from a phrase:

        If phrase.Final Then
            Dim direction = phrase.Direction
            Dim firstAlternative = phrase.Alternatives(0)
            Dim text = firstAlternative.Text
            Dim confidence = firstAlternative.Confidence
        End If
        
      • Extract the first interim speech from a phrase:

        If Not phrase.Final Then
            Dim direction = phrase.Direction
            Dim stability = phrase.Stability
            Dim firstAlternative = phrase.Alternatives(0)
            Dim text = firstAlternative.Text
        End If
        
      • Extract the call and translation from a phrase

        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:

    • Extract the first final speech from a phrase:

      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...
              }
          }
      }
      
    • Extract the first interim speech from a phrase:

      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...
              }
          }
      }
      
    • Extract the call and translation from a phrase:

      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:

    • Extract the first final speech from a phrase:

      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...
      
    • Extract the first interim speech from a phrase:

      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...
      
    • Extract the call and translation from a phrase:

      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:

    • Extract the first final speech from a phrase:

      if ($phrase->getFinal()) {
          $dir = $phrase->getDirection();
          $alternatives = $phrase->getAlternatives();
          $speech = array_shift($alternatives);
          if ($speech) {
              $text = $speech->getText();
              $confidence = $speech->getConfidence();
          }
      }
      
    • Extract the first interim speech from a phrase:

      if (!$phrase->getFinal()) {
          $dir = $phrase->getDirection();
          $stability = $phrase->getStability();
          $alternatives = $phrase->getAlternatives();
          $speech = array_shift($alternatives);
          if ($speech) {
              $text = $speech->getText();
          }
      }
      
    • Extract the call and translation from a phrase:

      $call = $phrase->getCall();
      $alternatives = $phrase->getAlternatives();
      $speech = array_shift($alternatives);
      if ($speech) {
          $translation = $speech->getTranslation();
      }