Text-to-speech

The AppFramework provides a Speech QML plug-in for text-to-speech functionality that enables applications created with AppStudio to support accessibility features such as text-to-speech with voice modulation. This TextToSpeech component can be used to provide audio feedback to end users, including aid for visually-impaired users and providing information when the user isn't looking at their device. To use this functionality, you must first include the following import statement:

Use dark colors for code blocksCopy
1
import ArcGIS.AppFramework.Speech 1.0

Convert text to speech

The core of the TextToSpeech component is the say method, which converts submitted text into a spoken statement. The following code sample demonstrates it in use, reading the contents of a text area when a button is clicked:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
ColumnLayout {
    anchors {
        fill: parent
        margins: 4 * AppFramework.displayScaleFactor
    }

    TextToSpeech {
        id: textToSpeech
    }

    Rectangle {
        Layout.fillWidth: true
        Layout.preferredHeight: 200 * scaleFactor
        color: transparent
        border.color: black
        border.width: 1 * scaleFactor

        TextArea {
            id: sayText
            width: parent.width
            Material.accent: "#8f499c"
            padding: 5 * scaleFactor
            selectByMouse: true
            wrapMode: TextEdit.WrapAnywhere
            text: "This text will be read."
        }
    }

    Button {
        Layout.fillWidth: true
        text: "Say it"
        onClicked: {
            textToSpeech.say(sayText.text);
        }
    }
}

Voice modification

The voice produced by the TextToSpeech component can be controlled by modifying the volume , pitch , and rate properties of the component. Each of these properties is stored as a double-precision integer (one decimal point), with the default value being 50. The following code sample provides a slider for the volume property:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
Slider {
    id: volumeSlider
    Layout.fillWidth: true
    Layout.leftMargin: 10 * AppFramework.displayScaleFactor
    Layout.rightMargin: Layout.leftMargin
    from: 0
    to: 100
    stepSize: 1
    onValueChanged: {
        textToSpeech.volume = value/100;
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.