Using Speech-to-Text in Test Cases¶
There are two ways of accessing speech-to-text functionality:
Via the built-in
Via the speech-to-text Stepdef
The Speech-to-Text step performs recognition on a given file, which is specified as a reference to an object in the Scenario Execution Context, and stores the result in the specified identifier in the Scenario Execution Context. The step will fail if the recognition fails to produce any results for the given audio file.
perform speech-to-text recognition on <audioFile Identifier> with language <language Language> and save as <result Identifier>
audioFile - The name of the scenario execution context object that contains the audio file to recognize
language - The same language as specified in the
SpeechToTextmodel, which must be supported by the Google Cloud Speech-to-Text API
result - The scenario execution object key where the recognized text should be stored
Feature File Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Feature: SpeechToText Scenario: speech-to-text Given a phone as A: * of type Android * with profile audioService And A starts a call to "123456789" as call1: * caller records audio from connect to disconnect * call duration is 5 seconds And within 20 seconds, expect the call call1 to connect And within 30 seconds, expect the call call1 to disconnect Then perform speech-to-text recognition on call1.recordings.A.connect_to_disconnect with language en-US and save as RESULT And verify RESULT == "expected recognized text"
Speech-to-Text Stepdefs and Models ¶
The Speech-To-Text Built-ins and File Built-ins provide access to the audio file that will be recognized by intaQt. These functions may be combined.
Speech to Text Built-in ¶
The Speech-to-Text built-in provides a function that takes the audio file and language as parameters and returns an object containing the recognized test. The audio file must be accessed through File Built-ins, which are described in the following section.
<speechToText Result> := SpeechToText.recognize(<audioFile File>, <language String>)
The recognition result is an object containing information about the status of the operation and the recognized text:
assert result.isOk() println(result.text) // text is valid only if isOk() is true
audioFile - A file as provided by
language - One of the languages supported by the Google Cloud Speech-to-Text API
speechToText := SpeechToText.recognize(audioFile, "de-De")
File Built-ins ¶
File.fromSystem Built-ins may be used to access the audio files used with the speech-to-text stepdef. Additional information is available in the File Built-ins section.
File From Project ¶
This function returns the file from the current execution context's project folder.
<file File> := File.fromProject(<path String>)
The specified file.
- path - The relative path to the project root folder
audioFile := File.fromProject("audio.wav")
File From System ¶
This function creates a new file instance by converting the specified path name string into an abstract path name. If the specified string is empty, then the result is an empty abstract path name.
<file File> := File.fromSystem(<pathname String>)
The new file instance.
- pathname - The path's name
Example 1 - Allocating the File with Its Global Path from the System
audioFile := File.fromSystem("audio.wav")
Combining the SpeechToText and File Built-ins ¶
The example below demonstrates a Stepdef that accesses the audio file using the File Built-ins and then uses the
SpeechToText Built-in to recognize the text.
1 2 3 4 5 6 7
stepdef "do speech-to-text" audioFile := File.fromProject("audio.wav") result := SpeechToText.recognize(audioFile, "de-DE") assert result.isOk() println(result.text) end