Guest User

script.js

a guest
Apr 23rd, 2021
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.onload=function(){
  2.   try{
  3.   const btn = document.getElementById("talk");
  4.   const content = document.getElementById("content");
  5.  
  6.   const SpeechRecog = window.SpeechRecognition|| window.webkitSpeechRecognition;
  7.   const recog = new SpeechRecog();
  8.   recog.onstart = function(){
  9.     console.log('voice is activated, you can speak into the microphone');
  10.   };
  11.  recog.onresult = function(event) {
  12.     console.log(event);
  13.     const current = event.resultIndex;
  14.     const transcript = event.results[current][0].transcript;
  15.     content.textContent = transcript;
  16.     document.getElementById("content").value = transcript;
  17.     }
  18.  btn.addEventListener('click',()=>{
  19.     $('#content').empty()
  20.     $('#prediction-list').empty()
  21.     recog.start();
  22.   });}catch(e){
  23.     console.log('Your browser does not support the SpeechAPI, Try with google chrome')
  24.  
  25.   }
  26. }
  27.  
  28.  
  29.  
  30.  
  31. // The minimum prediction confidence.
  32. const threshold = 0.8;
  33. // Load the model. Users optionally pass in a threshold and an array of
  34. // labels to include.
  35. async function getPred(){
  36.     const sentences=document.getElementById("content").value;
  37.     toxicity.load(threshold).then(model => {
  38.         model.classify(sentences).then(predictions => {
  39.     // `predictions` is an array of objects, one for each prediction head,
  40.     // that contains the raw probabilities for each input along with the
  41.     // final prediction in `match` (either `true` or `false`).
  42.     // If neither prediction exceeds the threshold, `match` is `null`.
  43.     console.log(predictions)
  44.  
  45.     predictions.forEach(function (p){
  46.         const className = p.label;
  47.         const probability = p.results;
  48.         const value = probability[0];
  49.         const value1 = value.probabilities;
  50.         const trueprob = (value1[1]*100).toPrecision(5);
  51.         const tag = value.match;
  52.         if (tag) {
  53.           $('#prediction-list').append('<b><li>'+className+' | Tag : '+tag+' | Confidence : '+trueprob+'</li></b>')
  54.         } else {
  55.           $('#prediction-list').append('<li>'+className+' | Tag : '+tag+' | Confidence : '+trueprob+'%'+'</li>')
  56.         }
  57.     });
  58.  
  59.    
  60.   });
  61. });};
RAW Paste Data