How to transcribe Speech

Set the component state and check if there is valid token.

    constructor(props) {
        super(props);

        this.state = {
            displayText: 'INITIALIZED: ready to test speech...'
        }
    }
    
    async componentDidMount() {
        // check for valid speech key/region
        const tokenRes = await getTokenOrRefresh();
        if (tokenRes.authToken === null) {
            this.setState({
                displayText: 'FATAL_ERROR: ' + tokenRes.error
            });
        }
    }

Calling Speech-to-Text with the microphone stream data

Function to get stream from microphone and make a call for transcription. We call this function when the microphone click happens.

Last updated

Was this helpful?