right  Talk To Us!

translator

  Available in REST API Version 2 and later.

This represents an AI translator. The AI translator uses Speech Recognition on the inbound audio of the primary and secondary calls of a connect action. The translations of the recognised speech are played simultaneously to both calls using Text-To-Speech (TTS). The translator can also send transcriptions of the recognised speech and the translation played to a results page.

A translator uses two speech recognition streams. The service must be configured so that the application will have two streams available when the connect action runs.

Note that using a translator is a chargeable feature.

Used by action connect

language wrappers and examples

It contains the following properties:

Property Required/Optional Default Description
primary required - A call translation options object that configures how to translate the audio from the primary call.
secondary required - A call translation options object that configures how to translate the audio from the secondary call.
transcription results page optional A web page request object that defines the web page that to receive transcription results. The request to this page happens asynchronously and its response is not considered part of the application flow.
id optional "" A user-defined string that can be used to uniquely identify each particular translator in results sent to the transcription results page.

Transcription Results

Each transcription result has the speech recognised along with the corresponding translation. They are sent to the transcription results page in an action result as they become available. The action in the action result object will be connect.translator

PropertyAvailabilityDescription
transcriptionalwaysAn array of phrase objects representing sequential parts of the recognised speech.
completedalwaystrue or false. true indicates that this is the last result produced by the translator.
idalwaysThe string identifying the translator, as specified in the translator object.

