Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.onload=function(){
- try{
- const btn = document.getElementById("talk");
- const content = document.getElementById("content");
- const SpeechRecog = window.SpeechRecognition|| window.webkitSpeechRecognition;
- const recog = new SpeechRecog();
- recog.onstart = function(){
- console.log('voice is activated, you can speak into the microphone');
- };
- recog.onresult = function(event) {
- console.log(event);
- const current = event.resultIndex;
- const transcript = event.results[current][0].transcript;
- content.textContent = transcript;
- document.getElementById("content").value = transcript;
- }
- btn.addEventListener('click',()=>{
- $('#content').empty()
- $('#prediction-list').empty()
- recog.start();
- });}catch(e){
- console.log('Your browser does not support the SpeechAPI, Try with google chrome')
- }
- }
- // The minimum prediction confidence.
- const threshold = 0.8;
- // Load the model. Users optionally pass in a threshold and an array of
- // labels to include.
- async function getPred(){
- const sentences=document.getElementById("content").value;
- toxicity.load(threshold).then(model => {
- model.classify(sentences).then(predictions => {
- // `predictions` is an array of objects, one for each prediction head,
- // that contains the raw probabilities for each input along with the
- // final prediction in `match` (either `true` or `false`).
- // If neither prediction exceeds the threshold, `match` is `null`.
- console.log(predictions)
- predictions.forEach(function (p){
- const className = p.label;
- const probability = p.results;
- const value = probability[0];
- const value1 = value.probabilities;
- const trueprob = (value1[1]*100).toPrecision(5);
- const tag = value.match;
- if (tag) {
- $('#prediction-list').append('<b><li>'+className+' | Tag : '+tag+' | Confidence : '+trueprob+'</li></b>')
- } else {
- $('#prediction-list').append('<li>'+className+' | Tag : '+tag+' | Confidence : '+trueprob+'%'+'</li>')
- }
- });
- });
- });};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement