{"version":3,"sources":["webpack:///./app/react/packages/tts/services/getTtsToken.js","webpack:///./app/react/packages/tts/services/requestTextToSpeech.js","webpack:///./app/react/packages/tts/hooks/useTextToSpeech.js"],"names":["getTtsToken","getWithXHR","requestTextToSpeech","text","token","url","xhr","headers","Authorization","method","data","speech","voice_name","then","res","useTextToSpeech","title","enabled","useQuery","ttsToken","process"],"mappings":"+LAMeA,EAFK,kBAAMC,YAFd,sB,QCAG,SAASC,EAAT,GAAoD,IAArBC,EAAoB,EAApBA,KAAMC,EAAc,EAAdA,MAAOC,EAAO,EAAPA,IACzD,OAAOC,YAAI,CACTD,MACAE,QAAS,CACPC,cAAc,SAAD,OAAWJ,IAE1BK,OAAQ,OACRC,KAAM,CACJC,OAAQ,CACNR,OACAS,WAAY,sBAGfC,MAAK,SAAAC,GAAG,OAAIA,EAAIJ,QCTN,SAASK,EAAgBC,GAAiC,IAAD,yDAAJ,GAAI,IAAvBC,eAAuB,SAGtE,EAA2BC,YAAS,WAAYlB,GAAlCmB,EAAd,EAAQT,KAER,OAAOQ,YACL,CAAC,eAAgBF,IACjB,kBACEd,EAAoB,CAClBC,KAAMa,EACNZ,MAAOe,EACPd,IAAKe,4CAET,CAIEH,UAAWE,GAAYF","file":"package-tts.e39354d908bb8493426d.chunk.js","sourcesContent":["import getWithXHR from 'Common/utils/getWithXHR'\n\nconst url = '/api/v1/tts_token'\n\nconst getTtsToken = () => getWithXHR(url)\n\nexport default getTtsToken\n","import xhr from 'Common/utils/xhr'\n\nexport default function requestTextToSpeech({ text, token, url }) {\n return xhr({\n url,\n headers: {\n Authorization: `Token ${token}`,\n },\n method: 'POST',\n data: {\n speech: {\n text,\n voice_name: 'en-US-Wavenet-F',\n },\n },\n }).then(res => res.data)\n}\n","import { useQuery } from 'react-query'\n\nimport getTtsToken from '../services/getTtsToken'\nimport requestTextToSpeech from '../services/requestTextToSpeech'\n\n// Second param is an optional object of configuration options\nexport default function useTextToSpeech(title, { enabled = true } = {}) {\n // TTS token will only be fetched once, not once per call to this hook,\n // since the query string will remain stable between calls.\n const { data: ttsToken } = useQuery('ttsToken', getTtsToken)\n\n return useQuery(\n ['flashcardTts', title],\n () =>\n requestTextToSpeech({\n text: title,\n token: ttsToken,\n url: process.env.ESL_TTS_URL,\n }),\n {\n // query requires the TTS token to be resolved before firing;\n // optionally pass an `enabled` flag in the hook's options params\n // to prevent firing a request before it's needed (see Flashcard.js)\n enabled: !!ttsToken && enabled,\n }\n )\n}\n"],"sourceRoot":""}