Using Speech-to-Text in Test Cases¶
There are two ways of accessing speech-to-text functionality:
-
Via the built-in
SpeechToText
model -
Via the speech-to-text Stepdef
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 recognize speech in audio call1.recordings.A.connect_to_disconnect with language en-US as RESULT And verify RESULT == "expected recognized text" |
Speech-to-Text Steps¶
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.
Recognize File with Language ¶
Recognizes the the file according to its language. This step must be combined with the Speech-to-Text Built-in, recognizeWithLanguage.
Syntax
1 | recognize speech in audio <audioFile Identifier> with language <language Language> as <result Identifier> |
Parameters
-
audioFile - The name of the scenario execution context object that contains the audio file to recognize
-
language - The same language as specified in the
SpeechToText
model, 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
Example
1 | Then recognize speech in audio call1.recordings.A.connect_to_disconnect with language en-US as RESULT |
Recognize File with Profile ¶
Recognizes the the file according to its profile. This step must be combined with the Speech-to-Text Built-in, recognizeWithProfile.
Syntax
1 | recognize speech in audio <audioFile Identifier> with profile <profile Identifier> as <result Identifier> |
Parameters
-
audioFile - The name of the scenario execution context object that contains the audio file to recognize
-
profile - The profile, which must be a valid Speech-to-Text profile
- Configuration information is available here
-
result - The scenario execution object key where the recognized text should be stored
Example
1 | Then recognize speech in audio call1.recordings.A.connect_to_disconnect with language en-US as RESULT |
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-ins ¶
The Speech-to-Text Built-ins provide a function that takes one of the following as parameters:
-
The audio file and language
-
The audio file and profile
It returns an object containing the recognized test. The audio file must be accessed through File Built-ins, which are described in the following section.
Recognize With Language ¶
Recognizes the audio file according to its language. The associated Feature File must include a Recognize Step.
Syntax
1 | <speechToText Result> := SpeechToText.recognizeWithLanguage(<audioFile File>, <language String>) |
Returns
The recognition result is an object containing information about the status of the operation and the recognized text:
1 2 | assert result.isOk() println(result.text) // text is valid only if isOk() is true |
Parameters
-
audioFile - A file as provided by
File.fromProject
orFile.fromSystem
builtins -
language - One of the languages supported by the Google Cloud Speech-to-Text API
Example
1 | speechToText := SpeechToText.recognizeWithLanguage(audioFile, "de-De") |
Recognize With Profile ¶
Recognizes the audio file according to its profile. The associated Feature File must include a Recognize Step.
Syntax
1 | <speechToText Result> := SpeechToText.recognizeWithProfile(<audioFile File>, <profile String>) |
Returns
The recognition result is an object containing information about the status of the operation and the recognized text:
1 2 | assert result.isOk() println(result.text) // text is valid only if isOk() is true |
Parameters
-
audioFile - A file as provided by
File.fromProject
orFile.fromSystem
builtins -
profile - The profile, which must be a valid Speech-to-Text profile
- Configuration information is available here
Example
1 | speechToText := SpeechToText.recognizeWithProfile(audioFile, "speechProfile1") |
File Built-ins ¶
The File.fromProject
or 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.
Syntax
1 | <file File> := File.fromProject(<path String>) |
Returns
The specified file.
Parameter
- path - The relative path to the project root folder
Example
1 | 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.
Syntax
1 | <file File> := File.fromSystem(<pathname String>) |
Returns
The new file instance.
Parameter
- pathname - The path's name
Example 1 - Allocating the File with Its Global Path from the System
1 | 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.
Example
1 2 3 4 5 6 7 | stepdef "do speech-to-text" audioFile := File.fromProject("audio.wav") result := SpeechToText.recognizeWithLanguage(audioFile, "de-DE") assert result.isOk() println(result.text) end |