Note that results are not returned to the application directly, but to the results page. A page that receives a transcription result should respond with a 204 response code indicating no content.


  • Examples:


    • Create a translator object:

      	{
      		"primary" : {
      			"speech_recognition_options" : {
      				"language" : "en-GB",
      				"speech_model_options" : {
      					"model" : "latest_long"
      				}
      			},
      			"tts_voice" : "French France Female Polly Lea"
      		},
      		"secondary" : {
      			"speech_recognition_options" : {
      				"language" : "fr-FR",
      				"speech_model_options" : {
      					"model" : "phone_call",
      					"enhanced" : true
      				}
      			},
      			"translation_options": {
      				"source_language" : "fr",
      				"target_language" : "en"
      			},
      			"tts_voice" : "English UK Female Polly Amy"
      		}
      	}
      
    • Create a translator object with transcriptions enabled:

      	{
      		"primary" : {
      			"speech_recognition_options" : {
      				"language" : "en-GB",
      				"speech_model_options" : {
      					"model" : "latest_long"
      				}
      			},
      			"tts_voice" : "French France Female Polly Lea"
      		},
      		"secondary" : {
      			"speech_recognition_options" : {
      				"language" : "fr-FR",
      				"speech_model_options" : {
      					"model" : "phone_call",
      					"enhanced" : true
      				}
      			},
      			"translation_options": {
      				"source_language" : "fr",
      				"target_language" : "en"
      			},
      			"tts_voice" : "English UK Female Polly Amy"
      		},
      		"transcription_results_page" : {
      			"url" : "transcription_results_page"
      		},
      		"id" : "translator1234"
      	}
      

      The following are examples of the results that may be sent to the transcription_results page:

      Primary result:

      "action_result" :
      {
      	"action" : "connect",
      	"result" :
      	{
      		"completed" : false,
      		"id" : "translator1234",
      		"transcription" :
      		[
      			{
      				"alternatives" :
      				[
      					{
      						"confidence" : 0.97,
      						"text" : "hello my friend",
      						"translation" : "bonjour mon ami"
      					}
      				],
      				"call" : "primary",
      				"direction" : "inbound",
      				"final" : true
      			}
      		]
      	}
      }
      

      Secondary result:

      "action_result" :
      {
      	"action" : "connect.translator",
      	"result" :
      	{
      		"completed" : false,
      		"id" : "translator1234",
      		"transcription" :
      		[
      			{
      				"alternatives" :
      				[
      					{
      						"confidence" : 0.97,
      						"text" : "au revoir pour le moment",
      						"translation" : "goodbye for now"
      					}
      				],
      				"call" : "secondary",
      				"direction" : "inbound",
      				"final" : true
      			}
      		]
      	}
      }
      
  • Translator Class
    Namespace: Aculab.Cloud.RestAPIWrapper
    Assembly: Aculab.Cloud.RestAPIWrapper.dll

    Construct a translator object that represents an AI translator that translates both primary and secondary calls that have been connected by the connect action.

    • public class Translator 
      {
          // Constructors
          public Translator(CallTranslationOptions primaryOptions, CallTranslationOptions secondaryOptions);
      
          // Members
          public string Id;
          public WebPageRequest TranscriptionResultsPage;
      }
      

      Examples:

      • Create a translator object:

        var primaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "en-GB",
                SpeechModelOptions = new SpeechModelOptions(model: "latest_long")
            },
            TTSVoice = "French France Female Polly Lea"
        };
        
        var secondaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "fr-FR",
                SpeechModelOptions = new SpeechModelOptions(model: "phone_call", enhanced: true)
            },
            TTSVoice = "English UK Female Polly Amy",
            TranslationOptions = new TranslationOptions(sourceLanguage: "fr", targetLanguage: "en")
        };
        
        var translator = new Translator(primaryOptions, secondaryOptions);
        
      • Create a translator object with transcriptions enabled:

        var primaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "en-GB",
                SpeechModelOptions = new SpeechModelOptions(model: "latest_long")
            },
            TTSVoice = "French France Female Polly Lea"
        };
        
        var secondaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "fr-FR",
                SpeechModelOptions = new SpeechModelOptions(model: "phone_call", enhanced: true)
            },
            TTSVoice = "English UK Female Polly Amy",
            TranslationOptions = new TranslationOptions(sourceLanguage: "fr", targetLanguage: "en")
        };
        
        var translator = new Translator(primaryOptions, secondaryOptions)
        {
            TranscriptionResultsPage = new WebPageRequest("transcriptionResultsPage.aspx"),
            Id = "translator1234"
        };
        

        Extract the transcription from the action result:

        var telephonyRequest = new TelephonyRequest(Request);
        
        var transcriptionResult = (TranslatorTranscriptionResult)telephonyRequest.InstanceInfo.ActionResult;
        var completed = transcriptionResult.Completed;
        var id = transcriptionResult.Id;
        var phrases = transcriptionResult.Transcription;
        foreach (var phrase in phrases)
        {
            var call = phrase.Call;
            var direction = phrase.Direction;
            var alternatives = phrase.Alternatives;
            foreach (var alternative in alternatives)
            {
                var text = alternative.Text;
                var confidence = alternative.Confidence;
                var translation = alternative.Translation;
                // process final speech result...
            }
        }
        
    • public class Translator 
      {
          // Constructors
          public Translator(CallTranslationOptions primaryOptions, CallTranslationOptions secondaryOptions);
      
          // Members
          public string Id;
          public WebPageRequest TranscriptionResultsPage;
      }
      

      Examples:

      • Create a translator object:

        var primaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "en-GB",
                SpeechModelOptions = new SpeechModelOptions(model: "latest_long")
            },
            TTSVoice = "French France Female Polly Lea"
        };
        
        var secondaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "fr-FR",
                SpeechModelOptions = new SpeechModelOptions(model: "phone_call", enhanced: true)
            },
            TTSVoice = "English UK Female Polly Amy",
            TranslationOptions = new TranslationOptions(sourceLanguage: "fr", targetLanguage: "en")
        };
        
        var translator = new Translator(primaryOptions, secondaryOptions);
        
      • Create a translator object with transcriptions enabled:

        var primaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "en-GB",
                SpeechModelOptions = new SpeechModelOptions(model: "latest_long")
            },
            TTSVoice = "French France Female Polly Lea"
        };
        
        var secondaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "fr-FR",
                SpeechModelOptions = new SpeechModelOptions(model: "phone_call", enhanced: true)
            },
            TTSVoice = "English UK Female Polly Amy",
            TranslationOptions = new TranslationOptions(sourceLanguage: "fr", targetLanguage: "en")
        };
        
        var translator = new Translator(primaryOptions, secondaryOptions)
        {
            TranscriptionResultsPage = new WebPageRequest("transcriptionResultsPage.aspx"),
            Id = "translator1234"
        };
        

        Extract the transcription from the action result:

        var telephonyRequest = new TelephonyRequest(Request);
        
        var transcriptionResult = (TranslatorTranscriptionResult)telephonyRequest.InstanceInfo.ActionResult;
        var completed = transcriptionResult.Completed;
        var id = transcriptionResult.Id;
        var phrases = transcriptionResult.Transcription;
        foreach (var phrase in phrases)
        {
            var call = phrase.Call;
            var direction = phrase.Direction;
            var alternatives = phrase.Alternatives;
            foreach (var alternative in alternatives)
            {
                var text = alternative.Text;
                var confidence = alternative.Confidence;
                var translation = alternative.Translation;
                // process final speech result...
            }
        }
        
    • public class Translator 
      {
          // Constructors
          public Translator(CallTranslationOptions primaryOptions, CallTranslationOptions secondaryOptions);
      
          // Members
          public string Id;
          public WebPageRequest TranscriptionResultsPage;
      }
      

      Examples:

      • Create a translator object:

        var primaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "en-GB",
                SpeechModelOptions = new SpeechModelOptions(model: "latest_long")
            },
            TTSVoice = "French France Female Polly Lea"
        };
        
        var secondaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "fr-FR",
                SpeechModelOptions = new SpeechModelOptions(model: "phone_call", enhanced: true)
            },
            TTSVoice = "English UK Female Polly Amy",
            TranslationOptions = new TranslationOptions(sourceLanguage: "fr", targetLanguage: "en")
        };
        
        var translator = new Translator(primaryOptions, secondaryOptions);
        
      • Create a translator object with transcriptions enabled:

        var primaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "en-GB",
                SpeechModelOptions = new SpeechModelOptions(model: "latest_long")
            },
            TTSVoice = "French France Female Polly Lea"
        };
        
        var secondaryOptions = new CallTranslationOptions()
        {
            SpeechRecognitionOptions = new SpeechRecognitionOptions()
            {
                Language = "fr-FR",
                SpeechModelOptions = new SpeechModelOptions(model: "phone_call", enhanced: true)
            },
            TTSVoice = "English UK Female Polly Amy",
            TranslationOptions = new TranslationOptions(sourceLanguage: "fr", targetLanguage: "en")
        };
        
        var translator = new Translator(primaryOptions, secondaryOptions)
        {
            TranscriptionResultsPage = new WebPageRequest("transcriptionResultsPage.aspx"),
            Id = "translator1234"
        };
        

        Extract the transcription from the action result:

        var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
        
        var transcriptionResult = (TranslatorTranscriptionResult)telephonyRequest.InstanceInfo.ActionResult;
        var completed = transcriptionResult.Completed;
        var id = transcriptionResult.Id;
        var phrases = transcriptionResult.Transcription;
        foreach (var phrase in phrases)
        {
            var call = phrase.Call;
            var direction = phrase.Direction;
            var alternatives = phrase.Alternatives;
            foreach (var alternative in alternatives)
            {
                var text = alternative.Text;
                var confidence = alternative.Confidence;
                var translation = alternative.Translation;
                // process final speech result...
            }
        }
        
  • Translator Class
    Namespace: Aculab.Cloud.RestAPIWrapper
    Assembly: Aculab.Cloud.RestAPIWrapper.dll

    Construct a translator object that represents an AI translator that translates both primary and secondary calls that have been connected by the connect action.

    • Public Class Translator
          ' Constructors
          Public Sub New (primaryOptions As Calltranslationoptions, secondaryOptions As Calltranslationoptions)
      
          ' Members
          Public Property Id As String
          Public Property TranscriptionResultsPage As Webpagerequest
      End Class
      

      Examples:

      • Create a translator object

        Dim primaryOptions = New CallTranslationOptions With {
            .SpeechRecognitionOptions = New SpeechRecognitionOptions() With {
                .Language = "en-GB",
                .SpeechModelOptions = New SpeechModelOptions(model:="latest_long")
            },
            .TTSVoice = "French France Female Polly Lea"
        }
        
        Dim secondaryOptions = New CallTranslationOptions() With {
            .SpeechRecognitionOptions = New SpeechRecognitionOptions() With {
                .Language = "fr-FR",
                .SpeechModelOptions = New SpeechModelOptions(model:="phone_call", enhanced:=True)
            },
            .TTSVoice = "English UK Female Polly Amy",
            .TranslationOptions = New TranslationOptions() With {
                .SourceLanguage = "fr",
                .TargetLanguage = "en"
            }
        }
        
        Dim translator = New Translator(primaryOptions, secondaryOptions)
        
      • Create a translator object with transcriptions enabled

        Dim primaryOptions = New CallTranslationOptions With {
            .SpeechRecognitionOptions = New SpeechRecognitionOptions() With {
                .Language = "en-GB",
                .SpeechModelOptions = New SpeechModelOptions(model:="latest_long")
            },
            .TTSVoice = "French France Female Polly Lea"
        }
        
        Dim secondaryOptions = New CallTranslationOptions() With {
            .SpeechRecognitionOptions = New SpeechRecognitionOptions() With {
                .Language = "fr-FR",
                .SpeechModelOptions = New SpeechModelOptions(model:="phone_call", enhanced:=True)
            },
            .TTSVoice = "English UK Female Polly Amy",
            .TranslationOptions = New TranslationOptions() With {
                .SourceLanguage = "fr",
                .TargetLanguage = "en"
            }
        }
        
        Dim translator = New Translator(primaryOptions, secondaryOptions) With {
            .TranscriptionResultsPage = New WebPageRequest("transcriptionResultsPage.aspx"),
            .Id = "1234"
        }
        

        Extract the transcription from the action result:

        Dim telephonyRequest = New TelephonyRequest(Request)
        
        Dim transcriptionResult As TranslatorTranscriptionResult = telephonyRequest.InstanceInfo.ActionResult
        Dim completed = transcriptionResult.Completed
        Dim id = transcriptionResult.Id
        Dim phrases = transcriptionResult.Transcription
        For Each phrase In phrases
            Dim caller = phrase.Call
            Dim direction = phrase.Direction
            Dim alternatives = phrase.Alternatives
            For Each alternative In alternatives
                Dim Text = alternative.Text
                Dim confidence = alternative.Confidence
                Dim translation = alternative.Translation
                ' process final speech result...
            Next
        Next
        
    • Public Class Translator
          ' Constructors
          Public Sub New (primaryOptions As Calltranslationoptions, secondaryOptions As Calltranslationoptions)
      
          ' Members
          Public Property Id As String
          Public Property TranscriptionResultsPage As Webpagerequest
      End Class
      

      Examples:

      • Create a translator object

        Dim primaryOptions = New CallTranslationOptions With {
            .SpeechRecognitionOptions = New SpeechRecognitionOptions() With {
                .Language = "en-GB",
                .SpeechModelOptions = New SpeechModelOptions(model:="latest_long")
            },
            .TTSVoice = "French France Female Polly Lea"
        }
        
        Dim secondaryOptions = New CallTranslationOptions() With {
            .SpeechRecognitionOptions = New SpeechRecognitionOptions() With {
                .Language = "fr-FR",
                .SpeechModelOptions = New SpeechModelOptions(model:="phone_call", enhanced:=True)
            },
            .TTSVoice = "English UK Female Polly Amy",
            .TranslationOptions = New TranslationOptions() With {
                .SourceLanguage = "fr",
                .TargetLanguage = "en"
            }
        }
        
        Dim translator = New Translator(primaryOptions, secondaryOptions)
        
      • Create a translator object with transcriptions enabled

        Dim primaryOptions = New CallTranslationOptions With {
            .SpeechRecognitionOptions = New SpeechRecognitionOptions() With {
                .Language = "en-GB",
                .SpeechModelOptions = New SpeechModelOptions(model:="latest_long")
            },
            .TTSVoice = "French France Female Polly Lea"
        }
        
        Dim secondaryOptions = New CallTranslationOptions() With {
            .SpeechRecognitionOptions = New SpeechRecognitionOptions() With {
                .Language = "fr-FR",
                .SpeechModelOptions = New SpeechModelOptions(model:="phone_call", enhanced:=True)
            },
            .TTSVoice = "English UK Female Polly Amy",
            .TranslationOptions = New TranslationOptions() With {
                .SourceLanguage = "fr",
                .TargetLanguage = "en"
            }
        }
        
        Dim translator = New Translator(primaryOptions, secondaryOptions) With {
            .TranscriptionResultsPage = New WebPageRequest("transcriptionResultsPage.aspx"),
            .Id = "1234"
        }
        

        Extract the transcription from the action result:

        Dim telephonyRequest = New TelephonyRequest(Request)
        
        Dim transcriptionResult As TranslatorTranscriptionResult = telephonyRequest.InstanceInfo.ActionResult
        Dim completed = transcriptionResult.Completed
        Dim id = transcriptionResult.Id
        Dim phrases = transcriptionResult.Transcription
        For Each phrase In phrases
            Dim caller = phrase.Call
            Dim direction = phrase.Direction
            Dim alternatives = phrase.Alternatives
            For Each alternative In alternatives
                Dim Text = alternative.Text
                Dim confidence = alternative.Confidence
                Dim translation = alternative.Translation
                ' process final speech result...
            Next
        Next
        
  • class Translator extends JSONElement

    Represents the Translator support class.

    Class synopsis:

    // Constructors:
    public Translator(CallTranslationOptions primary, CallTranslationOptions secondary)
    
    // Members:
    public void setTranscriptionResultsPage(WebPageRequest resultsPage)
    public void setID(String id)
    
    class TranslatorTranscriptionResult extends TranscriptionResult

    Represents a translator transcription result.

    Class synopsis:

    // Members Inherited from TranscriptionResult:
    public List<Phrase> getTranscription()
    public boolean getCompleted()
    public String getId()
    

    Examples:

    • Create a translator object:

      CallTranslationOptions primaryCTO = new CallTranslationOptions();
      CallTranslationOptions secondaryCTO = new CallTranslationOptions();
      
      {
          SpeechModelOptions speechModelOpts = new SpeechModelOptions();
          speechModelOpts.setModel("latest_long");
          SpeechRecognitionOptions speechRecognitionOpts = new SpeechRecognitionOptions();
          speechRecognitionOpts.setLanguage("en-GB");
          speechRecognitionOpts.setSpeechModelOptions(speechModelOpts);
      
          primaryCTO.setSpeechRecognitionOptions(speechRecognitionOpts);
          primaryCTO.setTTSVoice("French France Female Polly Lea");
      }
      
      {
          SpeechModelOptions speechModelOpts = new SpeechModelOptions();
          speechModelOpts.setModel("phone_call");
          speechModelOpts.setEnhanced(true);
          SpeechRecognitionOptions speechRecognitionOpts = new SpeechRecognitionOptions();
          speechRecognitionOpts.setLanguage("fr-FR");
          speechRecognitionOpts.setSpeechModelOptions(speechModelOpts);
      
          TranslationOptions translationOpts = new TranslationOptions();
          translationOpts.setSourceLanguage("fr");
          translationOpts.setTargetLanguage("en");
      
          secondaryCTO.setSpeechRecognitionOptions(speechRecognitionOpts);
          secondaryCTO.setTranslationOptions(translationOpts);
          secondaryCTO.setTTSVoice("English UK Female Polly Amy");
      }
      
      Translator translator = new Translator(primaryCTO, secondaryCTO);
      
    • Create a translator object with transcriptions enabled:

      CallTranslationOptions primaryCTO = new CallTranslationOptions();
      CallTranslationOptions secondaryCTO = new CallTranslationOptions();
      
      {
          SpeechModelOptions speechModelOpts = new SpeechModelOptions();
          speechModelOpts.setModel("latest_long");
          SpeechRecognitionOptions speechRecognitionOpts = new SpeechRecognitionOptions();
          speechRecognitionOpts.setLanguage("en-GB");
          speechRecognitionOpts.setSpeechModelOptions(speechModelOpts);
      
          primaryCTO.setSpeechRecognitionOptions(speechRecognitionOpts);
          primaryCTO.setTTSVoice("French France Female Polly Lea");
      }
      
      {
          SpeechModelOptions speechModelOpts = new SpeechModelOptions();
          speechModelOpts.setModel("phone_call");
          speechModelOpts.setEnhanced(true);
          SpeechRecognitionOptions speechRecognitionOpts = new SpeechRecognitionOptions();
          speechRecognitionOpts.setLanguage("fr-FR");
          speechRecognitionOpts.setSpeechModelOptions(speechModelOpts);
      
          TranslationOptions translationOpts = new TranslationOptions();
          translationOpts.setSourceLanguage("fr");
          translationOpts.setTargetLanguage("en");
      
          secondaryCTO.setSpeechRecognitionOptions(speechRecognitionOpts);
          secondaryCTO.setTranslationOptions(translationOpts);
          secondaryCTO.setTTSVoice("English UK Female Polly Amy");
      }
      
      WebPageRequest transcriptionResultsPage = new WebPageRequest("transcription_results_page");
      
      Translator translator = new Translator(primaryCTO, secondaryCTO);
      translator.setTranscriptionResultsPage(transcriptionResultsPage);
      translator.setID("translator1234");
      

      Extract the transcription from the action result:

      TranslatorTranscriptionResult transcriptionResult = (TranslatorTranscriptionResult)ourRequest.getInstanceInfo().getActionResult();
      String id = transcriptionResult.getId();
      boolean completed = transcriptionResult.getCompleted();
      List<Phrase> phrases = transcriptionResult.getTranscription();
      
      for (Phrase phrase : phrases)
      {
          String call = phrase.getCall();
          String dir = phrase.getDirection();
          List<Speech> alternatives = phrase.getAlternatives();
      
          for (Speech alternative : alternatives)
          {
              String text = alternative.getText();
              double confidence = alternative.getConfidence();
              String translation = alternative.getTranslation();
      
              /* process text and translation */
          }
      }
      
  • class Translator

    Represents the Translator support class.

    Class synopsis:

    # Translator object:
    Translator(primary, secondary)
    
    # Instance methods:
    Translator.set_transcription_results_page(resultsPage)
    Translator.set_id(id)
    
    Get Translator Transcription Result

    The Translator Transcription Result is represented by a dictionary. It is found within the action result for the transcription results page.

    Obtaining the Translator Transcription Result dictionary:

    my_request = TelephonyRequest(request)
    action_result = my_request.get_action_result()
    if action_result.get("action") == "connect.translator":
        transcription_result =  action_result.get("result")
    

    Examples:

    • Create a translator object:

      primarySMO = SpeechModelOptions()
      primarySMO.set_model("latest_long")
      primarySRO = SpeechRecognitionOptions()
      primarySRO.set_language("en-GB")
      primarySRO.set_speech_model_options(primarySMO)
      primaryCTO = CallTranslationOptions()
      primaryCTO.set_speech_recognition_options(primarySRO)
      primaryCTO.set_tts_voice("French France Female Polly Lea")
      
      secondarySMO = SpeechModelOptions()
      secondarySMO.set_model("phone_call")
      secondarySMO.set_enhanced(True)
      secondarySRO = SpeechRecognitionOptions()
      secondarySRO.set_language("fr-FR")
      secondarySRO.set_speech_model_options(secondarySMO)
      translationOpts = TranslationOptions()
      translationOpts.set_source_language("fr")
      translationOpts.set_target_language("en")
      secondaryCTO = CallTranslationOptions()
      secondaryCTO.set_speech_recognition_options(secondarySRO)
      secondaryCTO.set_translation_options(translationOpts)
      secondaryCTO.set_tts_voice("English UK Female Polly Amy")
      
      translator = Translator(primaryCTO, secondaryCTO)
      
    • Create a translator object with transcriptions enabled:

      primarySMO = SpeechModelOptions()
      primarySMO.set_model("latest_long")
      primarySRO = SpeechRecognitionOptions()
      primarySRO.set_language("en-GB")
      primarySRO.set_speech_model_options(primarySMO)
      primaryCTO = CallTranslationOptions()
      primaryCTO.set_speech_recognition_options(primarySRO)
      primaryCTO.set_tts_voice("French France Female Polly Lea")
      
      secondarySMO = SpeechModelOptions()
      secondarySMO.set_model("phone_call")
      secondarySMO.set_enhanced(True)
      secondarySRO = SpeechRecognitionOptions()
      secondarySRO.set_language("fr-FR")
      secondarySRO.set_speech_model_options(secondarySMO)
      translationOpts = TranslationOptions()
      translationOpts.set_source_language("fr")
      translationOpts.set_target_language("en")
      secondaryCTO = CallTranslationOptions()
      secondaryCTO.set_speech_recognition_options(secondarySRO)
      secondaryCTO.set_translation_options(translationOpts)
      secondaryCTO.set_tts_voice("English UK Female Polly Amy")
      
      translator = Translator(primaryCTO, secondaryCTO)
      
      translator.set_transcription_results_page(WebPage(url='transcription_results_page'))
      translator.set_id("translator1234")
      

      Extract the transcription from the action result:

      my_request = TelephonyRequest(request)
      action_result = my_request.get_action_result()
      
      if action_result.get("action") == "connect.translator":
      
          transcription_result = action_result.get("result")
      
          completed = transcription_result.get("completed")
          id = transcription_result.get("id")
          phrases = transcription_result.get("transcription")
      
          for phrase in phrases:
      
              call = phrase.get("call")
              direction = phrase.get("direction")
              alternatives = phrase.get("alternatives")
      
              for alternative in alternatives:
      
                  text = alternative.get("text")
                  confidence = alternative.get("confidence")
                  translation = alternative.get("translation")
                  # process text and translation
      
  • The Translator class

    Introduction

    Represents an AI translator.

    Class synopsis

    class Translator {
    
        /* methods */
        public __construct()
        public self setPrimaryCallTranslationOptions(CallTranslationOptions $opts)
        public self setSecondaryCallTranslationOptions(CallTranslationOptions $opts)
        public self setTranscriptionResultsPage(WebPageRequest|string $results_page, string $method = null)
        public self setID(string $id)
    }
    
    The TranslatorTranscriptionResult class

    Introduction

    Represents a translator transcription result.

    Class synopsis

    class TranslatorTranscriptionResult extends TranscriptionResult {
    
        /* inherited methods */
        public array[Phrase] getTranscription()
        public string getID()
        public boolean getCompleted()
        public string getAction()
        public boolean getInterrupted()
    }
    

    Examples:

    • Create a translator object:

      $translator = new Aculab\TelephonyRestAPI\Translator();
      
      $call_translation_options = new Aculab\TelephonyRestAPI\CallTranslationOptions();
      
      $speech_model_options = new \Aculab\TelephonyRestAPI\SpeechModelOptions();
      $speech_model_options->setModel("latest_long");
      $speech_recognition_options = new \Aculab\TelephonyRestAPI\SpeechRecognitionOptions();
      $speech_recognition_options->setLanguage("en-GB");
      $speech_recognition_options->setSpeechModelOptions($speech_model_options);
      $call_translation_options->setSpeechRecognitionOptions($speech_recognition_options);
      $call_translation_options->setTTSVoice("French France Female Polly Lea");
      $translator->setPrimaryCallTranslationOptions($call_translation_options);
      
      $call_translation_options = new Aculab\TelephonyRestAPI\CallTranslationOptions();
      $speech_model_options = new \Aculab\TelephonyRestAPI\SpeechModelOptions();
      $speech_model_options->setModel("phone_call")
          ->setEnhanced(true);
      $speech_recognition_options = new \Aculab\TelephonyRestAPI\SpeechRecognitionOptions();
      $speech_recognition_options->setLanguage("fr-FR");
      $speech_recognition_options->setSpeechModelOptions($speech_model_options);
      $translation_options = new Aculab\TelephonyRestAPI\TranslationOptions();
      $translation_options->setSourceLanguage('fr')
          ->setTargetLanguage('en');
      $call_translation_options->setSpeechRecognitionOptions($speech_recognition_options)
          ->setTranslationOptions($translation_options)
          ->setTTSVoice("English UK Female Polly Amy");
      $translator->setSecondaryCallTranslationOptions($call_translation_options);
      
    • Create a translator object with transcriptions enabled:

      $translator = new Aculab\TelephonyRestAPI\Translator();
      
      $call_translation_options = new Aculab\TelephonyRestAPI\CallTranslationOptions();
      
      $speech_model_options = new \Aculab\TelephonyRestAPI\SpeechModelOptions();
      $speech_model_options->setModel("latest_long");
      $speech_recognition_options = new \Aculab\TelephonyRestAPI\SpeechRecognitionOptions();
      $speech_recognition_options->setLanguage("en-GB");
      $speech_recognition_options->setSpeechModelOptions($speech_model_options);
      $call_translation_options->setSpeechRecognitionOptions($speech_recognition_options);
      $call_translation_options->setTTSVoice("French France Female Polly Lea");
      $translator->setPrimaryCallTranslationOptions($call_translation_options);
      
      $call_translation_options = new Aculab\TelephonyRestAPI\CallTranslationOptions();
      $speech_model_options = new \Aculab\TelephonyRestAPI\SpeechModelOptions();
      $speech_model_options->setModel("phone_call")
          ->setEnhanced(true);
      $speech_recognition_options = new \Aculab\TelephonyRestAPI\SpeechRecognitionOptions();
      $speech_recognition_options->setLanguage("fr-FR");
      $speech_recognition_options->setSpeechModelOptions($speech_model_options);
      $translation_options = new Aculab\TelephonyRestAPI\TranslationOptions();
      $translation_options->setSourceLanguage('fr')
          ->setTargetLanguage('en');
      $call_translation_options->setSpeechRecognitionOptions($speech_recognition_options)
          ->setTranslationOptions($translation_options)
          ->setTTSVoice("English UK Female Polly Amy");
      $translator->setSecondaryCallTranslationOptions($call_translation_options);
      
      $translator->setTranscriptionResultsPage("transcriptionResultsPage")
          ->setID("translator1234");
      

      Extract the transcription from the action result

      $info = \Aculab\TelephonyRestAPI\InstanceInfo::getInstanceInfo();
      
      $transcriptionResult = $info->getActionResult();
      
      $completed = $transcriptionResult->getCompleted();
      $id = $transcriptionResult->getID();
      $phrases = $transcriptionResult->getTranscription();
      foreach($phrases as $phrase) {
          $call = $phrase->getCall();
          $dir = $phrase->getDirection();
          $alternatives = $phrase->getAlternatives();
          foreach($alternatives as $speech) {
              if ($speech) {
                  $text = $speech->getText();
                  $confidence = $speech->getConfidence();
                  $translation = $speech->getTranslation();
                  /* process text and translation */
              }
          }
      }