fe-pilot
Version:
scanner in web, phonebook in web, autofill otp in web, share web, TextToSpeech in web, Voice Recognition in web, live location tracking in web, detect my location web, wakelock in web, color picker, WhatsappShare, SnapScanner, NetworkMonitor, View360
1 lines • 5.88 kB
JavaScript
var _excluded=["children","successCb","failureCb","loadingCb","successMsg","failureMsg"];function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(b,c){if(b){if("string"==typeof b)return _arrayLikeToArray(b,c);var a={}.toString.call(b).slice(8,-1);return"Object"===a&&b.constructor&&(a=b.constructor.name),"Map"===a||"Set"===a?Array.from(b):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?_arrayLikeToArray(b,c):void 0}}function _arrayLikeToArray(b,c){(null==c||c>b.length)&&(c=b.length);for(var d=0,f=Array(c);d<c;d++)f[d]=b[d];return f}function _iterableToArrayLimit(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d["return"]&&(k=d["return"](),Object(k)!==k))return}finally{if(m)throw h}}return l}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],-1===b.indexOf(c)&&{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(-1!==b.indexOf(d))continue;c[d]=a[d]}return c}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!=_typeof(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}import React,{useState}from"react";import{handleSuccess,handleError,handleLoading}from"../services/handlerService";import Wrapper from"../Wrapper/Wrapper";import VoiceRecognitionIcon from"./VoiceRecognitionIcon";var failureMsgDefault={unSupported:"VoiceRecognition is not supporting in your device",error:""},isBrowserSupport=function(){return globalThis.SpeechRecognition||globalThis.webkitSpeechRecognition},voiceRecognition=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},b=a.successCb,c=void 0===b?function(){}:b,d=a.failureCb,e=void 0===d?function(){}:d,f=a.loadingCb,g=void 0===f?function(){}:f,h=a.successMsg,i=void 0===h?"Successfully converted your voice to text!!":h,j=a.failureMsg,k=void 0===j?_objectSpread({},failureMsgDefault):j,l=a.setIsModalVisible,m=void 0===l?function(){}:l,n=a.setIsVoiceStarted,o=void 0===n?function(){}:n,p=a.setVoiceText,q=void 0===p?function(){}:p,r=_objectSpread(_objectSpread({},failureMsgDefault),k);(function(){if(isBrowserSupport()){handleLoading({loadingCb:g});var a=globalThis.SpeechRecognition||globalThis.webkitSpeechRecognition,b=new a;b.continuous=!1,b.lang="en-US",b.interimResults=!0,b.maxAlternatives=1,b.onresult=function(a){var b=a.results[0][0].transcript;q(b),a.results[0].isFinal&&setTimeout(function(){handleSuccess({msgType:"SUCCESSFUL",msg:i,successCb:c,data:b}),m(!1),q("")},1500)},b.start(),b.onsoundstart=function(){o(!0)},b.onsoundend=function(){o(!1)},b.onerror=function(a){return m(!1),handleError({msgType:"ERROR",msg:r.error||(null===a||void 0===a?void 0:a.error)||"Unable to convert your voice to text",failureCb:e})},b.onend=function(){b.abort(),b.onresult=function(){},b.stop(),setTimeout(function(){return m(!1)},1500)},m(!0)}else return handleError({msgType:"UN_SUPPORTED_FEATURE",msg:r.unSupported,failureCb:e});return!0})()};function VoiceRecognition(a){var b=a.children,c=a.successCb,d=a.failureCb,e=a.loadingCb,f=a.successMsg,g=a.failureMsg,h=_objectWithoutProperties(a,_excluded),i=useState(!1),j=_slicedToArray(i,2),k=j[0],l=j[1],m=useState(!1),n=_slicedToArray(m,2),o=n[0],p=n[1],q=useState(""),r=_slicedToArray(q,2),s=r[0],t=r[1];return React.Children.map(b||React.createElement(VoiceRecognitionIcon,null),function(a){return React.cloneElement("string"==typeof a?React.createElement("span",null,a):a,_objectSpread({successCb:c,failureCb:d,loadingCb:e,successMsg:f,failureMsg:g,voiceRecognition:voiceRecognition,isModalVisible:k,isVoiceStarted:o,voiceText:s,setIsModalVisible:l,setIsVoiceStarted:p,setVoiceText:t},h))})}var WVoiceRecognition=Wrapper(VoiceRecognition,isBrowserSupport);export{voiceRecognition,WVoiceRecognition as VoiceRecognition};export default WVoiceRecognition;