function syncRecognize(blob, sampleRate, measures) {
    console.log(blob);
    console.log(sampleRate);
    var audioBytes = '';
    var reader = new FileReader();

    // Read WAV blob as a file and convert to base64 string
    reader.readAsDataURL(blob);
    reader.onloadend = function() {
        audioBytes = reader.result.substring(22);

        // The audio file's encoding, sample rate in hertz, and BCP-47 language code
        const audio = {
            content: audioBytes,
        };
        const config = {
            languageCode: 'en-US',
            encoding: 'LINEAR16',
            sampleRateHertz: sampleRate,
        };
        const request = {
            audio: audio,
            config: config,
        };

        // Detects speech in the audio file
        client
            .recognize(request)
            .then(data => {
                const response = data[0];
                const transcription = response.results.map(result => result.alternatives[0].transcript).join('\n');
                console.log(transcription);
                var syllables = words_to_syllables.splitWords(transcription, measures);
                console.log(syllables);
                updateProgress("speech-to-text");
                return syllables;
            })
            .catch(err => {
                console.error('ERROR:', err);
                updateProgress("speech-to-text");
            });
    }
}
/*
 * Takes a WAV blob and sample rate, converts and sends to Google Cloud Speech API.
 * Returns
 */
Takes a WAV blob and sample rate, converts and sends to Google Cloud Speech API.
Returns
Takes a WAV blob and sample rate converts and sends to Google Cloud Speech API . Returns
function syncRecognize(blob, sampleRate, measures) {
    console.log(blob);
    console.log(sampleRate);
    var audioBytes = '';
    var reader = new FileReader();
    reader.readAsDataURL(blob);
    reader.onloadend = function() {
        audioBytes = reader.result.substring(22);
        const audio = {
            content: audioBytes,
        };
        const config = {
            languageCode: 'en-US',
            encoding: 'LINEAR16',
            sampleRateHertz: sampleRate,
        };
        const request = {
            audio: audio,
            config: config,
        };
        client
            .recognize(request)
            .then(data => {
                const response = data[0];
                const transcription = response.results.map(result => result.alternatives[0].transcript).join('\n');
                console.log(transcription);
                var syllables = words_to_syllables.splitWords(transcription, measures);
                console.log(syllables);
                updateProgress("speech-to-text");
                return syllables;
            })
            .catch(err => {
                console.error('ERROR:', err);
                updateProgress("speech-to-text");
            });
    }
}
function syncRecognize ( blob , sampleRate , measures ) { console . log ( blob ) ; console . log ( sampleRate ) ; var audioBytes = '' ; var reader = new FileReader ( ) ; reader . readAsDataURL ( blob ) ; reader . onloadend = function ( ) { audioBytes = reader . result . substring ( 22 ) ; const audio = { content : audioBytes , } ; const config = { languageCode : 'en-US' , encoding : 'LINEAR16' , sampleRateHertz : sampleRate , } ; const request = { audio : audio , config : config , } ; client . recognize ( request ) . then ( data => { const response = data [ 0 ] ; const transcription = response . results . map ( result => result . alternatives [ 0 ] . transcript ) . join ( '\n' ) ; console . log ( transcription ) ; var syllables = words_to_syllables . splitWords ( transcription , measures ) ; console . log ( syllables ) ; updateProgress ( "speech-to-text" ) ; return syllables ; } ) . catch ( err => { console . error ( 'ERROR:' , err ) ; updateProgress ( "speech-to-text" ) ; } ) ; } }
Takes a WAV blob and sample rate, converts and sends to Google Cloud Speech API.
Takes a WAV blob and sample rate converts and sends to Google Cloud Speech API .
// Read WAV blob as a file and convert to base64 string // The audio file's encoding, sample rate in hertz, and BCP-47 language code // Detects speech in the audio file