0% found this document useful (0 votes)
26 views1 page

Whisper Reactjs

Uploaded by

konlaptechs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Whisper Reactjs

Uploaded by

konlaptechs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import React, { useState } from 'react';

import * as sdk from 'microsoft-cognitiveservices-speech-sdk';

function SpeechAnalysis() {
const [scores, setScores] = useState({
accuracyScore: 0,
fluencyScore: 0,
compScore: 0,
});

async function handleClick() {


try {
// Get the microphone stream
const stream = await [Link]({ audio: true,
video: false });

// Configure the speech SDK


var speechConfig =
[Link]("YourSubscriptionKey", "YourServiceRegion");

// Create an audio config from the stream


var audioConfig = [Link]();

// Create the speech recognizer


var recognizer = new [Link](speechConfig, audioConfig);

// Handle the recognized event


[Link] = (s, e) => {
var pronunciation_result =
[Link]([Link]);
setScores({
accuracyScore: pronunciation_result.accuracyScore,
fluencyScore: pronunciation_result.fluencyScore,
compScore: pronunciation_result.completenessScore
});
};

// Start the recognizer


[Link]();
} catch (err) {
[Link]('Failed to start recording', err);
}
}

return (
<div>
<button onClick={handleClick}>
Start Speech Analysis
</button>
<div>Accuracy Score: {[Link]}</div>
<div>Fluency Score: {[Link]}</div>
<div>Completeness Score: {[Link]}</div>
</div>
);
}

export default SpeechAnalysis;

You might also like