microsoft.cognitiveservices.speech.sdk.bundle.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710
  1. /******/ (() => { // webpackBootstrap
  2. /******/ var __webpack_modules__ = ([
  3. /* 0 */,
  4. /* 1 */
  5. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  6. "use strict";
  7. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  8. if (k2 === undefined) k2 = k;
  9. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  10. }) : (function(o, m, k, k2) {
  11. if (k2 === undefined) k2 = k;
  12. o[k2] = m[k];
  13. }));
  14. var __exportStar = (this && this.__exportStar) || function(m, exports) {
  15. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  16. };
  17. Object.defineProperty(exports, "__esModule", ({ value: true }));
  18. /* eslint-disable @typescript-eslint/no-unused-vars */
  19. // Copyright (c) Microsoft Corporation. All rights reserved.
  20. // Licensed under the MIT license.
  21. const Exports_js_1 = __webpack_require__(2);
  22. // Note: this instantiation ensures the above import isn't
  23. // removed on compile. The import being absent causes an error on running
  24. void new Exports_js_1.AgentConfig();
  25. // Speech SDK API
  26. __exportStar(__webpack_require__(79), exports);
  27. /***/ }),
  28. /* 2 */
  29. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  30. "use strict";
  31. // Copyright (c) Microsoft Corporation. All rights reserved.
  32. // Licensed under the MIT license.
  33. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  34. if (k2 === undefined) k2 = k;
  35. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  36. }) : (function(o, m, k, k2) {
  37. if (k2 === undefined) k2 = k;
  38. o[k2] = m[k];
  39. }));
  40. var __exportStar = (this && this.__exportStar) || function(m, exports) {
  41. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  42. };
  43. Object.defineProperty(exports, "__esModule", ({ value: true }));
  44. exports.AutoDetectSourceLanguagesOpenRangeOptionName = exports.ForceDictationPropertyName = exports.ServicePropertiesPropertyName = exports.CancellationErrorCodePropertyName = exports.OutputFormatPropertyName = exports.SpeechSynthesisAdapter = exports.AvatarSynthesisAdapter = void 0;
  45. // Make sure not to export internal modules.
  46. //
  47. __exportStar(__webpack_require__(3), exports);
  48. __exportStar(__webpack_require__(56), exports);
  49. __exportStar(__webpack_require__(55), exports);
  50. __exportStar(__webpack_require__(57), exports);
  51. __exportStar(__webpack_require__(58), exports);
  52. __exportStar(__webpack_require__(59), exports);
  53. __exportStar(__webpack_require__(204), exports);
  54. __exportStar(__webpack_require__(205), exports);
  55. __exportStar(__webpack_require__(206), exports);
  56. __exportStar(__webpack_require__(217), exports);
  57. __exportStar(__webpack_require__(218), exports);
  58. __exportStar(__webpack_require__(219), exports);
  59. __exportStar(__webpack_require__(220), exports);
  60. __exportStar(__webpack_require__(221), exports);
  61. __exportStar(__webpack_require__(222), exports);
  62. __exportStar(__webpack_require__(223), exports);
  63. __exportStar(__webpack_require__(224), exports);
  64. __exportStar(__webpack_require__(196), exports);
  65. __exportStar(__webpack_require__(225), exports);
  66. __exportStar(__webpack_require__(226), exports);
  67. __exportStar(__webpack_require__(227), exports);
  68. __exportStar(__webpack_require__(228), exports);
  69. __exportStar(__webpack_require__(229), exports);
  70. __exportStar(__webpack_require__(230), exports);
  71. __exportStar(__webpack_require__(231), exports);
  72. __exportStar(__webpack_require__(232), exports);
  73. __exportStar(__webpack_require__(233), exports);
  74. __exportStar(__webpack_require__(234), exports);
  75. __exportStar(__webpack_require__(235), exports);
  76. __exportStar(__webpack_require__(237), exports);
  77. __exportStar(__webpack_require__(238), exports);
  78. __exportStar(__webpack_require__(239), exports);
  79. __exportStar(__webpack_require__(240), exports);
  80. __exportStar(__webpack_require__(241), exports);
  81. __exportStar(__webpack_require__(242), exports);
  82. __exportStar(__webpack_require__(243), exports);
  83. __exportStar(__webpack_require__(244), exports);
  84. __exportStar(__webpack_require__(246), exports);
  85. __exportStar(__webpack_require__(248), exports);
  86. __exportStar(__webpack_require__(250), exports);
  87. __exportStar(__webpack_require__(256), exports);
  88. __exportStar(__webpack_require__(257), exports);
  89. __exportStar(__webpack_require__(273), exports);
  90. __exportStar(__webpack_require__(274), exports);
  91. __exportStar(__webpack_require__(276), exports);
  92. var AvatarSynthesisAdapter_js_1 = __webpack_require__(277);
  93. Object.defineProperty(exports, "AvatarSynthesisAdapter", ({ enumerable: true, get: function () { return AvatarSynthesisAdapter_js_1.AvatarSynthesisAdapter; } }));
  94. var SpeechSynthesisAdapter_js_1 = __webpack_require__(278);
  95. Object.defineProperty(exports, "SpeechSynthesisAdapter", ({ enumerable: true, get: function () { return SpeechSynthesisAdapter_js_1.SpeechSynthesisAdapter; } }));
  96. __exportStar(__webpack_require__(279), exports);
  97. __exportStar(__webpack_require__(280), exports);
  98. __exportStar(__webpack_require__(281), exports);
  99. __exportStar(__webpack_require__(282), exports);
  100. __exportStar(__webpack_require__(283), exports);
  101. __exportStar(__webpack_require__(284), exports);
  102. __exportStar(__webpack_require__(285), exports);
  103. exports.OutputFormatPropertyName = "OutputFormat";
  104. exports.CancellationErrorCodePropertyName = "CancellationErrorCode";
  105. exports.ServicePropertiesPropertyName = "ServiceProperties";
  106. exports.ForceDictationPropertyName = "ForceDictation";
  107. exports.AutoDetectSourceLanguagesOpenRangeOptionName = "UND";
  108. /***/ }),
  109. /* 3 */
  110. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  111. "use strict";
  112. // Copyright (c) Microsoft Corporation. All rights reserved.
  113. // Licensed under the MIT license.
  114. Object.defineProperty(exports, "__esModule", ({ value: true }));
  115. exports.CognitiveSubscriptionKeyAuthentication = void 0;
  116. const Exports_js_1 = __webpack_require__(4);
  117. const HeaderNames_js_1 = __webpack_require__(54);
  118. const IAuthentication_js_1 = __webpack_require__(55);
  119. /**
  120. * @class
  121. */
  122. class CognitiveSubscriptionKeyAuthentication {
  123. /**
  124. * Creates and initializes an instance of the CognitiveSubscriptionKeyAuthentication class.
  125. * @constructor
  126. * @param {string} subscriptionKey - The subscription key
  127. */
  128. constructor(subscriptionKey) {
  129. if (!subscriptionKey) {
  130. throw new Exports_js_1.ArgumentNullError("subscriptionKey");
  131. }
  132. this.privAuthInfo = new IAuthentication_js_1.AuthInfo(HeaderNames_js_1.HeaderNames.AuthKey, subscriptionKey);
  133. }
  134. /**
  135. * Fetches the subscription key.
  136. * @member
  137. * @function
  138. * @public
  139. * @param {string} authFetchEventId - The id to fetch.
  140. */
  141. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  142. fetch(authFetchEventId) {
  143. return Promise.resolve(this.privAuthInfo);
  144. }
  145. /**
  146. * Fetches the subscription key.
  147. * @member
  148. * @function
  149. * @public
  150. * @param {string} authFetchEventId - The id to fetch.
  151. */
  152. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  153. fetchOnExpiry(authFetchEventId) {
  154. return Promise.resolve(this.privAuthInfo);
  155. }
  156. }
  157. exports.CognitiveSubscriptionKeyAuthentication = CognitiveSubscriptionKeyAuthentication;
  158. /***/ }),
  159. /* 4 */
  160. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  161. "use strict";
  162. // Copyright (c) Microsoft Corporation. All rights reserved.
  163. // Licensed under the MIT license.
  164. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  165. if (k2 === undefined) k2 = k;
  166. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  167. }) : (function(o, m, k, k2) {
  168. if (k2 === undefined) k2 = k;
  169. o[k2] = m[k];
  170. }));
  171. var __exportStar = (this && this.__exportStar) || function(m, exports) {
  172. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  173. };
  174. Object.defineProperty(exports, "__esModule", ({ value: true }));
  175. exports.TranslationStatus = void 0;
  176. __exportStar(__webpack_require__(5), exports);
  177. __exportStar(__webpack_require__(24), exports);
  178. __exportStar(__webpack_require__(25), exports);
  179. __exportStar(__webpack_require__(27), exports);
  180. __exportStar(__webpack_require__(28), exports);
  181. __exportStar(__webpack_require__(29), exports);
  182. __exportStar(__webpack_require__(26), exports);
  183. __exportStar(__webpack_require__(30), exports);
  184. __exportStar(__webpack_require__(31), exports);
  185. __exportStar(__webpack_require__(7), exports);
  186. __exportStar(__webpack_require__(32), exports);
  187. __exportStar(__webpack_require__(33), exports);
  188. __exportStar(__webpack_require__(34), exports);
  189. __exportStar(__webpack_require__(35), exports);
  190. __exportStar(__webpack_require__(36), exports);
  191. __exportStar(__webpack_require__(37), exports);
  192. __exportStar(__webpack_require__(38), exports);
  193. __exportStar(__webpack_require__(39), exports);
  194. __exportStar(__webpack_require__(40), exports);
  195. __exportStar(__webpack_require__(41), exports);
  196. __exportStar(__webpack_require__(42), exports);
  197. __exportStar(__webpack_require__(6), exports);
  198. __exportStar(__webpack_require__(43), exports);
  199. __exportStar(__webpack_require__(44), exports);
  200. __exportStar(__webpack_require__(45), exports);
  201. __exportStar(__webpack_require__(46), exports);
  202. __exportStar(__webpack_require__(47), exports);
  203. var TranslationStatus_js_1 = __webpack_require__(48);
  204. Object.defineProperty(exports, "TranslationStatus", ({ enumerable: true, get: function () { return TranslationStatus_js_1.TranslationStatus; } }));
  205. __exportStar(__webpack_require__(49), exports);
  206. __exportStar(__webpack_require__(50), exports);
  207. __exportStar(__webpack_require__(51), exports);
  208. __exportStar(__webpack_require__(52), exports);
  209. __exportStar(__webpack_require__(53), exports);
  210. /***/ }),
  211. /* 5 */
  212. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  213. "use strict";
  214. // Copyright (c) Microsoft Corporation. All rights reserved.
  215. // Licensed under the MIT license.
  216. Object.defineProperty(exports, "__esModule", ({ value: true }));
  217. exports.AudioStreamNodeErrorEvent = exports.AudioStreamNodeDetachedEvent = exports.AudioStreamNodeAttachedEvent = exports.AudioStreamNodeAttachingEvent = exports.AudioStreamNodeEvent = exports.AudioSourceErrorEvent = exports.AudioSourceOffEvent = exports.AudioSourceReadyEvent = exports.AudioSourceInitializingEvent = exports.AudioSourceEvent = void 0;
  218. /* eslint-disable max-classes-per-file */
  219. const PlatformEvent_js_1 = __webpack_require__(6);
  220. class AudioSourceEvent extends PlatformEvent_js_1.PlatformEvent {
  221. constructor(eventName, audioSourceId, eventType = PlatformEvent_js_1.EventType.Info) {
  222. super(eventName, eventType);
  223. this.privAudioSourceId = audioSourceId;
  224. }
  225. get audioSourceId() {
  226. return this.privAudioSourceId;
  227. }
  228. }
  229. exports.AudioSourceEvent = AudioSourceEvent;
  230. class AudioSourceInitializingEvent extends AudioSourceEvent {
  231. constructor(audioSourceId) {
  232. super("AudioSourceInitializingEvent", audioSourceId);
  233. }
  234. }
  235. exports.AudioSourceInitializingEvent = AudioSourceInitializingEvent;
  236. class AudioSourceReadyEvent extends AudioSourceEvent {
  237. constructor(audioSourceId) {
  238. super("AudioSourceReadyEvent", audioSourceId);
  239. }
  240. }
  241. exports.AudioSourceReadyEvent = AudioSourceReadyEvent;
  242. class AudioSourceOffEvent extends AudioSourceEvent {
  243. constructor(audioSourceId) {
  244. super("AudioSourceOffEvent", audioSourceId);
  245. }
  246. }
  247. exports.AudioSourceOffEvent = AudioSourceOffEvent;
  248. class AudioSourceErrorEvent extends AudioSourceEvent {
  249. constructor(audioSourceId, error) {
  250. super("AudioSourceErrorEvent", audioSourceId, PlatformEvent_js_1.EventType.Error);
  251. this.privError = error;
  252. }
  253. get error() {
  254. return this.privError;
  255. }
  256. }
  257. exports.AudioSourceErrorEvent = AudioSourceErrorEvent;
  258. class AudioStreamNodeEvent extends AudioSourceEvent {
  259. constructor(eventName, audioSourceId, audioNodeId) {
  260. super(eventName, audioSourceId);
  261. this.privAudioNodeId = audioNodeId;
  262. }
  263. get audioNodeId() {
  264. return this.privAudioNodeId;
  265. }
  266. }
  267. exports.AudioStreamNodeEvent = AudioStreamNodeEvent;
  268. class AudioStreamNodeAttachingEvent extends AudioStreamNodeEvent {
  269. constructor(audioSourceId, audioNodeId) {
  270. super("AudioStreamNodeAttachingEvent", audioSourceId, audioNodeId);
  271. }
  272. }
  273. exports.AudioStreamNodeAttachingEvent = AudioStreamNodeAttachingEvent;
  274. class AudioStreamNodeAttachedEvent extends AudioStreamNodeEvent {
  275. constructor(audioSourceId, audioNodeId) {
  276. super("AudioStreamNodeAttachedEvent", audioSourceId, audioNodeId);
  277. }
  278. }
  279. exports.AudioStreamNodeAttachedEvent = AudioStreamNodeAttachedEvent;
  280. class AudioStreamNodeDetachedEvent extends AudioStreamNodeEvent {
  281. constructor(audioSourceId, audioNodeId) {
  282. super("AudioStreamNodeDetachedEvent", audioSourceId, audioNodeId);
  283. }
  284. }
  285. exports.AudioStreamNodeDetachedEvent = AudioStreamNodeDetachedEvent;
  286. class AudioStreamNodeErrorEvent extends AudioStreamNodeEvent {
  287. constructor(audioSourceId, audioNodeId, error) {
  288. super("AudioStreamNodeErrorEvent", audioSourceId, audioNodeId);
  289. this.privError = error;
  290. }
  291. get error() {
  292. return this.privError;
  293. }
  294. }
  295. exports.AudioStreamNodeErrorEvent = AudioStreamNodeErrorEvent;
  296. /***/ }),
  297. /* 6 */
  298. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  299. "use strict";
  300. // Copyright (c) Microsoft Corporation. All rights reserved.
  301. // Licensed under the MIT license.
  302. Object.defineProperty(exports, "__esModule", ({ value: true }));
  303. exports.PlatformEvent = exports.EventType = void 0;
  304. const Guid_js_1 = __webpack_require__(7);
  305. var EventType;
  306. (function (EventType) {
  307. EventType[EventType["Debug"] = 0] = "Debug";
  308. EventType[EventType["Info"] = 1] = "Info";
  309. EventType[EventType["Warning"] = 2] = "Warning";
  310. EventType[EventType["Error"] = 3] = "Error";
  311. EventType[EventType["None"] = 4] = "None";
  312. })(EventType = exports.EventType || (exports.EventType = {}));
  313. class PlatformEvent {
  314. constructor(eventName, eventType) {
  315. this.privName = eventName;
  316. this.privEventId = (0, Guid_js_1.createNoDashGuid)();
  317. this.privEventTime = new Date().toISOString();
  318. this.privEventType = eventType;
  319. this.privMetadata = {};
  320. }
  321. get name() {
  322. return this.privName;
  323. }
  324. get eventId() {
  325. return this.privEventId;
  326. }
  327. get eventTime() {
  328. return this.privEventTime;
  329. }
  330. get eventType() {
  331. return this.privEventType;
  332. }
  333. get metadata() {
  334. return this.privMetadata;
  335. }
  336. }
  337. exports.PlatformEvent = PlatformEvent;
  338. /***/ }),
  339. /* 7 */
  340. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  341. "use strict";
  342. // Copyright (c) Microsoft Corporation. All rights reserved.
  343. // Licensed under the MIT license.
  344. Object.defineProperty(exports, "__esModule", ({ value: true }));
  345. exports.createNoDashGuid = exports.createGuid = void 0;
  346. const uuid_1 = __webpack_require__(8);
  347. const createGuid = () => (0, uuid_1.v4)();
  348. exports.createGuid = createGuid;
  349. const createNoDashGuid = () => createGuid().replace(new RegExp("-", "g"), "").toUpperCase();
  350. exports.createNoDashGuid = createNoDashGuid;
  351. /***/ }),
  352. /* 8 */
  353. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  354. "use strict";
  355. Object.defineProperty(exports, "__esModule", ({
  356. value: true
  357. }));
  358. Object.defineProperty(exports, "NIL", ({
  359. enumerable: true,
  360. get: function get() {
  361. return _nil.default;
  362. }
  363. }));
  364. Object.defineProperty(exports, "parse", ({
  365. enumerable: true,
  366. get: function get() {
  367. return _parse.default;
  368. }
  369. }));
  370. Object.defineProperty(exports, "stringify", ({
  371. enumerable: true,
  372. get: function get() {
  373. return _stringify.default;
  374. }
  375. }));
  376. Object.defineProperty(exports, "v1", ({
  377. enumerable: true,
  378. get: function get() {
  379. return _v.default;
  380. }
  381. }));
  382. Object.defineProperty(exports, "v3", ({
  383. enumerable: true,
  384. get: function get() {
  385. return _v2.default;
  386. }
  387. }));
  388. Object.defineProperty(exports, "v4", ({
  389. enumerable: true,
  390. get: function get() {
  391. return _v3.default;
  392. }
  393. }));
  394. Object.defineProperty(exports, "v5", ({
  395. enumerable: true,
  396. get: function get() {
  397. return _v4.default;
  398. }
  399. }));
  400. Object.defineProperty(exports, "validate", ({
  401. enumerable: true,
  402. get: function get() {
  403. return _validate.default;
  404. }
  405. }));
  406. Object.defineProperty(exports, "version", ({
  407. enumerable: true,
  408. get: function get() {
  409. return _version.default;
  410. }
  411. }));
  412. var _v = _interopRequireDefault(__webpack_require__(9));
  413. var _v2 = _interopRequireDefault(__webpack_require__(14));
  414. var _v3 = _interopRequireDefault(__webpack_require__(18));
  415. var _v4 = _interopRequireDefault(__webpack_require__(20));
  416. var _nil = _interopRequireDefault(__webpack_require__(22));
  417. var _version = _interopRequireDefault(__webpack_require__(23));
  418. var _validate = _interopRequireDefault(__webpack_require__(12));
  419. var _stringify = _interopRequireDefault(__webpack_require__(11));
  420. var _parse = _interopRequireDefault(__webpack_require__(16));
  421. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  422. /***/ }),
  423. /* 9 */
  424. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  425. "use strict";
  426. Object.defineProperty(exports, "__esModule", ({
  427. value: true
  428. }));
  429. exports["default"] = void 0;
  430. var _rng = _interopRequireDefault(__webpack_require__(10));
  431. var _stringify = __webpack_require__(11);
  432. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  433. // **`v1()` - Generate time-based UUID**
  434. //
  435. // Inspired by https://github.com/LiosK/UUID.js
  436. // and http://docs.python.org/library/uuid.html
  437. let _nodeId;
  438. let _clockseq; // Previous uuid creation time
  439. let _lastMSecs = 0;
  440. let _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
  441. function v1(options, buf, offset) {
  442. let i = buf && offset || 0;
  443. const b = buf || new Array(16);
  444. options = options || {};
  445. let node = options.node || _nodeId;
  446. let clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
  447. // specified. We do this lazily to minimize issues related to insufficient
  448. // system entropy. See #189
  449. if (node == null || clockseq == null) {
  450. const seedBytes = options.random || (options.rng || _rng.default)();
  451. if (node == null) {
  452. // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
  453. node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
  454. }
  455. if (clockseq == null) {
  456. // Per 4.2.2, randomize (14 bit) clockseq
  457. clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
  458. }
  459. } // UUID timestamps are 100 nano-second units since the Gregorian epoch,
  460. // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
  461. // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
  462. // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
  463. let msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock
  464. // cycle to simulate higher resolution clock
  465. let nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
  466. const dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
  467. if (dt < 0 && options.clockseq === undefined) {
  468. clockseq = clockseq + 1 & 0x3fff;
  469. } // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
  470. // time interval
  471. if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
  472. nsecs = 0;
  473. } // Per 4.2.1.2 Throw error if too many uuids are requested
  474. if (nsecs >= 10000) {
  475. throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
  476. }
  477. _lastMSecs = msecs;
  478. _lastNSecs = nsecs;
  479. _clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
  480. msecs += 12219292800000; // `time_low`
  481. const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
  482. b[i++] = tl >>> 24 & 0xff;
  483. b[i++] = tl >>> 16 & 0xff;
  484. b[i++] = tl >>> 8 & 0xff;
  485. b[i++] = tl & 0xff; // `time_mid`
  486. const tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
  487. b[i++] = tmh >>> 8 & 0xff;
  488. b[i++] = tmh & 0xff; // `time_high_and_version`
  489. b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
  490. b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
  491. b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low`
  492. b[i++] = clockseq & 0xff; // `node`
  493. for (let n = 0; n < 6; ++n) {
  494. b[i + n] = node[n];
  495. }
  496. return buf || (0, _stringify.unsafeStringify)(b);
  497. }
  498. var _default = v1;
  499. exports["default"] = _default;
  500. /***/ }),
  501. /* 10 */
  502. /***/ ((__unused_webpack_module, exports) => {
  503. "use strict";
  504. Object.defineProperty(exports, "__esModule", ({
  505. value: true
  506. }));
  507. exports["default"] = rng;
  508. // Unique ID creation requires a high quality random # generator. In the browser we therefore
  509. // require the crypto API and do not support built-in fallback to lower quality random number
  510. // generators (like Math.random()).
  511. let getRandomValues;
  512. const rnds8 = new Uint8Array(16);
  513. function rng() {
  514. // lazy load so that environments that need to polyfill have a chance to do so
  515. if (!getRandomValues) {
  516. // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
  517. getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
  518. if (!getRandomValues) {
  519. throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
  520. }
  521. }
  522. return getRandomValues(rnds8);
  523. }
  524. /***/ }),
  525. /* 11 */
  526. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  527. "use strict";
  528. Object.defineProperty(exports, "__esModule", ({
  529. value: true
  530. }));
  531. exports["default"] = void 0;
  532. exports.unsafeStringify = unsafeStringify;
  533. var _validate = _interopRequireDefault(__webpack_require__(12));
  534. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  535. /**
  536. * Convert array of 16 byte values to UUID string format of the form:
  537. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  538. */
  539. const byteToHex = [];
  540. for (let i = 0; i < 256; ++i) {
  541. byteToHex.push((i + 0x100).toString(16).slice(1));
  542. }
  543. function unsafeStringify(arr, offset = 0) {
  544. // Note: Be careful editing this code! It's been tuned for performance
  545. // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
  546. return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
  547. }
  548. function stringify(arr, offset = 0) {
  549. const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one
  550. // of the following:
  551. // - One or more input array values don't map to a hex octet (leading to
  552. // "undefined" in the uuid)
  553. // - Invalid input values for the RFC `version` or `variant` fields
  554. if (!(0, _validate.default)(uuid)) {
  555. throw TypeError('Stringified UUID is invalid');
  556. }
  557. return uuid;
  558. }
  559. var _default = stringify;
  560. exports["default"] = _default;
  561. /***/ }),
  562. /* 12 */
  563. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  564. "use strict";
  565. Object.defineProperty(exports, "__esModule", ({
  566. value: true
  567. }));
  568. exports["default"] = void 0;
  569. var _regex = _interopRequireDefault(__webpack_require__(13));
  570. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  571. function validate(uuid) {
  572. return typeof uuid === 'string' && _regex.default.test(uuid);
  573. }
  574. var _default = validate;
  575. exports["default"] = _default;
  576. /***/ }),
  577. /* 13 */
  578. /***/ ((__unused_webpack_module, exports) => {
  579. "use strict";
  580. Object.defineProperty(exports, "__esModule", ({
  581. value: true
  582. }));
  583. exports["default"] = void 0;
  584. var _default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
  585. exports["default"] = _default;
  586. /***/ }),
  587. /* 14 */
  588. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  589. "use strict";
  590. Object.defineProperty(exports, "__esModule", ({
  591. value: true
  592. }));
  593. exports["default"] = void 0;
  594. var _v = _interopRequireDefault(__webpack_require__(15));
  595. var _md = _interopRequireDefault(__webpack_require__(17));
  596. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  597. const v3 = (0, _v.default)('v3', 0x30, _md.default);
  598. var _default = v3;
  599. exports["default"] = _default;
  600. /***/ }),
  601. /* 15 */
  602. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  603. "use strict";
  604. Object.defineProperty(exports, "__esModule", ({
  605. value: true
  606. }));
  607. exports.URL = exports.DNS = void 0;
  608. exports["default"] = v35;
  609. var _stringify = __webpack_require__(11);
  610. var _parse = _interopRequireDefault(__webpack_require__(16));
  611. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  612. function stringToBytes(str) {
  613. str = unescape(encodeURIComponent(str)); // UTF8 escape
  614. const bytes = [];
  615. for (let i = 0; i < str.length; ++i) {
  616. bytes.push(str.charCodeAt(i));
  617. }
  618. return bytes;
  619. }
  620. const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
  621. exports.DNS = DNS;
  622. const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
  623. exports.URL = URL;
  624. function v35(name, version, hashfunc) {
  625. function generateUUID(value, namespace, buf, offset) {
  626. var _namespace;
  627. if (typeof value === 'string') {
  628. value = stringToBytes(value);
  629. }
  630. if (typeof namespace === 'string') {
  631. namespace = (0, _parse.default)(namespace);
  632. }
  633. if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
  634. throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
  635. } // Compute hash of namespace and value, Per 4.3
  636. // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
  637. // hashfunc([...namespace, ... value])`
  638. let bytes = new Uint8Array(16 + value.length);
  639. bytes.set(namespace);
  640. bytes.set(value, namespace.length);
  641. bytes = hashfunc(bytes);
  642. bytes[6] = bytes[6] & 0x0f | version;
  643. bytes[8] = bytes[8] & 0x3f | 0x80;
  644. if (buf) {
  645. offset = offset || 0;
  646. for (let i = 0; i < 16; ++i) {
  647. buf[offset + i] = bytes[i];
  648. }
  649. return buf;
  650. }
  651. return (0, _stringify.unsafeStringify)(bytes);
  652. } // Function#name is not settable on some platforms (#270)
  653. try {
  654. generateUUID.name = name; // eslint-disable-next-line no-empty
  655. } catch (err) {} // For CommonJS default export support
  656. generateUUID.DNS = DNS;
  657. generateUUID.URL = URL;
  658. return generateUUID;
  659. }
  660. /***/ }),
  661. /* 16 */
  662. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  663. "use strict";
  664. Object.defineProperty(exports, "__esModule", ({
  665. value: true
  666. }));
  667. exports["default"] = void 0;
  668. var _validate = _interopRequireDefault(__webpack_require__(12));
  669. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  670. function parse(uuid) {
  671. if (!(0, _validate.default)(uuid)) {
  672. throw TypeError('Invalid UUID');
  673. }
  674. let v;
  675. const arr = new Uint8Array(16); // Parse ########-....-....-....-............
  676. arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
  677. arr[1] = v >>> 16 & 0xff;
  678. arr[2] = v >>> 8 & 0xff;
  679. arr[3] = v & 0xff; // Parse ........-####-....-....-............
  680. arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
  681. arr[5] = v & 0xff; // Parse ........-....-####-....-............
  682. arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
  683. arr[7] = v & 0xff; // Parse ........-....-....-####-............
  684. arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
  685. arr[9] = v & 0xff; // Parse ........-....-....-....-############
  686. // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
  687. arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
  688. arr[11] = v / 0x100000000 & 0xff;
  689. arr[12] = v >>> 24 & 0xff;
  690. arr[13] = v >>> 16 & 0xff;
  691. arr[14] = v >>> 8 & 0xff;
  692. arr[15] = v & 0xff;
  693. return arr;
  694. }
  695. var _default = parse;
  696. exports["default"] = _default;
  697. /***/ }),
  698. /* 17 */
  699. /***/ ((__unused_webpack_module, exports) => {
  700. "use strict";
  701. Object.defineProperty(exports, "__esModule", ({
  702. value: true
  703. }));
  704. exports["default"] = void 0;
  705. /*
  706. * Browser-compatible JavaScript MD5
  707. *
  708. * Modification of JavaScript MD5
  709. * https://github.com/blueimp/JavaScript-MD5
  710. *
  711. * Copyright 2011, Sebastian Tschan
  712. * https://blueimp.net
  713. *
  714. * Licensed under the MIT license:
  715. * https://opensource.org/licenses/MIT
  716. *
  717. * Based on
  718. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  719. * Digest Algorithm, as defined in RFC 1321.
  720. * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
  721. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  722. * Distributed under the BSD License
  723. * See http://pajhome.org.uk/crypt/md5 for more info.
  724. */
  725. function md5(bytes) {
  726. if (typeof bytes === 'string') {
  727. const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
  728. bytes = new Uint8Array(msg.length);
  729. for (let i = 0; i < msg.length; ++i) {
  730. bytes[i] = msg.charCodeAt(i);
  731. }
  732. }
  733. return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
  734. }
  735. /*
  736. * Convert an array of little-endian words to an array of bytes
  737. */
  738. function md5ToHexEncodedArray(input) {
  739. const output = [];
  740. const length32 = input.length * 32;
  741. const hexTab = '0123456789abcdef';
  742. for (let i = 0; i < length32; i += 8) {
  743. const x = input[i >> 5] >>> i % 32 & 0xff;
  744. const hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
  745. output.push(hex);
  746. }
  747. return output;
  748. }
  749. /**
  750. * Calculate output length with padding and bit length
  751. */
  752. function getOutputLength(inputLength8) {
  753. return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
  754. }
  755. /*
  756. * Calculate the MD5 of an array of little-endian words, and a bit length.
  757. */
  758. function wordsToMd5(x, len) {
  759. /* append padding */
  760. x[len >> 5] |= 0x80 << len % 32;
  761. x[getOutputLength(len) - 1] = len;
  762. let a = 1732584193;
  763. let b = -271733879;
  764. let c = -1732584194;
  765. let d = 271733878;
  766. for (let i = 0; i < x.length; i += 16) {
  767. const olda = a;
  768. const oldb = b;
  769. const oldc = c;
  770. const oldd = d;
  771. a = md5ff(a, b, c, d, x[i], 7, -680876936);
  772. d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
  773. c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
  774. b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
  775. a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
  776. d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
  777. c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
  778. b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
  779. a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
  780. d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
  781. c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
  782. b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
  783. a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
  784. d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
  785. c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
  786. b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
  787. a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
  788. d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
  789. c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
  790. b = md5gg(b, c, d, a, x[i], 20, -373897302);
  791. a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
  792. d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
  793. c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
  794. b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
  795. a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
  796. d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
  797. c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
  798. b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
  799. a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
  800. d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
  801. c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
  802. b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
  803. a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
  804. d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
  805. c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
  806. b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
  807. a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
  808. d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
  809. c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
  810. b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
  811. a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
  812. d = md5hh(d, a, b, c, x[i], 11, -358537222);
  813. c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
  814. b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
  815. a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
  816. d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
  817. c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
  818. b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
  819. a = md5ii(a, b, c, d, x[i], 6, -198630844);
  820. d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
  821. c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
  822. b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
  823. a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
  824. d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
  825. c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
  826. b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
  827. a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
  828. d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
  829. c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
  830. b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
  831. a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
  832. d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
  833. c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
  834. b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
  835. a = safeAdd(a, olda);
  836. b = safeAdd(b, oldb);
  837. c = safeAdd(c, oldc);
  838. d = safeAdd(d, oldd);
  839. }
  840. return [a, b, c, d];
  841. }
  842. /*
  843. * Convert an array bytes to an array of little-endian words
  844. * Characters >255 have their high-byte silently ignored.
  845. */
  846. function bytesToWords(input) {
  847. if (input.length === 0) {
  848. return [];
  849. }
  850. const length8 = input.length * 8;
  851. const output = new Uint32Array(getOutputLength(length8));
  852. for (let i = 0; i < length8; i += 8) {
  853. output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
  854. }
  855. return output;
  856. }
  857. /*
  858. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  859. * to work around bugs in some JS interpreters.
  860. */
  861. function safeAdd(x, y) {
  862. const lsw = (x & 0xffff) + (y & 0xffff);
  863. const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  864. return msw << 16 | lsw & 0xffff;
  865. }
  866. /*
  867. * Bitwise rotate a 32-bit number to the left.
  868. */
  869. function bitRotateLeft(num, cnt) {
  870. return num << cnt | num >>> 32 - cnt;
  871. }
  872. /*
  873. * These functions implement the four basic operations the algorithm uses.
  874. */
  875. function md5cmn(q, a, b, x, s, t) {
  876. return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
  877. }
  878. function md5ff(a, b, c, d, x, s, t) {
  879. return md5cmn(b & c | ~b & d, a, b, x, s, t);
  880. }
  881. function md5gg(a, b, c, d, x, s, t) {
  882. return md5cmn(b & d | c & ~d, a, b, x, s, t);
  883. }
  884. function md5hh(a, b, c, d, x, s, t) {
  885. return md5cmn(b ^ c ^ d, a, b, x, s, t);
  886. }
  887. function md5ii(a, b, c, d, x, s, t) {
  888. return md5cmn(c ^ (b | ~d), a, b, x, s, t);
  889. }
  890. var _default = md5;
  891. exports["default"] = _default;
  892. /***/ }),
  893. /* 18 */
  894. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  895. "use strict";
  896. Object.defineProperty(exports, "__esModule", ({
  897. value: true
  898. }));
  899. exports["default"] = void 0;
  900. var _native = _interopRequireDefault(__webpack_require__(19));
  901. var _rng = _interopRequireDefault(__webpack_require__(10));
  902. var _stringify = __webpack_require__(11);
  903. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  904. function v4(options, buf, offset) {
  905. if (_native.default.randomUUID && !buf && !options) {
  906. return _native.default.randomUUID();
  907. }
  908. options = options || {};
  909. const rnds = options.random || (options.rng || _rng.default)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
  910. rnds[6] = rnds[6] & 0x0f | 0x40;
  911. rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
  912. if (buf) {
  913. offset = offset || 0;
  914. for (let i = 0; i < 16; ++i) {
  915. buf[offset + i] = rnds[i];
  916. }
  917. return buf;
  918. }
  919. return (0, _stringify.unsafeStringify)(rnds);
  920. }
  921. var _default = v4;
  922. exports["default"] = _default;
  923. /***/ }),
  924. /* 19 */
  925. /***/ ((__unused_webpack_module, exports) => {
  926. "use strict";
  927. Object.defineProperty(exports, "__esModule", ({
  928. value: true
  929. }));
  930. exports["default"] = void 0;
  931. const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
  932. var _default = {
  933. randomUUID
  934. };
  935. exports["default"] = _default;
  936. /***/ }),
  937. /* 20 */
  938. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  939. "use strict";
  940. Object.defineProperty(exports, "__esModule", ({
  941. value: true
  942. }));
  943. exports["default"] = void 0;
  944. var _v = _interopRequireDefault(__webpack_require__(15));
  945. var _sha = _interopRequireDefault(__webpack_require__(21));
  946. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  947. const v5 = (0, _v.default)('v5', 0x50, _sha.default);
  948. var _default = v5;
  949. exports["default"] = _default;
  950. /***/ }),
  951. /* 21 */
  952. /***/ ((__unused_webpack_module, exports) => {
  953. "use strict";
  954. Object.defineProperty(exports, "__esModule", ({
  955. value: true
  956. }));
  957. exports["default"] = void 0;
  958. // Adapted from Chris Veness' SHA1 code at
  959. // http://www.movable-type.co.uk/scripts/sha1.html
  960. function f(s, x, y, z) {
  961. switch (s) {
  962. case 0:
  963. return x & y ^ ~x & z;
  964. case 1:
  965. return x ^ y ^ z;
  966. case 2:
  967. return x & y ^ x & z ^ y & z;
  968. case 3:
  969. return x ^ y ^ z;
  970. }
  971. }
  972. function ROTL(x, n) {
  973. return x << n | x >>> 32 - n;
  974. }
  975. function sha1(bytes) {
  976. const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
  977. const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  978. if (typeof bytes === 'string') {
  979. const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
  980. bytes = [];
  981. for (let i = 0; i < msg.length; ++i) {
  982. bytes.push(msg.charCodeAt(i));
  983. }
  984. } else if (!Array.isArray(bytes)) {
  985. // Convert Array-like to Array
  986. bytes = Array.prototype.slice.call(bytes);
  987. }
  988. bytes.push(0x80);
  989. const l = bytes.length / 4 + 2;
  990. const N = Math.ceil(l / 16);
  991. const M = new Array(N);
  992. for (let i = 0; i < N; ++i) {
  993. const arr = new Uint32Array(16);
  994. for (let j = 0; j < 16; ++j) {
  995. arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
  996. }
  997. M[i] = arr;
  998. }
  999. M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
  1000. M[N - 1][14] = Math.floor(M[N - 1][14]);
  1001. M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
  1002. for (let i = 0; i < N; ++i) {
  1003. const W = new Uint32Array(80);
  1004. for (let t = 0; t < 16; ++t) {
  1005. W[t] = M[i][t];
  1006. }
  1007. for (let t = 16; t < 80; ++t) {
  1008. W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
  1009. }
  1010. let a = H[0];
  1011. let b = H[1];
  1012. let c = H[2];
  1013. let d = H[3];
  1014. let e = H[4];
  1015. for (let t = 0; t < 80; ++t) {
  1016. const s = Math.floor(t / 20);
  1017. const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
  1018. e = d;
  1019. d = c;
  1020. c = ROTL(b, 30) >>> 0;
  1021. b = a;
  1022. a = T;
  1023. }
  1024. H[0] = H[0] + a >>> 0;
  1025. H[1] = H[1] + b >>> 0;
  1026. H[2] = H[2] + c >>> 0;
  1027. H[3] = H[3] + d >>> 0;
  1028. H[4] = H[4] + e >>> 0;
  1029. }
  1030. return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
  1031. }
  1032. var _default = sha1;
  1033. exports["default"] = _default;
  1034. /***/ }),
  1035. /* 22 */
  1036. /***/ ((__unused_webpack_module, exports) => {
  1037. "use strict";
  1038. Object.defineProperty(exports, "__esModule", ({
  1039. value: true
  1040. }));
  1041. exports["default"] = void 0;
  1042. var _default = '00000000-0000-0000-0000-000000000000';
  1043. exports["default"] = _default;
  1044. /***/ }),
  1045. /* 23 */
  1046. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1047. "use strict";
  1048. Object.defineProperty(exports, "__esModule", ({
  1049. value: true
  1050. }));
  1051. exports["default"] = void 0;
  1052. var _validate = _interopRequireDefault(__webpack_require__(12));
  1053. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1054. function version(uuid) {
  1055. if (!(0, _validate.default)(uuid)) {
  1056. throw TypeError('Invalid UUID');
  1057. }
  1058. return parseInt(uuid.slice(14, 15), 16);
  1059. }
  1060. var _default = version;
  1061. exports["default"] = _default;
  1062. /***/ }),
  1063. /* 24 */
  1064. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1065. "use strict";
  1066. // Copyright (c) Microsoft Corporation. All rights reserved.
  1067. // Licensed under the MIT license.
  1068. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1069. exports.ConnectionRedirectEvent = exports.ConnectionMessageSentEvent = exports.ConnectionMessageReceivedEvent = exports.ConnectionEstablishErrorEvent = exports.ConnectionErrorEvent = exports.ConnectionClosedEvent = exports.ConnectionEstablishedEvent = exports.ConnectionStartEvent = exports.ConnectionEvent = exports.ServiceEvent = void 0;
  1070. const PlatformEvent_js_1 = __webpack_require__(6);
  1071. class ServiceEvent extends PlatformEvent_js_1.PlatformEvent {
  1072. constructor(eventName, jsonstring, eventType = PlatformEvent_js_1.EventType.Info) {
  1073. super(eventName, eventType);
  1074. this.privJsonResult = jsonstring;
  1075. }
  1076. get jsonString() {
  1077. return this.privJsonResult;
  1078. }
  1079. }
  1080. exports.ServiceEvent = ServiceEvent;
  1081. class ConnectionEvent extends PlatformEvent_js_1.PlatformEvent {
  1082. constructor(eventName, connectionId, eventType = PlatformEvent_js_1.EventType.Info) {
  1083. super(eventName, eventType);
  1084. this.privConnectionId = connectionId;
  1085. }
  1086. get connectionId() {
  1087. return this.privConnectionId;
  1088. }
  1089. }
  1090. exports.ConnectionEvent = ConnectionEvent;
  1091. class ConnectionStartEvent extends ConnectionEvent {
  1092. constructor(connectionId, uri, headers) {
  1093. super("ConnectionStartEvent", connectionId);
  1094. this.privUri = uri;
  1095. this.privHeaders = headers;
  1096. }
  1097. get uri() {
  1098. return this.privUri;
  1099. }
  1100. get headers() {
  1101. return this.privHeaders;
  1102. }
  1103. }
  1104. exports.ConnectionStartEvent = ConnectionStartEvent;
  1105. class ConnectionEstablishedEvent extends ConnectionEvent {
  1106. constructor(connectionId) {
  1107. super("ConnectionEstablishedEvent", connectionId);
  1108. }
  1109. }
  1110. exports.ConnectionEstablishedEvent = ConnectionEstablishedEvent;
  1111. class ConnectionClosedEvent extends ConnectionEvent {
  1112. constructor(connectionId, statusCode, reason) {
  1113. super("ConnectionClosedEvent", connectionId, PlatformEvent_js_1.EventType.Debug);
  1114. this.privReason = reason;
  1115. this.privStatusCode = statusCode;
  1116. }
  1117. get reason() {
  1118. return this.privReason;
  1119. }
  1120. get statusCode() {
  1121. return this.privStatusCode;
  1122. }
  1123. }
  1124. exports.ConnectionClosedEvent = ConnectionClosedEvent;
  1125. class ConnectionErrorEvent extends ConnectionEvent {
  1126. constructor(connectionId, message, type) {
  1127. super("ConnectionErrorEvent", connectionId, PlatformEvent_js_1.EventType.Debug);
  1128. this.privMessage = message;
  1129. this.privType = type;
  1130. }
  1131. get message() {
  1132. return this.privMessage;
  1133. }
  1134. get type() {
  1135. return this.privType;
  1136. }
  1137. }
  1138. exports.ConnectionErrorEvent = ConnectionErrorEvent;
  1139. class ConnectionEstablishErrorEvent extends ConnectionEvent {
  1140. constructor(connectionId, statuscode, reason) {
  1141. super("ConnectionEstablishErrorEvent", connectionId, PlatformEvent_js_1.EventType.Error);
  1142. this.privStatusCode = statuscode;
  1143. this.privReason = reason;
  1144. }
  1145. get reason() {
  1146. return this.privReason;
  1147. }
  1148. get statusCode() {
  1149. return this.privStatusCode;
  1150. }
  1151. }
  1152. exports.ConnectionEstablishErrorEvent = ConnectionEstablishErrorEvent;
  1153. class ConnectionMessageReceivedEvent extends ConnectionEvent {
  1154. constructor(connectionId, networkReceivedTimeISO, message) {
  1155. super("ConnectionMessageReceivedEvent", connectionId);
  1156. this.privNetworkReceivedTime = networkReceivedTimeISO;
  1157. this.privMessage = message;
  1158. }
  1159. get networkReceivedTime() {
  1160. return this.privNetworkReceivedTime;
  1161. }
  1162. get message() {
  1163. return this.privMessage;
  1164. }
  1165. }
  1166. exports.ConnectionMessageReceivedEvent = ConnectionMessageReceivedEvent;
  1167. class ConnectionMessageSentEvent extends ConnectionEvent {
  1168. constructor(connectionId, networkSentTimeISO, message) {
  1169. super("ConnectionMessageSentEvent", connectionId);
  1170. this.privNetworkSentTime = networkSentTimeISO;
  1171. this.privMessage = message;
  1172. }
  1173. get networkSentTime() {
  1174. return this.privNetworkSentTime;
  1175. }
  1176. get message() {
  1177. return this.privMessage;
  1178. }
  1179. }
  1180. exports.ConnectionMessageSentEvent = ConnectionMessageSentEvent;
  1181. class ConnectionRedirectEvent extends ConnectionEvent {
  1182. constructor(connectionId, redirectUrl, originalUrl, context) {
  1183. super("ConnectionRedirectEvent", connectionId, PlatformEvent_js_1.EventType.Info);
  1184. this.privRedirectUrl = redirectUrl;
  1185. this.privOriginalUrl = originalUrl;
  1186. this.privContext = context;
  1187. }
  1188. get redirectUrl() {
  1189. return this.privRedirectUrl;
  1190. }
  1191. get originalUrl() {
  1192. return this.privOriginalUrl;
  1193. }
  1194. get context() {
  1195. return this.privContext;
  1196. }
  1197. }
  1198. exports.ConnectionRedirectEvent = ConnectionRedirectEvent;
  1199. /***/ }),
  1200. /* 25 */
  1201. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1202. "use strict";
  1203. /* eslint-disable @typescript-eslint/no-unsafe-return */
  1204. // Copyright (c) Microsoft Corporation. All rights reserved.
  1205. // Licensed under the MIT license.
  1206. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1207. exports.ConnectionMessage = exports.MessageType = void 0;
  1208. const Error_js_1 = __webpack_require__(26);
  1209. const Guid_js_1 = __webpack_require__(7);
  1210. var MessageType;
  1211. (function (MessageType) {
  1212. MessageType[MessageType["Text"] = 0] = "Text";
  1213. MessageType[MessageType["Binary"] = 1] = "Binary";
  1214. })(MessageType = exports.MessageType || (exports.MessageType = {}));
  1215. class ConnectionMessage {
  1216. constructor(messageType, body, headers, id) {
  1217. this.privBody = null;
  1218. if (messageType === MessageType.Text && body && !(typeof (body) === "string")) {
  1219. throw new Error_js_1.InvalidOperationError("Payload must be a string");
  1220. }
  1221. if (messageType === MessageType.Binary && body && !(body instanceof ArrayBuffer)) {
  1222. throw new Error_js_1.InvalidOperationError("Payload must be ArrayBuffer");
  1223. }
  1224. this.privMessageType = messageType;
  1225. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  1226. this.privBody = body;
  1227. this.privHeaders = headers ? headers : {};
  1228. this.privId = id ? id : (0, Guid_js_1.createNoDashGuid)();
  1229. switch (this.messageType) {
  1230. case MessageType.Binary:
  1231. this.privSize = this.binaryBody !== null ? this.binaryBody.byteLength : 0;
  1232. break;
  1233. case MessageType.Text:
  1234. this.privSize = this.textBody.length;
  1235. }
  1236. }
  1237. get messageType() {
  1238. return this.privMessageType;
  1239. }
  1240. get headers() {
  1241. return this.privHeaders;
  1242. }
  1243. get body() {
  1244. return this.privBody;
  1245. }
  1246. get textBody() {
  1247. if (this.privMessageType === MessageType.Binary) {
  1248. throw new Error_js_1.InvalidOperationError("Not supported for binary message");
  1249. }
  1250. return this.privBody;
  1251. }
  1252. get binaryBody() {
  1253. if (this.privMessageType === MessageType.Text) {
  1254. throw new Error_js_1.InvalidOperationError("Not supported for text message");
  1255. }
  1256. return this.privBody;
  1257. }
  1258. get id() {
  1259. return this.privId;
  1260. }
  1261. }
  1262. exports.ConnectionMessage = ConnectionMessage;
  1263. /***/ }),
  1264. /* 26 */
  1265. /***/ ((__unused_webpack_module, exports) => {
  1266. "use strict";
  1267. // Copyright (c) Microsoft Corporation. All rights reserved.
  1268. // Licensed under the MIT license.
  1269. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1270. exports.ObjectDisposedError = exports.InvalidOperationError = exports.ArgumentNullError = void 0;
  1271. /* eslint-disable max-classes-per-file */
  1272. /**
  1273. * The error that is thrown when an argument passed in is null.
  1274. *
  1275. * @export
  1276. * @class ArgumentNullError
  1277. * @extends {Error}
  1278. */
  1279. class ArgumentNullError extends Error {
  1280. /**
  1281. * Creates an instance of ArgumentNullError.
  1282. *
  1283. * @param {string} argumentName - Name of the argument that is null
  1284. *
  1285. * @memberOf ArgumentNullError
  1286. */
  1287. constructor(argumentName) {
  1288. super(argumentName);
  1289. this.name = "ArgumentNull";
  1290. this.message = argumentName;
  1291. }
  1292. }
  1293. exports.ArgumentNullError = ArgumentNullError;
  1294. /**
  1295. * The error that is thrown when an invalid operation is performed in the code.
  1296. *
  1297. * @export
  1298. * @class InvalidOperationError
  1299. * @extends {Error}
  1300. */
  1301. class InvalidOperationError extends Error {
  1302. /**
  1303. * Creates an instance of InvalidOperationError.
  1304. *
  1305. * @param {string} error - The error
  1306. *
  1307. * @memberOf InvalidOperationError
  1308. */
  1309. constructor(error) {
  1310. super(error);
  1311. this.name = "InvalidOperation";
  1312. this.message = error;
  1313. }
  1314. }
  1315. exports.InvalidOperationError = InvalidOperationError;
  1316. /**
  1317. * The error that is thrown when an object is disposed.
  1318. *
  1319. * @export
  1320. * @class ObjectDisposedError
  1321. * @extends {Error}
  1322. */
  1323. class ObjectDisposedError extends Error {
  1324. /**
  1325. * Creates an instance of ObjectDisposedError.
  1326. *
  1327. * @param {string} objectName - The object that is disposed
  1328. * @param {string} error - The error
  1329. *
  1330. * @memberOf ObjectDisposedError
  1331. */
  1332. constructor(objectName, error) {
  1333. super(error);
  1334. this.name = objectName + "ObjectDisposed";
  1335. this.message = error;
  1336. }
  1337. }
  1338. exports.ObjectDisposedError = ObjectDisposedError;
  1339. /***/ }),
  1340. /* 27 */
  1341. /***/ ((__unused_webpack_module, exports) => {
  1342. "use strict";
  1343. // Copyright (c) Microsoft Corporation. All rights reserved.
  1344. // Licensed under the MIT license.
  1345. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1346. exports.ConnectionOpenResponse = void 0;
  1347. class ConnectionOpenResponse {
  1348. constructor(statusCode, reason) {
  1349. this.privStatusCode = statusCode;
  1350. this.privReason = reason;
  1351. }
  1352. get statusCode() {
  1353. return this.privStatusCode;
  1354. }
  1355. get reason() {
  1356. return this.privReason;
  1357. }
  1358. }
  1359. exports.ConnectionOpenResponse = ConnectionOpenResponse;
  1360. /***/ }),
  1361. /* 28 */
  1362. /***/ ((__unused_webpack_module, exports) => {
  1363. "use strict";
  1364. // Copyright (c) Microsoft Corporation. All rights reserved.
  1365. // Licensed under the MIT license.
  1366. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1367. exports.DeferralMap = void 0;
  1368. /**
  1369. * The error that is thrown when an argument passed in is null.
  1370. *
  1371. * @export
  1372. * @class DefferalMap
  1373. */
  1374. class DeferralMap {
  1375. constructor() {
  1376. this.privMap = {};
  1377. }
  1378. add(id, deferral) {
  1379. this.privMap[id] = deferral;
  1380. }
  1381. getId(id) {
  1382. return this.privMap[id];
  1383. }
  1384. complete(id, result) {
  1385. try {
  1386. this.privMap[id].resolve(result);
  1387. }
  1388. catch (error) {
  1389. this.privMap[id].reject(error);
  1390. }
  1391. finally {
  1392. this.privMap[id] = undefined;
  1393. }
  1394. }
  1395. }
  1396. exports.DeferralMap = DeferralMap;
  1397. /***/ }),
  1398. /* 29 */
  1399. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1400. "use strict";
  1401. // Copyright (c) Microsoft Corporation. All rights reserved.
  1402. // Licensed under the MIT license.
  1403. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1404. exports.SendingAgentContextMessageEvent = exports.DialogEvent = void 0;
  1405. const PlatformEvent_js_1 = __webpack_require__(6);
  1406. class DialogEvent extends PlatformEvent_js_1.PlatformEvent {
  1407. constructor(eventName, eventType = PlatformEvent_js_1.EventType.Info) {
  1408. super(eventName, eventType);
  1409. }
  1410. }
  1411. exports.DialogEvent = DialogEvent;
  1412. class SendingAgentContextMessageEvent extends DialogEvent {
  1413. constructor(agentConfig) {
  1414. super("SendingAgentContextMessageEvent");
  1415. this.privAgentConfig = agentConfig;
  1416. }
  1417. get agentConfig() {
  1418. return this.privAgentConfig;
  1419. }
  1420. }
  1421. exports.SendingAgentContextMessageEvent = SendingAgentContextMessageEvent;
  1422. /***/ }),
  1423. /* 30 */
  1424. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1425. "use strict";
  1426. // Copyright (c) Microsoft Corporation. All rights reserved.
  1427. // Licensed under the MIT license.
  1428. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1429. exports.Events = void 0;
  1430. const Error_js_1 = __webpack_require__(26);
  1431. const EventSource_js_1 = __webpack_require__(31);
  1432. class Events {
  1433. static setEventSource(eventSource) {
  1434. if (!eventSource) {
  1435. throw new Error_js_1.ArgumentNullError("eventSource");
  1436. }
  1437. Events.privInstance = eventSource;
  1438. }
  1439. static get instance() {
  1440. return Events.privInstance;
  1441. }
  1442. }
  1443. exports.Events = Events;
  1444. Events.privInstance = new EventSource_js_1.EventSource();
  1445. /***/ }),
  1446. /* 31 */
  1447. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1448. "use strict";
  1449. // Copyright (c) Microsoft Corporation. All rights reserved.
  1450. // Licensed under the MIT license.
  1451. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1452. exports.EventSource = void 0;
  1453. const Error_js_1 = __webpack_require__(26);
  1454. const Guid_js_1 = __webpack_require__(7);
  1455. class EventSource {
  1456. constructor(metadata) {
  1457. this.privEventListeners = {};
  1458. this.privIsDisposed = false;
  1459. this.privConsoleListener = undefined;
  1460. this.privMetadata = metadata;
  1461. }
  1462. onEvent(event) {
  1463. if (this.isDisposed()) {
  1464. throw (new Error_js_1.ObjectDisposedError("EventSource"));
  1465. }
  1466. if (this.metadata) {
  1467. for (const paramName in this.metadata) {
  1468. if (paramName) {
  1469. if (event.metadata) {
  1470. if (!event.metadata[paramName]) {
  1471. event.metadata[paramName] = this.metadata[paramName];
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. for (const eventId in this.privEventListeners) {
  1478. if (eventId && this.privEventListeners[eventId]) {
  1479. this.privEventListeners[eventId](event);
  1480. }
  1481. }
  1482. }
  1483. attach(onEventCallback) {
  1484. const id = (0, Guid_js_1.createNoDashGuid)();
  1485. this.privEventListeners[id] = onEventCallback;
  1486. return {
  1487. detach: () => {
  1488. delete this.privEventListeners[id];
  1489. return Promise.resolve();
  1490. },
  1491. };
  1492. }
  1493. attachListener(listener) {
  1494. return this.attach((e) => listener.onEvent(e));
  1495. }
  1496. attachConsoleListener(listener) {
  1497. if (!!this.privConsoleListener) {
  1498. void this.privConsoleListener.detach(); // Detach implementation for eventListeners is synchronous
  1499. }
  1500. this.privConsoleListener = this.attach((e) => listener.onEvent(e));
  1501. return this.privConsoleListener;
  1502. }
  1503. isDisposed() {
  1504. return this.privIsDisposed;
  1505. }
  1506. dispose() {
  1507. this.privEventListeners = null;
  1508. this.privIsDisposed = true;
  1509. }
  1510. get metadata() {
  1511. return this.privMetadata;
  1512. }
  1513. }
  1514. exports.EventSource = EventSource;
  1515. /***/ }),
  1516. /* 32 */
  1517. /***/ ((__unused_webpack_module, exports) => {
  1518. "use strict";
  1519. // Copyright (c) Microsoft Corporation. All rights reserved.
  1520. // Licensed under the MIT license.
  1521. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1522. /***/ }),
  1523. /* 33 */
  1524. /***/ ((__unused_webpack_module, exports) => {
  1525. "use strict";
  1526. // Copyright (c) Microsoft Corporation. All rights reserved.
  1527. // Licensed under the MIT license.
  1528. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1529. exports.ConnectionState = void 0;
  1530. var ConnectionState;
  1531. (function (ConnectionState) {
  1532. ConnectionState[ConnectionState["None"] = 0] = "None";
  1533. ConnectionState[ConnectionState["Connected"] = 1] = "Connected";
  1534. ConnectionState[ConnectionState["Connecting"] = 2] = "Connecting";
  1535. ConnectionState[ConnectionState["Disconnected"] = 3] = "Disconnected";
  1536. })(ConnectionState = exports.ConnectionState || (exports.ConnectionState = {}));
  1537. /***/ }),
  1538. /* 34 */
  1539. /***/ ((__unused_webpack_module, exports) => {
  1540. "use strict";
  1541. // Copyright (c) Microsoft Corporation. All rights reserved.
  1542. // Licensed under the MIT license.
  1543. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1544. /***/ }),
  1545. /* 35 */
  1546. /***/ ((__unused_webpack_module, exports) => {
  1547. "use strict";
  1548. // Copyright (c) Microsoft Corporation. All rights reserved.
  1549. // Licensed under the MIT license.
  1550. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1551. /***/ }),
  1552. /* 36 */
  1553. /***/ ((__unused_webpack_module, exports) => {
  1554. "use strict";
  1555. // Copyright (c) Microsoft Corporation. All rights reserved.
  1556. // Licensed under the MIT license.
  1557. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1558. /***/ }),
  1559. /* 37 */
  1560. /***/ ((__unused_webpack_module, exports) => {
  1561. "use strict";
  1562. // Copyright (c) Microsoft Corporation. All rights reserved.
  1563. // Licensed under the MIT license.
  1564. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1565. /***/ }),
  1566. /* 38 */
  1567. /***/ ((__unused_webpack_module, exports) => {
  1568. "use strict";
  1569. // Copyright (c) Microsoft Corporation. All rights reserved.
  1570. // Licensed under the MIT license.
  1571. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1572. /***/ }),
  1573. /* 39 */
  1574. /***/ ((__unused_webpack_module, exports) => {
  1575. "use strict";
  1576. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1577. /***/ }),
  1578. /* 40 */
  1579. /***/ ((__unused_webpack_module, exports) => {
  1580. "use strict";
  1581. // Copyright (c) Microsoft Corporation. All rights reserved.
  1582. // Licensed under the MIT license.
  1583. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1584. /***/ }),
  1585. /* 41 */
  1586. /***/ ((__unused_webpack_module, exports) => {
  1587. "use strict";
  1588. // Copyright (c) Microsoft Corporation. All rights reserved.
  1589. // Licensed under the MIT license.
  1590. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1591. /***/ }),
  1592. /* 42 */
  1593. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1594. "use strict";
  1595. // Copyright (c) Microsoft Corporation. All rights reserved.
  1596. // Licensed under the MIT license.
  1597. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1598. exports.List = void 0;
  1599. const Error_js_1 = __webpack_require__(26);
  1600. class List {
  1601. constructor(list) {
  1602. this.privSubscriptionIdCounter = 0;
  1603. this.privAddSubscriptions = {};
  1604. this.privRemoveSubscriptions = {};
  1605. this.privDisposedSubscriptions = {};
  1606. this.privDisposeReason = null;
  1607. this.privList = [];
  1608. // copy the list rather than taking as is.
  1609. if (list) {
  1610. for (const item of list) {
  1611. this.privList.push(item);
  1612. }
  1613. }
  1614. }
  1615. get(itemIndex) {
  1616. this.throwIfDisposed();
  1617. return this.privList[itemIndex];
  1618. }
  1619. first() {
  1620. return this.get(0);
  1621. }
  1622. last() {
  1623. return this.get(this.length() - 1);
  1624. }
  1625. add(item) {
  1626. this.throwIfDisposed();
  1627. this.insertAt(this.privList.length, item);
  1628. }
  1629. insertAt(index, item) {
  1630. this.throwIfDisposed();
  1631. if (index === 0) {
  1632. this.privList.unshift(item);
  1633. }
  1634. else if (index === this.privList.length) {
  1635. this.privList.push(item);
  1636. }
  1637. else {
  1638. this.privList.splice(index, 0, item);
  1639. }
  1640. this.triggerSubscriptions(this.privAddSubscriptions);
  1641. }
  1642. removeFirst() {
  1643. this.throwIfDisposed();
  1644. return this.removeAt(0);
  1645. }
  1646. removeLast() {
  1647. this.throwIfDisposed();
  1648. return this.removeAt(this.length() - 1);
  1649. }
  1650. removeAt(index) {
  1651. this.throwIfDisposed();
  1652. return this.remove(index, 1)[0];
  1653. }
  1654. remove(index, count) {
  1655. this.throwIfDisposed();
  1656. const removedElements = this.privList.splice(index, count);
  1657. this.triggerSubscriptions(this.privRemoveSubscriptions);
  1658. return removedElements;
  1659. }
  1660. clear() {
  1661. this.throwIfDisposed();
  1662. this.remove(0, this.length());
  1663. }
  1664. length() {
  1665. this.throwIfDisposed();
  1666. return this.privList.length;
  1667. }
  1668. onAdded(addedCallback) {
  1669. this.throwIfDisposed();
  1670. const subscriptionId = this.privSubscriptionIdCounter++;
  1671. this.privAddSubscriptions[subscriptionId] = addedCallback;
  1672. return {
  1673. detach: () => {
  1674. delete this.privAddSubscriptions[subscriptionId];
  1675. return Promise.resolve();
  1676. },
  1677. };
  1678. }
  1679. onRemoved(removedCallback) {
  1680. this.throwIfDisposed();
  1681. const subscriptionId = this.privSubscriptionIdCounter++;
  1682. this.privRemoveSubscriptions[subscriptionId] = removedCallback;
  1683. return {
  1684. detach: () => {
  1685. delete this.privRemoveSubscriptions[subscriptionId];
  1686. return Promise.resolve();
  1687. },
  1688. };
  1689. }
  1690. onDisposed(disposedCallback) {
  1691. this.throwIfDisposed();
  1692. const subscriptionId = this.privSubscriptionIdCounter++;
  1693. this.privDisposedSubscriptions[subscriptionId] = disposedCallback;
  1694. return {
  1695. detach: () => {
  1696. delete this.privDisposedSubscriptions[subscriptionId];
  1697. return Promise.resolve();
  1698. },
  1699. };
  1700. }
  1701. join(seperator) {
  1702. this.throwIfDisposed();
  1703. return this.privList.join(seperator);
  1704. }
  1705. toArray() {
  1706. const cloneCopy = Array();
  1707. this.privList.forEach((val) => {
  1708. cloneCopy.push(val);
  1709. });
  1710. return cloneCopy;
  1711. }
  1712. any(callback) {
  1713. this.throwIfDisposed();
  1714. if (callback) {
  1715. return this.where(callback).length() > 0;
  1716. }
  1717. else {
  1718. return this.length() > 0;
  1719. }
  1720. }
  1721. all(callback) {
  1722. this.throwIfDisposed();
  1723. return this.where(callback).length() === this.length();
  1724. }
  1725. forEach(callback) {
  1726. this.throwIfDisposed();
  1727. for (let i = 0; i < this.length(); i++) {
  1728. callback(this.privList[i], i);
  1729. }
  1730. }
  1731. select(callback) {
  1732. this.throwIfDisposed();
  1733. const selectList = [];
  1734. for (let i = 0; i < this.privList.length; i++) {
  1735. selectList.push(callback(this.privList[i], i));
  1736. }
  1737. return new List(selectList);
  1738. }
  1739. where(callback) {
  1740. this.throwIfDisposed();
  1741. const filteredList = new List();
  1742. for (let i = 0; i < this.privList.length; i++) {
  1743. if (callback(this.privList[i], i)) {
  1744. filteredList.add(this.privList[i]);
  1745. }
  1746. }
  1747. return filteredList;
  1748. }
  1749. orderBy(compareFn) {
  1750. this.throwIfDisposed();
  1751. const clonedArray = this.toArray();
  1752. const orderedArray = clonedArray.sort(compareFn);
  1753. return new List(orderedArray);
  1754. }
  1755. orderByDesc(compareFn) {
  1756. this.throwIfDisposed();
  1757. return this.orderBy((a, b) => compareFn(b, a));
  1758. }
  1759. clone() {
  1760. this.throwIfDisposed();
  1761. return new List(this.toArray());
  1762. }
  1763. concat(list) {
  1764. this.throwIfDisposed();
  1765. return new List(this.privList.concat(list.toArray()));
  1766. }
  1767. concatArray(array) {
  1768. this.throwIfDisposed();
  1769. return new List(this.privList.concat(array));
  1770. }
  1771. isDisposed() {
  1772. return this.privList == null;
  1773. }
  1774. dispose(reason) {
  1775. if (!this.isDisposed()) {
  1776. this.privDisposeReason = reason;
  1777. this.privList = null;
  1778. this.privAddSubscriptions = null;
  1779. this.privRemoveSubscriptions = null;
  1780. this.triggerSubscriptions(this.privDisposedSubscriptions);
  1781. }
  1782. }
  1783. throwIfDisposed() {
  1784. if (this.isDisposed()) {
  1785. throw new Error_js_1.ObjectDisposedError("List", this.privDisposeReason);
  1786. }
  1787. }
  1788. triggerSubscriptions(subscriptions) {
  1789. if (subscriptions) {
  1790. for (const subscriptionId in subscriptions) {
  1791. if (subscriptionId) {
  1792. subscriptions[subscriptionId]();
  1793. }
  1794. }
  1795. }
  1796. }
  1797. }
  1798. exports.List = List;
  1799. /***/ }),
  1800. /* 43 */
  1801. /***/ ((__unused_webpack_module, exports) => {
  1802. "use strict";
  1803. // Copyright (c) Microsoft Corporation. All rights reserved.
  1804. // Licensed under the MIT license.
  1805. Object.defineProperty(exports, "__esModule", ({ value: true }));
  1806. exports.marshalPromiseToCallbacks = exports.Sink = exports.Deferred = exports.PromiseResultEventSource = exports.PromiseResult = exports.PromiseState = void 0;
  1807. /* eslint-disable max-classes-per-file, @typescript-eslint/typedef */
  1808. var PromiseState;
  1809. (function (PromiseState) {
  1810. PromiseState[PromiseState["None"] = 0] = "None";
  1811. PromiseState[PromiseState["Resolved"] = 1] = "Resolved";
  1812. PromiseState[PromiseState["Rejected"] = 2] = "Rejected";
  1813. })(PromiseState = exports.PromiseState || (exports.PromiseState = {}));
  1814. class PromiseResult {
  1815. constructor(promiseResultEventSource) {
  1816. this.throwIfError = () => {
  1817. if (this.isError) {
  1818. throw this.error;
  1819. }
  1820. };
  1821. promiseResultEventSource.on((result) => {
  1822. if (!this.privIsCompleted) {
  1823. this.privIsCompleted = true;
  1824. this.privIsError = false;
  1825. this.privResult = result;
  1826. }
  1827. }, (error) => {
  1828. if (!this.privIsCompleted) {
  1829. this.privIsCompleted = true;
  1830. this.privIsError = true;
  1831. this.privError = error;
  1832. }
  1833. });
  1834. }
  1835. get isCompleted() {
  1836. return this.privIsCompleted;
  1837. }
  1838. get isError() {
  1839. return this.privIsError;
  1840. }
  1841. get error() {
  1842. return this.privError;
  1843. }
  1844. get result() {
  1845. return this.privResult;
  1846. }
  1847. }
  1848. exports.PromiseResult = PromiseResult;
  1849. class PromiseResultEventSource {
  1850. constructor() {
  1851. this.setResult = (result) => {
  1852. this.privOnSetResult(result);
  1853. };
  1854. this.setError = (error) => {
  1855. this.privOnSetError(error);
  1856. };
  1857. this.on = (onSetResult, onSetError) => {
  1858. this.privOnSetResult = onSetResult;
  1859. this.privOnSetError = onSetError;
  1860. };
  1861. }
  1862. }
  1863. exports.PromiseResultEventSource = PromiseResultEventSource;
  1864. class Deferred {
  1865. constructor() {
  1866. this.resolve = (result) => {
  1867. this.privResolve(result);
  1868. return this;
  1869. };
  1870. this.reject = (error) => {
  1871. this.privReject(error);
  1872. return this;
  1873. };
  1874. // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
  1875. this.privPromise = new Promise((resolve, reject) => {
  1876. this.privResolve = resolve;
  1877. this.privReject = reject;
  1878. });
  1879. }
  1880. get promise() {
  1881. return this.privPromise;
  1882. }
  1883. }
  1884. exports.Deferred = Deferred;
  1885. class Sink {
  1886. constructor() {
  1887. this.privState = PromiseState.None;
  1888. this.privPromiseResult = null;
  1889. this.privPromiseResultEvents = null;
  1890. this.privSuccessHandlers = [];
  1891. this.privErrorHandlers = [];
  1892. this.privPromiseResultEvents = new PromiseResultEventSource();
  1893. this.privPromiseResult = new PromiseResult(this.privPromiseResultEvents);
  1894. }
  1895. get state() {
  1896. return this.privState;
  1897. }
  1898. get result() {
  1899. return this.privPromiseResult;
  1900. }
  1901. resolve(result) {
  1902. if (this.privState !== PromiseState.None) {
  1903. throw new Error("'Cannot resolve a completed promise'");
  1904. }
  1905. this.privState = PromiseState.Resolved;
  1906. this.privPromiseResultEvents.setResult(result);
  1907. for (let i = 0; i < this.privSuccessHandlers.length; i++) {
  1908. this.executeSuccessCallback(result, this.privSuccessHandlers[i], this.privErrorHandlers[i]);
  1909. }
  1910. this.detachHandlers();
  1911. }
  1912. reject(error) {
  1913. if (this.privState !== PromiseState.None) {
  1914. throw new Error("'Cannot reject a completed promise'");
  1915. }
  1916. this.privState = PromiseState.Rejected;
  1917. this.privPromiseResultEvents.setError(error);
  1918. for (const errorHandler of this.privErrorHandlers) {
  1919. this.executeErrorCallback(error, errorHandler);
  1920. }
  1921. this.detachHandlers();
  1922. }
  1923. on(successCallback, errorCallback) {
  1924. if (successCallback == null) {
  1925. // eslint-disable-next-line @typescript-eslint/no-empty-function
  1926. successCallback = () => { };
  1927. }
  1928. if (this.privState === PromiseState.None) {
  1929. this.privSuccessHandlers.push(successCallback);
  1930. this.privErrorHandlers.push(errorCallback);
  1931. }
  1932. else {
  1933. if (this.privState === PromiseState.Resolved) {
  1934. this.executeSuccessCallback(this.privPromiseResult.result, successCallback, errorCallback);
  1935. }
  1936. else if (this.privState === PromiseState.Rejected) {
  1937. this.executeErrorCallback(this.privPromiseResult.error, errorCallback);
  1938. }
  1939. this.detachHandlers();
  1940. }
  1941. }
  1942. executeSuccessCallback(result, successCallback, errorCallback) {
  1943. try {
  1944. successCallback(result);
  1945. }
  1946. catch (e) {
  1947. this.executeErrorCallback(`'Unhandled callback error: ${e}'`, errorCallback);
  1948. }
  1949. }
  1950. executeErrorCallback(error, errorCallback) {
  1951. if (errorCallback) {
  1952. try {
  1953. errorCallback(error);
  1954. }
  1955. catch (e) {
  1956. throw new Error(`'Unhandled callback error: ${e}. InnerError: ${error}'`);
  1957. }
  1958. }
  1959. else {
  1960. throw new Error(`'Unhandled error: ${error}'`);
  1961. }
  1962. }
  1963. detachHandlers() {
  1964. this.privErrorHandlers = [];
  1965. this.privSuccessHandlers = [];
  1966. }
  1967. }
  1968. exports.Sink = Sink;
  1969. // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
  1970. function marshalPromiseToCallbacks(promise, cb, err) {
  1971. promise.then((val) => {
  1972. try {
  1973. if (!!cb) {
  1974. cb(val);
  1975. }
  1976. }
  1977. catch (error) {
  1978. if (!!err) {
  1979. try {
  1980. if (error instanceof Error) {
  1981. const typedError = error;
  1982. err(typedError.name + ": " + typedError.message);
  1983. }
  1984. else {
  1985. err(error);
  1986. }
  1987. // eslint-disable-next-line no-empty
  1988. }
  1989. catch (error) { }
  1990. }
  1991. }
  1992. }, (error) => {
  1993. if (!!err) {
  1994. try {
  1995. if (error instanceof Error) {
  1996. const typedError = error;
  1997. err(typedError.name + ": " + typedError.message);
  1998. }
  1999. else {
  2000. err(error);
  2001. }
  2002. // eslint-disable-next-line no-empty
  2003. }
  2004. catch (error) { }
  2005. }
  2006. });
  2007. }
  2008. exports.marshalPromiseToCallbacks = marshalPromiseToCallbacks;
  2009. /***/ }),
  2010. /* 44 */
  2011. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2012. "use strict";
  2013. // Copyright (c) Microsoft Corporation. All rights reserved.
  2014. // Licensed under the MIT license.
  2015. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2016. exports.Queue = void 0;
  2017. const Error_js_1 = __webpack_require__(26);
  2018. const List_js_1 = __webpack_require__(42);
  2019. const Promise_js_1 = __webpack_require__(43);
  2020. var SubscriberType;
  2021. (function (SubscriberType) {
  2022. SubscriberType[SubscriberType["Dequeue"] = 0] = "Dequeue";
  2023. SubscriberType[SubscriberType["Peek"] = 1] = "Peek";
  2024. })(SubscriberType || (SubscriberType = {}));
  2025. class Queue {
  2026. constructor(list) {
  2027. this.privPromiseStore = new List_js_1.List();
  2028. this.privIsDrainInProgress = false;
  2029. this.privIsDisposing = false;
  2030. this.privDisposeReason = null;
  2031. this.privList = list ? list : new List_js_1.List();
  2032. this.privDetachables = [];
  2033. this.privSubscribers = new List_js_1.List();
  2034. this.privDetachables.push(this.privList.onAdded(() => this.drain()));
  2035. }
  2036. enqueue(item) {
  2037. this.throwIfDispose();
  2038. this.enqueueFromPromise(new Promise((resolve) => resolve(item)));
  2039. }
  2040. enqueueFromPromise(promise) {
  2041. this.throwIfDispose();
  2042. promise.then((val) => {
  2043. this.privList.add(val);
  2044. // eslint-disable-next-line @typescript-eslint/no-empty-function
  2045. }, () => { });
  2046. }
  2047. dequeue() {
  2048. this.throwIfDispose();
  2049. const deferredSubscriber = new Promise_js_1.Deferred();
  2050. if (this.privSubscribers) {
  2051. this.privSubscribers.add({ deferral: deferredSubscriber, type: SubscriberType.Dequeue });
  2052. this.drain();
  2053. }
  2054. return deferredSubscriber.promise;
  2055. }
  2056. peek() {
  2057. this.throwIfDispose();
  2058. const deferredSubscriber = new Promise_js_1.Deferred();
  2059. const subs = this.privSubscribers;
  2060. if (subs) {
  2061. this.privSubscribers.add({ deferral: deferredSubscriber, type: SubscriberType.Peek });
  2062. this.drain();
  2063. }
  2064. return deferredSubscriber.promise;
  2065. }
  2066. length() {
  2067. this.throwIfDispose();
  2068. return this.privList.length();
  2069. }
  2070. isDisposed() {
  2071. return this.privSubscribers == null;
  2072. }
  2073. async drainAndDispose(pendingItemProcessor, reason) {
  2074. if (!this.isDisposed() && !this.privIsDisposing) {
  2075. this.privDisposeReason = reason;
  2076. this.privIsDisposing = true;
  2077. const subs = this.privSubscribers;
  2078. if (subs) {
  2079. while (subs.length() > 0) {
  2080. const subscriber = subs.removeFirst();
  2081. // TODO: this needs work (Resolve(null) instead?).
  2082. subscriber.deferral.resolve(undefined);
  2083. // subscriber.deferral.reject("Disposed");
  2084. }
  2085. // note: this block assumes cooperative multitasking, i.e.,
  2086. // between the if-statement and the assignment there are no
  2087. // thread switches.
  2088. // Reason is that between the initial const = this.; and this
  2089. // point there is the derral.resolve() operation that might have
  2090. // caused recursive calls to the Queue, especially, calling
  2091. // Dispose() on the queue alredy (which would reset the var
  2092. // here to null!).
  2093. // That should generally hold true for javascript...
  2094. if (this.privSubscribers === subs) {
  2095. this.privSubscribers = subs;
  2096. }
  2097. }
  2098. for (const detachable of this.privDetachables) {
  2099. await detachable.detach();
  2100. }
  2101. if (this.privPromiseStore.length() > 0 && pendingItemProcessor) {
  2102. const promiseArray = [];
  2103. this.privPromiseStore.toArray().forEach((wrapper) => {
  2104. promiseArray.push(wrapper);
  2105. });
  2106. return Promise.all(promiseArray).finally(() => {
  2107. this.privSubscribers = null;
  2108. this.privList.forEach((item) => {
  2109. pendingItemProcessor(item);
  2110. });
  2111. this.privList = null;
  2112. return;
  2113. }).then();
  2114. }
  2115. else {
  2116. this.privSubscribers = null;
  2117. this.privList = null;
  2118. }
  2119. }
  2120. }
  2121. async dispose(reason) {
  2122. await this.drainAndDispose(null, reason);
  2123. }
  2124. drain() {
  2125. if (!this.privIsDrainInProgress && !this.privIsDisposing) {
  2126. this.privIsDrainInProgress = true;
  2127. const subs = this.privSubscribers;
  2128. const lists = this.privList;
  2129. if (subs && lists) {
  2130. while (lists.length() > 0 && subs.length() > 0 && !this.privIsDisposing) {
  2131. const subscriber = subs.removeFirst();
  2132. if (subscriber.type === SubscriberType.Peek) {
  2133. subscriber.deferral.resolve(lists.first());
  2134. }
  2135. else {
  2136. const dequeuedItem = lists.removeFirst();
  2137. subscriber.deferral.resolve(dequeuedItem);
  2138. }
  2139. }
  2140. // note: this block assumes cooperative multitasking, i.e.,
  2141. // between the if-statement and the assignment there are no
  2142. // thread switches.
  2143. // Reason is that between the initial const = this.; and this
  2144. // point there is the derral.resolve() operation that might have
  2145. // caused recursive calls to the Queue, especially, calling
  2146. // Dispose() on the queue alredy (which would reset the var
  2147. // here to null!).
  2148. // That should generally hold true for javascript...
  2149. if (this.privSubscribers === subs) {
  2150. this.privSubscribers = subs;
  2151. }
  2152. // note: this block assumes cooperative multitasking, i.e.,
  2153. // between the if-statement and the assignment there are no
  2154. // thread switches.
  2155. // Reason is that between the initial const = this.; and this
  2156. // point there is the derral.resolve() operation that might have
  2157. // caused recursive calls to the Queue, especially, calling
  2158. // Dispose() on the queue alredy (which would reset the var
  2159. // here to null!).
  2160. // That should generally hold true for javascript...
  2161. if (this.privList === lists) {
  2162. this.privList = lists;
  2163. }
  2164. }
  2165. this.privIsDrainInProgress = false;
  2166. }
  2167. }
  2168. throwIfDispose() {
  2169. if (this.isDisposed()) {
  2170. if (this.privDisposeReason) {
  2171. throw new Error_js_1.InvalidOperationError(this.privDisposeReason);
  2172. }
  2173. throw new Error_js_1.ObjectDisposedError("Queue");
  2174. }
  2175. else if (this.privIsDisposing) {
  2176. throw new Error_js_1.InvalidOperationError("Queue disposing");
  2177. }
  2178. }
  2179. }
  2180. exports.Queue = Queue;
  2181. /***/ }),
  2182. /* 45 */
  2183. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2184. "use strict";
  2185. /* eslint-disable @typescript-eslint/no-unsafe-assignment */
  2186. // Copyright (c) Microsoft Corporation. All rights reserved.
  2187. // Licensed under the MIT license.
  2188. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2189. exports.RawWebsocketMessage = void 0;
  2190. const ConnectionMessage_js_1 = __webpack_require__(25);
  2191. const Error_js_1 = __webpack_require__(26);
  2192. const Guid_js_1 = __webpack_require__(7);
  2193. class RawWebsocketMessage {
  2194. constructor(messageType, payload, id) {
  2195. this.privPayload = null;
  2196. if (!payload) {
  2197. throw new Error_js_1.ArgumentNullError("payload");
  2198. }
  2199. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
  2200. if (messageType === ConnectionMessage_js_1.MessageType.Binary && Object.getPrototypeOf(payload).constructor.name !== "ArrayBuffer") {
  2201. throw new Error_js_1.InvalidOperationError("Payload must be ArrayBuffer");
  2202. }
  2203. if (messageType === ConnectionMessage_js_1.MessageType.Text && !(typeof (payload) === "string")) {
  2204. throw new Error_js_1.InvalidOperationError("Payload must be a string");
  2205. }
  2206. this.privMessageType = messageType;
  2207. this.privPayload = payload;
  2208. this.privId = id ? id : (0, Guid_js_1.createNoDashGuid)();
  2209. }
  2210. get messageType() {
  2211. return this.privMessageType;
  2212. }
  2213. get payload() {
  2214. // eslint-disable-next-line @typescript-eslint/no-unsafe-return
  2215. return this.privPayload;
  2216. }
  2217. get textContent() {
  2218. if (this.privMessageType === ConnectionMessage_js_1.MessageType.Binary) {
  2219. throw new Error_js_1.InvalidOperationError("Not supported for binary message");
  2220. }
  2221. return this.privPayload;
  2222. }
  2223. get binaryContent() {
  2224. if (this.privMessageType === ConnectionMessage_js_1.MessageType.Text) {
  2225. throw new Error_js_1.InvalidOperationError("Not supported for text message");
  2226. }
  2227. return this.privPayload;
  2228. }
  2229. get id() {
  2230. return this.privId;
  2231. }
  2232. }
  2233. exports.RawWebsocketMessage = RawWebsocketMessage;
  2234. /***/ }),
  2235. /* 46 */
  2236. /***/ ((__unused_webpack_module, exports) => {
  2237. "use strict";
  2238. // Copyright (c) Microsoft Corporation. All rights reserved.
  2239. // Licensed under the MIT license.
  2240. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2241. exports.RiffPcmEncoder = void 0;
  2242. class RiffPcmEncoder {
  2243. constructor(actualSampleRate, desiredSampleRate) {
  2244. this.privActualSampleRate = actualSampleRate;
  2245. this.privDesiredSampleRate = desiredSampleRate;
  2246. }
  2247. encode(actualAudioFrame) {
  2248. const audioFrame = this.downSampleAudioFrame(actualAudioFrame, this.privActualSampleRate, this.privDesiredSampleRate);
  2249. if (!audioFrame) {
  2250. return null;
  2251. }
  2252. const audioLength = audioFrame.length * 2;
  2253. const buffer = new ArrayBuffer(audioLength);
  2254. const view = new DataView(buffer);
  2255. this.floatTo16BitPCM(view, 0, audioFrame);
  2256. return buffer;
  2257. }
  2258. setString(view, offset, str) {
  2259. for (let i = 0; i < str.length; i++) {
  2260. view.setUint8(offset + i, str.charCodeAt(i));
  2261. }
  2262. }
  2263. floatTo16BitPCM(view, offset, input) {
  2264. for (let i = 0; i < input.length; i++, offset += 2) {
  2265. const s = Math.max(-1, Math.min(1, input[i]));
  2266. view.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
  2267. }
  2268. }
  2269. downSampleAudioFrame(srcFrame, srcRate, dstRate) {
  2270. if (!srcFrame) {
  2271. return null;
  2272. }
  2273. if (dstRate === srcRate || dstRate > srcRate) {
  2274. return srcFrame;
  2275. }
  2276. const ratio = srcRate / dstRate;
  2277. const dstLength = Math.round(srcFrame.length / ratio);
  2278. const dstFrame = new Float32Array(dstLength);
  2279. let srcOffset = 0;
  2280. let dstOffset = 0;
  2281. while (dstOffset < dstLength) {
  2282. const nextSrcOffset = Math.round((dstOffset + 1) * ratio);
  2283. let accum = 0;
  2284. let count = 0;
  2285. while (srcOffset < nextSrcOffset && srcOffset < srcFrame.length) {
  2286. accum += srcFrame[srcOffset++];
  2287. count++;
  2288. }
  2289. dstFrame[dstOffset++] = accum / count;
  2290. }
  2291. return dstFrame;
  2292. }
  2293. }
  2294. exports.RiffPcmEncoder = RiffPcmEncoder;
  2295. /***/ }),
  2296. /* 47 */
  2297. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2298. "use strict";
  2299. // Copyright (c) Microsoft Corporation. All rights reserved.
  2300. // Licensed under the MIT license.
  2301. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2302. exports.Stream = void 0;
  2303. const Error_js_1 = __webpack_require__(26);
  2304. const Guid_js_1 = __webpack_require__(7);
  2305. const Queue_js_1 = __webpack_require__(44);
  2306. class Stream {
  2307. constructor(streamId) {
  2308. this.privIsWriteEnded = false;
  2309. this.privIsReadEnded = false;
  2310. this.privId = streamId ? streamId : (0, Guid_js_1.createNoDashGuid)();
  2311. this.privReaderQueue = new Queue_js_1.Queue();
  2312. }
  2313. get isClosed() {
  2314. return this.privIsWriteEnded;
  2315. }
  2316. get isReadEnded() {
  2317. return this.privIsReadEnded;
  2318. }
  2319. get id() {
  2320. return this.privId;
  2321. }
  2322. close() {
  2323. if (!this.privIsWriteEnded) {
  2324. this.writeStreamChunk({
  2325. buffer: null,
  2326. isEnd: true,
  2327. timeReceived: Date.now(),
  2328. });
  2329. this.privIsWriteEnded = true;
  2330. }
  2331. }
  2332. writeStreamChunk(streamChunk) {
  2333. this.throwIfClosed();
  2334. if (!this.privReaderQueue.isDisposed()) {
  2335. try {
  2336. this.privReaderQueue.enqueue(streamChunk);
  2337. }
  2338. catch (e) {
  2339. // Do nothing
  2340. }
  2341. }
  2342. }
  2343. read() {
  2344. if (this.privIsReadEnded) {
  2345. throw new Error_js_1.InvalidOperationError("Stream read has already finished");
  2346. }
  2347. return this.privReaderQueue
  2348. .dequeue()
  2349. .then(async (streamChunk) => {
  2350. if (streamChunk === undefined || streamChunk.isEnd) {
  2351. await this.privReaderQueue.dispose("End of stream reached");
  2352. }
  2353. return streamChunk;
  2354. });
  2355. }
  2356. readEnded() {
  2357. if (!this.privIsReadEnded) {
  2358. this.privIsReadEnded = true;
  2359. this.privReaderQueue = new Queue_js_1.Queue();
  2360. }
  2361. }
  2362. throwIfClosed() {
  2363. if (this.privIsWriteEnded) {
  2364. throw new Error_js_1.InvalidOperationError("Stream closed");
  2365. }
  2366. }
  2367. }
  2368. exports.Stream = Stream;
  2369. /***/ }),
  2370. /* 48 */
  2371. /***/ ((__unused_webpack_module, exports) => {
  2372. "use strict";
  2373. // Copyright (c) Microsoft Corporation. All rights reserved.
  2374. // Licensed under the MIT license.
  2375. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2376. exports.TranslationStatus = void 0;
  2377. /**
  2378. * Defines translation status.
  2379. * @class TranslationStatus
  2380. */
  2381. var TranslationStatus;
  2382. (function (TranslationStatus) {
  2383. /**
  2384. * @member TranslationStatus.Success
  2385. */
  2386. TranslationStatus[TranslationStatus["Success"] = 0] = "Success";
  2387. /**
  2388. * @member TranslationStatus.Error
  2389. */
  2390. TranslationStatus[TranslationStatus["Error"] = 1] = "Error";
  2391. })(TranslationStatus = exports.TranslationStatus || (exports.TranslationStatus = {}));
  2392. /***/ }),
  2393. /* 49 */
  2394. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2395. "use strict";
  2396. // Copyright (c) Microsoft Corporation. All rights reserved.
  2397. // Licensed under the MIT license.
  2398. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2399. exports.ChunkedArrayBufferStream = void 0;
  2400. const Exports_js_1 = __webpack_require__(4);
  2401. class ChunkedArrayBufferStream extends Exports_js_1.Stream {
  2402. constructor(targetChunkSize, streamId) {
  2403. super(streamId);
  2404. this.privTargetChunkSize = Math.round(targetChunkSize);
  2405. this.privNextBufferReadyBytes = 0;
  2406. }
  2407. writeStreamChunk(chunk) {
  2408. // No pending write, and the buffer is the right size so write it.
  2409. if (chunk.isEnd ||
  2410. (0 === this.privNextBufferReadyBytes && chunk.buffer.byteLength === this.privTargetChunkSize)) {
  2411. super.writeStreamChunk(chunk);
  2412. return;
  2413. }
  2414. let bytesCopiedFromBuffer = 0;
  2415. while (bytesCopiedFromBuffer < chunk.buffer.byteLength) {
  2416. // Fill the next buffer.
  2417. if (undefined === this.privNextBufferToWrite) {
  2418. this.privNextBufferToWrite = new ArrayBuffer(this.privTargetChunkSize);
  2419. this.privNextBufferStartTime = chunk.timeReceived;
  2420. }
  2421. // Find out how many bytes we can copy into the read buffer.
  2422. const bytesToCopy = Math.min(chunk.buffer.byteLength - bytesCopiedFromBuffer, this.privTargetChunkSize - this.privNextBufferReadyBytes);
  2423. const targetView = new Uint8Array(this.privNextBufferToWrite);
  2424. const sourceView = new Uint8Array(chunk.buffer.slice(bytesCopiedFromBuffer, bytesToCopy + bytesCopiedFromBuffer));
  2425. targetView.set(sourceView, this.privNextBufferReadyBytes);
  2426. this.privNextBufferReadyBytes += bytesToCopy;
  2427. bytesCopiedFromBuffer += bytesToCopy;
  2428. // Are we ready to write?
  2429. if (this.privNextBufferReadyBytes === this.privTargetChunkSize) {
  2430. super.writeStreamChunk({
  2431. buffer: this.privNextBufferToWrite,
  2432. isEnd: false,
  2433. timeReceived: this.privNextBufferStartTime,
  2434. });
  2435. this.privNextBufferReadyBytes = 0;
  2436. this.privNextBufferToWrite = undefined;
  2437. }
  2438. }
  2439. }
  2440. close() {
  2441. // Send whatever is pending, then close the base class.
  2442. if (0 !== this.privNextBufferReadyBytes && !this.isClosed) {
  2443. super.writeStreamChunk({
  2444. buffer: this.privNextBufferToWrite.slice(0, this.privNextBufferReadyBytes),
  2445. isEnd: false,
  2446. timeReceived: this.privNextBufferStartTime,
  2447. });
  2448. }
  2449. super.close();
  2450. }
  2451. }
  2452. exports.ChunkedArrayBufferStream = ChunkedArrayBufferStream;
  2453. /***/ }),
  2454. /* 50 */
  2455. /***/ ((__unused_webpack_module, exports) => {
  2456. "use strict";
  2457. // Copyright (c) Microsoft Corporation. All rights reserved.
  2458. // Licensed under the MIT license.
  2459. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2460. /***/ }),
  2461. /* 51 */
  2462. /***/ ((__unused_webpack_module, exports) => {
  2463. "use strict";
  2464. // Copyright (c) Microsoft Corporation. All rights reserved.
  2465. // Licensed under the MIT license.
  2466. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2467. exports.Timeout = void 0;
  2468. class Timeout {
  2469. static load() {
  2470. // Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
  2471. const scheduledTimeoutFunctions = new Map([[0, () => { }]]); // eslint-disable-line @typescript-eslint/no-empty-function
  2472. const unhandledRequests = new Map();
  2473. // eslint-disable-next-line
  2474. const workerScript = `!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=14)}([function(e,t,n){"use strict";n.d(t,"a",(function(){return i})),n.d(t,"b",(function(){return u})),n.d(t,"c",(function(){return a})),n.d(t,"d",(function(){return d}));const r=new Map,o=new Map,i=e=>{const t=r.get(e);if(void 0===t)throw new Error('There is no interval scheduled with the given id "'.concat(e,'".'));clearTimeout(t),r.delete(e)},u=e=>{const t=o.get(e);if(void 0===t)throw new Error('There is no timeout scheduled with the given id "'.concat(e,'".'));clearTimeout(t),o.delete(e)},f=(e,t)=>{let n,r;if("performance"in self){const o=performance.now();n=o,r=e-Math.max(0,o-t)}else n=Date.now(),r=e;return{expected:n+r,remainingDelay:r}},c=(e,t,n,r)=>{const o="performance"in self?performance.now():Date.now();o>n?postMessage({id:null,method:"call",params:{timerId:t}}):e.set(t,setTimeout(c,n-o,e,t,n))},a=(e,t,n)=>{const{expected:o,remainingDelay:i}=f(e,n);r.set(t,setTimeout(c,i,r,t,o))},d=(e,t,n)=>{const{expected:r,remainingDelay:i}=f(e,n);o.set(t,setTimeout(c,i,o,t,r))}},function(e,t,n){"use strict";n.r(t);var r=n(2);for(var o in r)"default"!==o&&function(e){n.d(t,e,(function(){return r[e]}))}(o);var i=n(3);for(var o in i)"default"!==o&&function(e){n.d(t,e,(function(){return i[e]}))}(o);var u=n(4);for(var o in u)"default"!==o&&function(e){n.d(t,e,(function(){return u[e]}))}(o);var f=n(5);for(var o in f)"default"!==o&&function(e){n.d(t,e,(function(){return f[e]}))}(o);var c=n(6);for(var o in c)"default"!==o&&function(e){n.d(t,e,(function(){return c[e]}))}(o);var a=n(7);for(var o in a)"default"!==o&&function(e){n.d(t,e,(function(){return a[e]}))}(o);var d=n(8);for(var o in d)"default"!==o&&function(e){n.d(t,e,(function(){return d[e]}))}(o);var s=n(9);for(var o in s)"default"!==o&&function(e){n.d(t,e,(function(){return s[e]}))}(o)},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t,n){"use strict";n.r(t);var r=n(11);for(var o in r)"default"!==o&&function(e){n.d(t,e,(function(){return r[e]}))}(o);var i=n(12);for(var o in i)"default"!==o&&function(e){n.d(t,e,(function(){return i[e]}))}(o);var u=n(13);for(var o in u)"default"!==o&&function(e){n.d(t,e,(function(){return u[e]}))}(o)},function(e,t){},function(e,t){},function(e,t){},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n(1);for(var i in o)"default"!==i&&function(e){n.d(t,e,(function(){return o[e]}))}(i);var u=n(10);for(var i in u)"default"!==i&&function(e){n.d(t,e,(function(){return u[e]}))}(i);addEventListener("message",({data:e})=>{try{if("clear"===e.method){const{id:t,params:{timerId:n}}=e;Object(r.b)(n),postMessage({error:null,id:t})}else{if("set"!==e.method)throw new Error('The given method "'.concat(e.method,'" is not supported'));{const{params:{delay:t,now:n,timerId:o}}=e;Object(r.d)(t,o,n)}}}catch(t){postMessage({error:{message:t.message},id:e.id,result:null})}})}]);`;
  2475. const workerUrl = "data:text/javascript;base64," + btoa(workerScript);
  2476. const worker = new Worker(workerUrl);
  2477. worker.addEventListener("message", ({ data }) => {
  2478. if (Timeout.isCallNotification(data)) {
  2479. const { params: { timerId } } = data;
  2480. const idOrFunc = scheduledTimeoutFunctions.get(timerId);
  2481. if (typeof idOrFunc === "number") {
  2482. const unhandledTimerId = unhandledRequests.get(idOrFunc);
  2483. if (unhandledTimerId === undefined ||
  2484. unhandledTimerId !== timerId) {
  2485. throw new Error("The timer is in an undefined state.");
  2486. }
  2487. }
  2488. else if (typeof idOrFunc !== "undefined") {
  2489. idOrFunc();
  2490. // A timeout can be safely deleted because it is only called once.
  2491. scheduledTimeoutFunctions.delete(timerId);
  2492. }
  2493. else {
  2494. throw new Error("The timer is in an undefined state.");
  2495. }
  2496. }
  2497. else if (Timeout.isClearResponse(data)) {
  2498. const { id } = data;
  2499. const unhandledTimerId = unhandledRequests.get(id);
  2500. if (unhandledTimerId === undefined) {
  2501. throw new Error("The timer is in an undefined state.");
  2502. }
  2503. unhandledRequests.delete(id);
  2504. scheduledTimeoutFunctions.delete(unhandledTimerId);
  2505. }
  2506. else {
  2507. const { error: { message } } = data;
  2508. throw new Error(message);
  2509. }
  2510. });
  2511. const clearTimeout = (timerId) => {
  2512. const id = Math.random();
  2513. unhandledRequests.set(id, timerId);
  2514. scheduledTimeoutFunctions.set(timerId, id);
  2515. worker.postMessage({
  2516. id,
  2517. method: "clear",
  2518. params: { timerId }
  2519. });
  2520. };
  2521. const setTimeout = (func, delay) => {
  2522. const timerId = Math.random();
  2523. scheduledTimeoutFunctions.set(timerId, func);
  2524. worker.postMessage({
  2525. id: null,
  2526. method: "set",
  2527. params: {
  2528. delay,
  2529. now: performance.now(),
  2530. timerId
  2531. }
  2532. });
  2533. return timerId;
  2534. };
  2535. return {
  2536. clearTimeout,
  2537. setTimeout
  2538. };
  2539. }
  2540. static loadWorkerTimers() {
  2541. return () => {
  2542. if (Timeout.workerTimers !== null) {
  2543. return Timeout.workerTimers;
  2544. }
  2545. Timeout.workerTimers = Timeout.load();
  2546. return Timeout.workerTimers;
  2547. };
  2548. }
  2549. static isCallNotification(message) {
  2550. return message.method !== undefined && message.method === "call";
  2551. }
  2552. static isClearResponse(message) {
  2553. return message.error === null && typeof message.id === "number";
  2554. }
  2555. }
  2556. exports.Timeout = Timeout;
  2557. Timeout.workerTimers = null;
  2558. Timeout.clearTimeout = (timerId) => Timeout.timers().clearTimeout(timerId);
  2559. Timeout.setTimeout = (func, delay) => Timeout.timers().setTimeout(func, delay);
  2560. Timeout.timers = Timeout.loadWorkerTimers();
  2561. /***/ }),
  2562. /* 52 */
  2563. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2564. "use strict";
  2565. // Copyright (c) Microsoft Corporation. All rights reserved.
  2566. // Licensed under the MIT license.
  2567. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2568. exports.OCSPCacheUpdateErrorEvent = exports.OCSPResponseRetrievedEvent = exports.OCSPCacheFetchErrorEvent = exports.OCSPVerificationFailedEvent = exports.OCSPCacheHitEvent = exports.OCSPCacheEntryNeedsRefreshEvent = exports.OCSPCacheEntryExpiredEvent = exports.OCSPWSUpgradeStartedEvent = exports.OCSPStapleReceivedEvent = exports.OCSPCacheUpdateCompleteEvent = exports.OCSPDiskCacheStoreEvent = exports.OCSPMemoryCacheStoreEvent = exports.OCSPCacheUpdateNeededEvent = exports.OCSPDiskCacheHitEvent = exports.OCSPCacheMissEvent = exports.OCSPMemoryCacheHitEvent = exports.OCSPEvent = void 0;
  2569. /* eslint-disable max-classes-per-file */
  2570. const PlatformEvent_js_1 = __webpack_require__(6);
  2571. class OCSPEvent extends PlatformEvent_js_1.PlatformEvent {
  2572. constructor(eventName, eventType, signature) {
  2573. super(eventName, eventType);
  2574. this.privSignature = signature;
  2575. }
  2576. }
  2577. exports.OCSPEvent = OCSPEvent;
  2578. class OCSPMemoryCacheHitEvent extends OCSPEvent {
  2579. constructor(signature) {
  2580. super("OCSPMemoryCacheHitEvent", PlatformEvent_js_1.EventType.Debug, signature);
  2581. }
  2582. }
  2583. exports.OCSPMemoryCacheHitEvent = OCSPMemoryCacheHitEvent;
  2584. class OCSPCacheMissEvent extends OCSPEvent {
  2585. constructor(signature) {
  2586. super("OCSPCacheMissEvent", PlatformEvent_js_1.EventType.Debug, signature);
  2587. }
  2588. }
  2589. exports.OCSPCacheMissEvent = OCSPCacheMissEvent;
  2590. class OCSPDiskCacheHitEvent extends OCSPEvent {
  2591. constructor(signature) {
  2592. super("OCSPDiskCacheHitEvent", PlatformEvent_js_1.EventType.Debug, signature);
  2593. }
  2594. }
  2595. exports.OCSPDiskCacheHitEvent = OCSPDiskCacheHitEvent;
  2596. class OCSPCacheUpdateNeededEvent extends OCSPEvent {
  2597. constructor(signature) {
  2598. super("OCSPCacheUpdateNeededEvent", PlatformEvent_js_1.EventType.Debug, signature);
  2599. }
  2600. }
  2601. exports.OCSPCacheUpdateNeededEvent = OCSPCacheUpdateNeededEvent;
  2602. class OCSPMemoryCacheStoreEvent extends OCSPEvent {
  2603. constructor(signature) {
  2604. super("OCSPMemoryCacheStoreEvent", PlatformEvent_js_1.EventType.Debug, signature);
  2605. }
  2606. }
  2607. exports.OCSPMemoryCacheStoreEvent = OCSPMemoryCacheStoreEvent;
  2608. class OCSPDiskCacheStoreEvent extends OCSPEvent {
  2609. constructor(signature) {
  2610. super("OCSPDiskCacheStoreEvent", PlatformEvent_js_1.EventType.Debug, signature);
  2611. }
  2612. }
  2613. exports.OCSPDiskCacheStoreEvent = OCSPDiskCacheStoreEvent;
  2614. class OCSPCacheUpdateCompleteEvent extends OCSPEvent {
  2615. constructor(signature) {
  2616. super("OCSPCacheUpdateCompleteEvent", PlatformEvent_js_1.EventType.Debug, signature);
  2617. }
  2618. }
  2619. exports.OCSPCacheUpdateCompleteEvent = OCSPCacheUpdateCompleteEvent;
  2620. class OCSPStapleReceivedEvent extends OCSPEvent {
  2621. constructor() {
  2622. super("OCSPStapleReceivedEvent", PlatformEvent_js_1.EventType.Debug, "");
  2623. }
  2624. }
  2625. exports.OCSPStapleReceivedEvent = OCSPStapleReceivedEvent;
  2626. class OCSPWSUpgradeStartedEvent extends OCSPEvent {
  2627. constructor(serialNumber) {
  2628. super("OCSPWSUpgradeStartedEvent", PlatformEvent_js_1.EventType.Debug, serialNumber);
  2629. }
  2630. }
  2631. exports.OCSPWSUpgradeStartedEvent = OCSPWSUpgradeStartedEvent;
  2632. class OCSPCacheEntryExpiredEvent extends OCSPEvent {
  2633. constructor(serialNumber, expireTime) {
  2634. super("OCSPCacheEntryExpiredEvent", PlatformEvent_js_1.EventType.Debug, serialNumber);
  2635. this.privExpireTime = expireTime;
  2636. }
  2637. }
  2638. exports.OCSPCacheEntryExpiredEvent = OCSPCacheEntryExpiredEvent;
  2639. class OCSPCacheEntryNeedsRefreshEvent extends OCSPEvent {
  2640. constructor(serialNumber, startTime, expireTime) {
  2641. super("OCSPCacheEntryNeedsRefreshEvent", PlatformEvent_js_1.EventType.Debug, serialNumber);
  2642. this.privExpireTime = expireTime;
  2643. this.privStartTime = startTime;
  2644. }
  2645. }
  2646. exports.OCSPCacheEntryNeedsRefreshEvent = OCSPCacheEntryNeedsRefreshEvent;
  2647. class OCSPCacheHitEvent extends OCSPEvent {
  2648. constructor(serialNumber, startTime, expireTime) {
  2649. super("OCSPCacheHitEvent", PlatformEvent_js_1.EventType.Debug, serialNumber);
  2650. this.privExpireTime = expireTime;
  2651. this.privExpireTimeString = new Date(expireTime).toLocaleDateString();
  2652. this.privStartTime = startTime;
  2653. this.privStartTimeString = new Date(startTime).toLocaleTimeString();
  2654. }
  2655. }
  2656. exports.OCSPCacheHitEvent = OCSPCacheHitEvent;
  2657. class OCSPVerificationFailedEvent extends OCSPEvent {
  2658. constructor(serialNumber, error) {
  2659. super("OCSPVerificationFailedEvent", PlatformEvent_js_1.EventType.Debug, serialNumber);
  2660. this.privError = error;
  2661. }
  2662. }
  2663. exports.OCSPVerificationFailedEvent = OCSPVerificationFailedEvent;
  2664. class OCSPCacheFetchErrorEvent extends OCSPEvent {
  2665. constructor(serialNumber, error) {
  2666. super("OCSPCacheFetchErrorEvent", PlatformEvent_js_1.EventType.Debug, serialNumber);
  2667. this.privError = error;
  2668. }
  2669. }
  2670. exports.OCSPCacheFetchErrorEvent = OCSPCacheFetchErrorEvent;
  2671. class OCSPResponseRetrievedEvent extends OCSPEvent {
  2672. constructor(serialNumber) {
  2673. super("OCSPResponseRetrievedEvent", PlatformEvent_js_1.EventType.Debug, serialNumber);
  2674. }
  2675. }
  2676. exports.OCSPResponseRetrievedEvent = OCSPResponseRetrievedEvent;
  2677. class OCSPCacheUpdateErrorEvent extends OCSPEvent {
  2678. constructor(serialNumber, error) {
  2679. super("OCSPCacheUpdateErrorEvent", PlatformEvent_js_1.EventType.Debug, serialNumber);
  2680. this.privError = error;
  2681. }
  2682. }
  2683. exports.OCSPCacheUpdateErrorEvent = OCSPCacheUpdateErrorEvent;
  2684. /***/ }),
  2685. /* 53 */
  2686. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2687. "use strict";
  2688. // Copyright (c) Microsoft Corporation. All rights reserved.
  2689. // Licensed under the MIT license.
  2690. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2691. exports.BackgroundEvent = void 0;
  2692. const Exports_js_1 = __webpack_require__(4);
  2693. class BackgroundEvent extends Exports_js_1.PlatformEvent {
  2694. constructor(error) {
  2695. super("BackgroundEvent", Exports_js_1.EventType.Error);
  2696. this.privError = error;
  2697. }
  2698. get error() {
  2699. return this.privError;
  2700. }
  2701. }
  2702. exports.BackgroundEvent = BackgroundEvent;
  2703. /***/ }),
  2704. /* 54 */
  2705. /***/ ((__unused_webpack_module, exports) => {
  2706. "use strict";
  2707. // Copyright (c) Microsoft Corporation. All rights reserved.
  2708. // Licensed under the MIT license.
  2709. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2710. exports.HeaderNames = void 0;
  2711. class HeaderNames {
  2712. }
  2713. exports.HeaderNames = HeaderNames;
  2714. HeaderNames.AuthKey = "Ocp-Apim-Subscription-Key";
  2715. HeaderNames.Authorization = "Authorization";
  2716. HeaderNames.SpIDAuthKey = "Apim-Subscription-Id";
  2717. HeaderNames.ConnectionId = "X-ConnectionId";
  2718. HeaderNames.ContentType = "Content-Type";
  2719. HeaderNames.CustomCommandsAppId = "X-CommandsAppId";
  2720. HeaderNames.Path = "Path";
  2721. HeaderNames.RequestId = "X-RequestId";
  2722. HeaderNames.RequestStreamId = "X-StreamId";
  2723. HeaderNames.RequestTimestamp = "X-Timestamp";
  2724. /***/ }),
  2725. /* 55 */
  2726. /***/ ((__unused_webpack_module, exports) => {
  2727. "use strict";
  2728. // Copyright (c) Microsoft Corporation. All rights reserved.
  2729. // Licensed under the MIT license.
  2730. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2731. exports.AuthInfo = void 0;
  2732. class AuthInfo {
  2733. constructor(headerName, token) {
  2734. this.privHeaderName = headerName;
  2735. this.privToken = token;
  2736. }
  2737. get headerName() {
  2738. return this.privHeaderName;
  2739. }
  2740. get token() {
  2741. return this.privToken;
  2742. }
  2743. }
  2744. exports.AuthInfo = AuthInfo;
  2745. /***/ }),
  2746. /* 56 */
  2747. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2748. "use strict";
  2749. // Copyright (c) Microsoft Corporation. All rights reserved.
  2750. // Licensed under the MIT license.
  2751. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2752. exports.CognitiveTokenAuthentication = void 0;
  2753. const Exports_js_1 = __webpack_require__(4);
  2754. const IAuthentication_js_1 = __webpack_require__(55);
  2755. const HeaderNames_js_1 = __webpack_require__(54);
  2756. class CognitiveTokenAuthentication {
  2757. constructor(fetchCallback, fetchOnExpiryCallback) {
  2758. if (!fetchCallback) {
  2759. throw new Exports_js_1.ArgumentNullError("fetchCallback");
  2760. }
  2761. if (!fetchOnExpiryCallback) {
  2762. throw new Exports_js_1.ArgumentNullError("fetchOnExpiryCallback");
  2763. }
  2764. this.privFetchCallback = fetchCallback;
  2765. this.privFetchOnExpiryCallback = fetchOnExpiryCallback;
  2766. }
  2767. fetch(authFetchEventId) {
  2768. return this.privFetchCallback(authFetchEventId).then((token) => new IAuthentication_js_1.AuthInfo(HeaderNames_js_1.HeaderNames.Authorization, token === undefined ? undefined : CognitiveTokenAuthentication.privTokenPrefix + token));
  2769. }
  2770. fetchOnExpiry(authFetchEventId) {
  2771. return this.privFetchOnExpiryCallback(authFetchEventId).then((token) => new IAuthentication_js_1.AuthInfo(HeaderNames_js_1.HeaderNames.Authorization, token === undefined ? undefined : CognitiveTokenAuthentication.privTokenPrefix + token));
  2772. }
  2773. }
  2774. exports.CognitiveTokenAuthentication = CognitiveTokenAuthentication;
  2775. CognitiveTokenAuthentication.privTokenPrefix = "Bearer ";
  2776. /***/ }),
  2777. /* 57 */
  2778. /***/ ((__unused_webpack_module, exports) => {
  2779. "use strict";
  2780. // Copyright (c) Microsoft Corporation. All rights reserved.
  2781. // Licensed under the MIT license.
  2782. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2783. /***/ }),
  2784. /* 58 */
  2785. /***/ ((__unused_webpack_module, exports) => {
  2786. "use strict";
  2787. // Copyright (c) Microsoft Corporation. All rights reserved.
  2788. // Licensed under the MIT license.
  2789. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2790. /***/ }),
  2791. /* 59 */
  2792. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2793. "use strict";
  2794. // Copyright (c) Microsoft Corporation. All rights reserved.
  2795. // Licensed under the MIT license.
  2796. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2797. exports.IntentConnectionFactory = void 0;
  2798. const Exports_js_1 = __webpack_require__(60);
  2799. const Exports_js_2 = __webpack_require__(79);
  2800. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  2801. const Exports_js_3 = __webpack_require__(2);
  2802. const HeaderNames_js_1 = __webpack_require__(54);
  2803. class IntentConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {
  2804. create(config, authInfo, connectionId) {
  2805. let endpoint = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint);
  2806. if (!endpoint) {
  2807. const region = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_IntentRegion);
  2808. const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);
  2809. const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, "wss://" + region + ".sr.speech" + hostSuffix);
  2810. endpoint = host + "/speech/recognition/interactive/cognitiveservices/v1";
  2811. }
  2812. const queryParams = {
  2813. format: "simple",
  2814. language: config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage),
  2815. };
  2816. this.setCommonUrlParams(config, queryParams, endpoint);
  2817. const headers = {};
  2818. if (authInfo.token !== undefined && authInfo.token !== "") {
  2819. headers[authInfo.headerName] = authInfo.token;
  2820. }
  2821. headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;
  2822. config.parameters.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Url, endpoint);
  2823. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "false") === "true";
  2824. return Promise.resolve(new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_3.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId));
  2825. }
  2826. getSpeechRegionFromIntentRegion(intentRegion) {
  2827. switch (intentRegion) {
  2828. case "West US":
  2829. case "US West":
  2830. case "westus":
  2831. return "uswest";
  2832. case "West US 2":
  2833. case "US West 2":
  2834. case "westus2":
  2835. return "uswest2";
  2836. case "South Central US":
  2837. case "US South Central":
  2838. case "southcentralus":
  2839. return "ussouthcentral";
  2840. case "West Central US":
  2841. case "US West Central":
  2842. case "westcentralus":
  2843. return "uswestcentral";
  2844. case "East US":
  2845. case "US East":
  2846. case "eastus":
  2847. return "useast";
  2848. case "East US 2":
  2849. case "US East 2":
  2850. case "eastus2":
  2851. return "useast2";
  2852. case "West Europe":
  2853. case "Europe West":
  2854. case "westeurope":
  2855. return "europewest";
  2856. case "North Europe":
  2857. case "Europe North":
  2858. case "northeurope":
  2859. return "europenorth";
  2860. case "Brazil South":
  2861. case "South Brazil":
  2862. case "southbrazil":
  2863. return "brazilsouth";
  2864. case "Australia East":
  2865. case "East Australia":
  2866. case "eastaustralia":
  2867. return "australiaeast";
  2868. case "Southeast Asia":
  2869. case "Asia Southeast":
  2870. case "southeastasia":
  2871. return "asiasoutheast";
  2872. case "East Asia":
  2873. case "Asia East":
  2874. case "eastasia":
  2875. return "asiaeast";
  2876. default:
  2877. return intentRegion;
  2878. }
  2879. }
  2880. }
  2881. exports.IntentConnectionFactory = IntentConnectionFactory;
  2882. /***/ }),
  2883. /* 60 */
  2884. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  2885. "use strict";
  2886. // Copyright (c) Microsoft Corporation. All rights reserved.
  2887. // Licensed under the MIT license.
  2888. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  2889. if (k2 === undefined) k2 = k;
  2890. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  2891. }) : (function(o, m, k, k2) {
  2892. if (k2 === undefined) k2 = k;
  2893. o[k2] = m[k];
  2894. }));
  2895. var __exportStar = (this && this.__exportStar) || function(m, exports) {
  2896. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  2897. };
  2898. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2899. __exportStar(__webpack_require__(61), exports);
  2900. __exportStar(__webpack_require__(65), exports);
  2901. __exportStar(__webpack_require__(66), exports);
  2902. __exportStar(__webpack_require__(68), exports);
  2903. __exportStar(__webpack_require__(69), exports);
  2904. __exportStar(__webpack_require__(70), exports);
  2905. __exportStar(__webpack_require__(71), exports);
  2906. __exportStar(__webpack_require__(77), exports);
  2907. __exportStar(__webpack_require__(78), exports);
  2908. __exportStar(__webpack_require__(200), exports);
  2909. __exportStar(__webpack_require__(203), exports);
  2910. /***/ }),
  2911. /* 61 */
  2912. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  2913. "use strict";
  2914. /* eslint-disable @typescript-eslint/no-unsafe-assignment */
  2915. // Copyright (c) Microsoft Corporation. All rights reserved.
  2916. // Licensed under the MIT license.
  2917. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  2918. if (k2 === undefined) k2 = k;
  2919. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  2920. }) : (function(o, m, k, k2) {
  2921. if (k2 === undefined) k2 = k;
  2922. o[k2] = m[k];
  2923. }));
  2924. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  2925. Object.defineProperty(o, "default", { enumerable: true, value: v });
  2926. }) : function(o, v) {
  2927. o["default"] = v;
  2928. });
  2929. var __importStar = (this && this.__importStar) || function (mod) {
  2930. if (mod && mod.__esModule) return mod;
  2931. var result = {};
  2932. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  2933. __setModuleDefault(result, mod);
  2934. return result;
  2935. };
  2936. Object.defineProperty(exports, "__esModule", ({ value: true }));
  2937. exports.ConsoleLoggingListener = void 0;
  2938. const fs = __importStar(__webpack_require__(62));
  2939. const LogLevel_js_1 = __webpack_require__(63);
  2940. const Contracts_js_1 = __webpack_require__(64);
  2941. class ConsoleLoggingListener {
  2942. constructor(logLevelFilter = LogLevel_js_1.LogLevel.None) {
  2943. this.privLogPath = undefined;
  2944. this.privEnableConsoleOutput = true;
  2945. this.privLogLevelFilter = logLevelFilter;
  2946. }
  2947. set logPath(path) {
  2948. Contracts_js_1.Contracts.throwIfNullOrUndefined(fs.openSync, "\nFile System access not available");
  2949. this.privLogPath = path;
  2950. }
  2951. set enableConsoleOutput(enableOutput) {
  2952. this.privEnableConsoleOutput = enableOutput;
  2953. }
  2954. onEvent(event) {
  2955. if (event.eventType >= this.privLogLevelFilter) {
  2956. const log = this.toString(event);
  2957. if (!!this.logCallback) {
  2958. this.logCallback(log);
  2959. }
  2960. if (!!this.privLogPath) {
  2961. fs.writeFileSync(this.privLogPath, log + "\n", { flag: "a+" });
  2962. }
  2963. if (this.privEnableConsoleOutput) {
  2964. switch (event.eventType) {
  2965. case LogLevel_js_1.LogLevel.Debug:
  2966. // eslint-disable-next-line no-console
  2967. console.debug(log);
  2968. break;
  2969. case LogLevel_js_1.LogLevel.Info:
  2970. // eslint-disable-next-line no-console
  2971. console.info(log);
  2972. break;
  2973. case LogLevel_js_1.LogLevel.Warning:
  2974. // eslint-disable-next-line no-console
  2975. console.warn(log);
  2976. break;
  2977. case LogLevel_js_1.LogLevel.Error:
  2978. // eslint-disable-next-line no-console
  2979. console.error(log);
  2980. break;
  2981. default:
  2982. // eslint-disable-next-line no-console
  2983. console.log(log);
  2984. break;
  2985. }
  2986. }
  2987. }
  2988. }
  2989. toString(event) {
  2990. const logFragments = [
  2991. `${event.eventTime}`,
  2992. `${event.name}`,
  2993. ];
  2994. const e = event;
  2995. for (const prop in e) {
  2996. if (prop && event.hasOwnProperty(prop) &&
  2997. prop !== "eventTime" && prop !== "eventType" &&
  2998. prop !== "eventId" && prop !== "name" &&
  2999. prop !== "constructor") {
  3000. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
  3001. const value = e[prop];
  3002. let valueToLog = "<NULL>";
  3003. if (value !== undefined && value !== null) {
  3004. if (typeof (value) === "number" || typeof (value) === "string") {
  3005. valueToLog = value.toString();
  3006. }
  3007. else {
  3008. valueToLog = JSON.stringify(value);
  3009. }
  3010. }
  3011. logFragments.push(`${prop}: ${valueToLog}`);
  3012. }
  3013. }
  3014. return logFragments.join(" | ");
  3015. }
  3016. }
  3017. exports.ConsoleLoggingListener = ConsoleLoggingListener;
  3018. /***/ }),
  3019. /* 62 */
  3020. /***/ (() => {
  3021. /* (ignored) */
  3022. /***/ }),
  3023. /* 63 */
  3024. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3025. "use strict";
  3026. // Copyright (c) Microsoft Corporation. All rights reserved.
  3027. // Licensed under the MIT license.
  3028. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3029. exports.LogLevel = void 0;
  3030. const Exports_js_1 = __webpack_require__(4);
  3031. Object.defineProperty(exports, "LogLevel", ({ enumerable: true, get: function () { return Exports_js_1.EventType; } }));
  3032. /***/ }),
  3033. /* 64 */
  3034. /***/ ((__unused_webpack_module, exports) => {
  3035. "use strict";
  3036. // Copyright (c) Microsoft Corporation. All rights reserved.
  3037. // Licensed under the MIT license.
  3038. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3039. exports.Contracts = void 0;
  3040. /**
  3041. * @class Contracts
  3042. * @private
  3043. */
  3044. class Contracts {
  3045. static throwIfNullOrUndefined(param, name) {
  3046. if (param === undefined || param === null) {
  3047. throw new Error("throwIfNullOrUndefined:" + name);
  3048. }
  3049. }
  3050. static throwIfNull(param, name) {
  3051. if (param === null) {
  3052. throw new Error("throwIfNull:" + name);
  3053. }
  3054. }
  3055. static throwIfNullOrWhitespace(param, name) {
  3056. Contracts.throwIfNullOrUndefined(param, name);
  3057. if (("" + param).trim().length < 1) {
  3058. throw new Error("throwIfNullOrWhitespace:" + name);
  3059. }
  3060. }
  3061. static throwIfNullOrTooLong(param, name, maxLength) {
  3062. Contracts.throwIfNullOrUndefined(param, name);
  3063. if (("" + param).length > maxLength) {
  3064. throw new Error("throwIfNullOrTooLong:" + name + " (more than " + maxLength.toString() + " characters)");
  3065. }
  3066. }
  3067. static throwIfNullOrTooShort(param, name, minLength) {
  3068. Contracts.throwIfNullOrUndefined(param, name);
  3069. if (("" + param).length < minLength) {
  3070. throw new Error("throwIfNullOrTooShort:" + name + " (less than " + minLength.toString() + " characters)");
  3071. }
  3072. }
  3073. static throwIfDisposed(isDisposed) {
  3074. if (isDisposed) {
  3075. throw new Error("the object is already disposed");
  3076. }
  3077. }
  3078. static throwIfArrayEmptyOrWhitespace(array, name) {
  3079. Contracts.throwIfNullOrUndefined(array, name);
  3080. if (array.length === 0) {
  3081. throw new Error("throwIfArrayEmptyOrWhitespace:" + name);
  3082. }
  3083. for (const item of array) {
  3084. Contracts.throwIfNullOrWhitespace(item, name);
  3085. }
  3086. }
  3087. static throwIfFileDoesNotExist(param, name) {
  3088. Contracts.throwIfNullOrWhitespace(param, name);
  3089. // TODO check for file existence.
  3090. }
  3091. static throwIfNotUndefined(param, name) {
  3092. if (param !== undefined) {
  3093. throw new Error("throwIfNotUndefined:" + name);
  3094. }
  3095. }
  3096. }
  3097. exports.Contracts = Contracts;
  3098. /***/ }),
  3099. /* 65 */
  3100. /***/ ((__unused_webpack_module, exports) => {
  3101. "use strict";
  3102. // Copyright (c) Microsoft Corporation. All rights reserved.
  3103. // Licensed under the MIT license.
  3104. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3105. /***/ }),
  3106. /* 66 */
  3107. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3108. "use strict";
  3109. // Copyright (c) Microsoft Corporation. All rights reserved.
  3110. // Licensed under the MIT license.
  3111. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3112. exports.MicAudioSource = exports.AudioWorkletSourceURLPropertyName = void 0;
  3113. const Exports_js_1 = __webpack_require__(2);
  3114. const Exports_js_2 = __webpack_require__(4);
  3115. const AudioStreamFormat_js_1 = __webpack_require__(67);
  3116. exports.AudioWorkletSourceURLPropertyName = "MICROPHONE-WorkletSourceUrl";
  3117. class MicAudioSource {
  3118. constructor(privRecorder, deviceId, audioSourceId, mediaStream) {
  3119. this.privRecorder = privRecorder;
  3120. this.deviceId = deviceId;
  3121. this.privStreams = {};
  3122. this.privOutputChunkSize = MicAudioSource.AUDIOFORMAT.avgBytesPerSec / 10;
  3123. this.privId = audioSourceId ? audioSourceId : (0, Exports_js_2.createNoDashGuid)();
  3124. this.privEvents = new Exports_js_2.EventSource();
  3125. this.privMediaStream = mediaStream || null;
  3126. this.privIsClosing = false;
  3127. }
  3128. get format() {
  3129. return Promise.resolve(MicAudioSource.AUDIOFORMAT);
  3130. }
  3131. turnOn() {
  3132. if (this.privInitializeDeferral) {
  3133. return this.privInitializeDeferral.promise;
  3134. }
  3135. this.privInitializeDeferral = new Exports_js_2.Deferred();
  3136. try {
  3137. this.createAudioContext();
  3138. }
  3139. catch (error) {
  3140. if (error instanceof Error) {
  3141. const typedError = error;
  3142. this.privInitializeDeferral.reject(typedError.name + ": " + typedError.message);
  3143. }
  3144. else {
  3145. this.privInitializeDeferral.reject(error);
  3146. }
  3147. return this.privInitializeDeferral.promise;
  3148. }
  3149. const nav = window.navigator;
  3150. let getUserMedia = (
  3151. // eslint-disable-next-line
  3152. nav.getUserMedia ||
  3153. nav.webkitGetUserMedia ||
  3154. nav.mozGetUserMedia ||
  3155. nav.msGetUserMedia);
  3156. if (!!nav.mediaDevices) {
  3157. getUserMedia = (constraints, successCallback, errorCallback) => {
  3158. nav.mediaDevices
  3159. .getUserMedia(constraints)
  3160. .then(successCallback)
  3161. .catch(errorCallback);
  3162. };
  3163. }
  3164. if (!getUserMedia) {
  3165. const errorMsg = "Browser does not support getUserMedia.";
  3166. this.privInitializeDeferral.reject(errorMsg);
  3167. this.onEvent(new Exports_js_2.AudioSourceErrorEvent(errorMsg, "")); // mic initialized error - no streamid at this point
  3168. }
  3169. else {
  3170. const next = () => {
  3171. this.onEvent(new Exports_js_2.AudioSourceInitializingEvent(this.privId)); // no stream id
  3172. if (this.privMediaStream && this.privMediaStream.active) {
  3173. this.onEvent(new Exports_js_2.AudioSourceReadyEvent(this.privId));
  3174. this.privInitializeDeferral.resolve();
  3175. }
  3176. else {
  3177. getUserMedia({ audio: this.deviceId ? { deviceId: this.deviceId } : true, video: false }, (mediaStream) => {
  3178. this.privMediaStream = mediaStream;
  3179. this.onEvent(new Exports_js_2.AudioSourceReadyEvent(this.privId));
  3180. this.privInitializeDeferral.resolve();
  3181. }, (error) => {
  3182. const errorMsg = `Error occurred during microphone initialization: ${error}`;
  3183. this.privInitializeDeferral.reject(errorMsg);
  3184. this.onEvent(new Exports_js_2.AudioSourceErrorEvent(this.privId, errorMsg));
  3185. });
  3186. }
  3187. };
  3188. if (this.privContext.state === "suspended") {
  3189. // NOTE: On iOS, the Web Audio API requires sounds to be triggered from an explicit user action.
  3190. // https://github.com/WebAudio/web-audio-api/issues/790
  3191. this.privContext.resume()
  3192. .then(next)
  3193. .catch((reason) => {
  3194. this.privInitializeDeferral.reject(`Failed to initialize audio context: ${reason}`);
  3195. });
  3196. }
  3197. else {
  3198. next();
  3199. }
  3200. }
  3201. return this.privInitializeDeferral.promise;
  3202. }
  3203. id() {
  3204. return this.privId;
  3205. }
  3206. attach(audioNodeId) {
  3207. this.onEvent(new Exports_js_2.AudioStreamNodeAttachingEvent(this.privId, audioNodeId));
  3208. return this.listen(audioNodeId).then((stream) => {
  3209. this.onEvent(new Exports_js_2.AudioStreamNodeAttachedEvent(this.privId, audioNodeId));
  3210. return {
  3211. detach: async () => {
  3212. stream.readEnded();
  3213. delete this.privStreams[audioNodeId];
  3214. this.onEvent(new Exports_js_2.AudioStreamNodeDetachedEvent(this.privId, audioNodeId));
  3215. return this.turnOff();
  3216. },
  3217. id: () => audioNodeId,
  3218. read: () => stream.read(),
  3219. };
  3220. });
  3221. }
  3222. detach(audioNodeId) {
  3223. if (audioNodeId && this.privStreams[audioNodeId]) {
  3224. this.privStreams[audioNodeId].close();
  3225. delete this.privStreams[audioNodeId];
  3226. this.onEvent(new Exports_js_2.AudioStreamNodeDetachedEvent(this.privId, audioNodeId));
  3227. }
  3228. }
  3229. async turnOff() {
  3230. for (const streamId in this.privStreams) {
  3231. if (streamId) {
  3232. const stream = this.privStreams[streamId];
  3233. if (stream) {
  3234. stream.close();
  3235. }
  3236. }
  3237. }
  3238. this.onEvent(new Exports_js_2.AudioSourceOffEvent(this.privId)); // no stream now
  3239. if (this.privInitializeDeferral) {
  3240. // Correctly handle when browser forces mic off before turnOn() completes
  3241. // eslint-disable-next-line @typescript-eslint/await-thenable
  3242. await this.privInitializeDeferral;
  3243. this.privInitializeDeferral = null;
  3244. }
  3245. await this.destroyAudioContext();
  3246. return;
  3247. }
  3248. get events() {
  3249. return this.privEvents;
  3250. }
  3251. get deviceInfo() {
  3252. return this.getMicrophoneLabel().then((label) => ({
  3253. bitspersample: MicAudioSource.AUDIOFORMAT.bitsPerSample,
  3254. channelcount: MicAudioSource.AUDIOFORMAT.channels,
  3255. connectivity: Exports_js_1.connectivity.Unknown,
  3256. manufacturer: "Speech SDK",
  3257. model: label,
  3258. samplerate: MicAudioSource.AUDIOFORMAT.samplesPerSec,
  3259. type: Exports_js_1.type.Microphones,
  3260. }));
  3261. }
  3262. setProperty(name, value) {
  3263. if (name === exports.AudioWorkletSourceURLPropertyName) {
  3264. this.privRecorder.setWorkletUrl(value);
  3265. }
  3266. else {
  3267. throw new Error("Property '" + name + "' is not supported on Microphone.");
  3268. }
  3269. }
  3270. getMicrophoneLabel() {
  3271. const defaultMicrophoneName = "microphone";
  3272. // If we did this already, return the value.
  3273. if (this.privMicrophoneLabel !== undefined) {
  3274. return Promise.resolve(this.privMicrophoneLabel);
  3275. }
  3276. // If the stream isn't currently running, we can't query devices because security.
  3277. if (this.privMediaStream === undefined || !this.privMediaStream.active) {
  3278. return Promise.resolve(defaultMicrophoneName);
  3279. }
  3280. // Setup a default
  3281. this.privMicrophoneLabel = defaultMicrophoneName;
  3282. // Get the id of the device running the audio track.
  3283. const microphoneDeviceId = this.privMediaStream.getTracks()[0].getSettings().deviceId;
  3284. // If the browser doesn't support getting the device ID, set a default and return.
  3285. if (undefined === microphoneDeviceId) {
  3286. return Promise.resolve(this.privMicrophoneLabel);
  3287. }
  3288. const deferred = new Exports_js_2.Deferred();
  3289. // Enumerate the media devices.
  3290. navigator.mediaDevices.enumerateDevices().then((devices) => {
  3291. for (const device of devices) {
  3292. if (device.deviceId === microphoneDeviceId) {
  3293. // Found the device
  3294. this.privMicrophoneLabel = device.label;
  3295. break;
  3296. }
  3297. }
  3298. deferred.resolve(this.privMicrophoneLabel);
  3299. }, () => deferred.resolve(this.privMicrophoneLabel));
  3300. return deferred.promise;
  3301. }
  3302. async listen(audioNodeId) {
  3303. await this.turnOn();
  3304. const stream = new Exports_js_2.ChunkedArrayBufferStream(this.privOutputChunkSize, audioNodeId);
  3305. this.privStreams[audioNodeId] = stream;
  3306. try {
  3307. this.privRecorder.record(this.privContext, this.privMediaStream, stream);
  3308. }
  3309. catch (error) {
  3310. this.onEvent(new Exports_js_2.AudioStreamNodeErrorEvent(this.privId, audioNodeId, error));
  3311. throw error;
  3312. }
  3313. const result = stream;
  3314. return result;
  3315. }
  3316. onEvent(event) {
  3317. this.privEvents.onEvent(event);
  3318. Exports_js_2.Events.instance.onEvent(event);
  3319. }
  3320. createAudioContext() {
  3321. if (!!this.privContext) {
  3322. return;
  3323. }
  3324. this.privContext = AudioStreamFormat_js_1.AudioStreamFormatImpl.getAudioContext(MicAudioSource.AUDIOFORMAT.samplesPerSec);
  3325. }
  3326. async destroyAudioContext() {
  3327. if (!this.privContext) {
  3328. return;
  3329. }
  3330. this.privRecorder.releaseMediaResources(this.privContext);
  3331. // This pattern brought to you by a bug in the TypeScript compiler where it
  3332. // confuses the ("close" in this.privContext) with this.privContext always being null as the alternate.
  3333. // https://github.com/Microsoft/TypeScript/issues/11498
  3334. let hasClose = false;
  3335. if ("close" in this.privContext) {
  3336. hasClose = true;
  3337. }
  3338. if (hasClose) {
  3339. if (!this.privIsClosing) {
  3340. // The audio context close may take enough time that the close is called twice
  3341. this.privIsClosing = true;
  3342. await this.privContext.close();
  3343. this.privContext = null;
  3344. this.privIsClosing = false;
  3345. }
  3346. }
  3347. else if (null !== this.privContext && this.privContext.state === "running") {
  3348. // Suspend actually takes a callback, but analogous to the
  3349. // resume method, it'll be only fired if suspend is called
  3350. // in a direct response to a user action. The later is not always
  3351. // the case, as TurnOff is also called, when we receive an
  3352. // end-of-speech message from the service. So, doing a best effort
  3353. // fire-and-forget here.
  3354. await this.privContext.suspend();
  3355. }
  3356. }
  3357. }
  3358. exports.MicAudioSource = MicAudioSource;
  3359. MicAudioSource.AUDIOFORMAT = AudioStreamFormat_js_1.AudioStreamFormat.getDefaultInputFormat();
  3360. /***/ }),
  3361. /* 67 */
  3362. /***/ ((__unused_webpack_module, exports) => {
  3363. "use strict";
  3364. // Copyright (c) Microsoft Corporation. All rights reserved.
  3365. // Licensed under the MIT license.
  3366. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3367. exports.AudioStreamFormatImpl = exports.AudioStreamFormat = exports.AudioFormatTag = void 0;
  3368. // eslint-disable-next-line max-classes-per-file
  3369. var AudioFormatTag;
  3370. (function (AudioFormatTag) {
  3371. AudioFormatTag[AudioFormatTag["PCM"] = 1] = "PCM";
  3372. AudioFormatTag[AudioFormatTag["MuLaw"] = 2] = "MuLaw";
  3373. AudioFormatTag[AudioFormatTag["Siren"] = 3] = "Siren";
  3374. AudioFormatTag[AudioFormatTag["MP3"] = 4] = "MP3";
  3375. AudioFormatTag[AudioFormatTag["SILKSkype"] = 5] = "SILKSkype";
  3376. AudioFormatTag[AudioFormatTag["OGG_OPUS"] = 6] = "OGG_OPUS";
  3377. AudioFormatTag[AudioFormatTag["WEBM_OPUS"] = 7] = "WEBM_OPUS";
  3378. AudioFormatTag[AudioFormatTag["ALaw"] = 8] = "ALaw";
  3379. AudioFormatTag[AudioFormatTag["FLAC"] = 9] = "FLAC";
  3380. AudioFormatTag[AudioFormatTag["OPUS"] = 10] = "OPUS";
  3381. AudioFormatTag[AudioFormatTag["AMR_WB"] = 11] = "AMR_WB";
  3382. AudioFormatTag[AudioFormatTag["G722"] = 12] = "G722";
  3383. })(AudioFormatTag = exports.AudioFormatTag || (exports.AudioFormatTag = {}));
  3384. /**
  3385. * Represents audio stream format used for custom audio input configurations.
  3386. * @class AudioStreamFormat
  3387. */
  3388. class AudioStreamFormat {
  3389. /**
  3390. * Creates an audio stream format object representing the default audio stream
  3391. * format (16KHz 16bit mono PCM).
  3392. * @member AudioStreamFormat.getDefaultInputFormat
  3393. * @function
  3394. * @public
  3395. * @returns {AudioStreamFormat} The audio stream format being created.
  3396. */
  3397. static getDefaultInputFormat() {
  3398. return AudioStreamFormatImpl.getDefaultInputFormat();
  3399. }
  3400. /**
  3401. * Creates an audio stream format object with the specified format characteristics.
  3402. * @member AudioStreamFormat.getWaveFormat
  3403. * @function
  3404. * @public
  3405. * @param {number} samplesPerSecond - Sample rate, in samples per second (Hertz).
  3406. * @param {number} bitsPerSample - Bits per sample, typically 16.
  3407. * @param {number} channels - Number of channels in the waveform-audio data. Monaural data
  3408. * uses one channel and stereo data uses two channels.
  3409. * @param {AudioFormatTag} format - Audio format (PCM, alaw or mulaw).
  3410. * @returns {AudioStreamFormat} The audio stream format being created.
  3411. */
  3412. static getWaveFormat(samplesPerSecond, bitsPerSample, channels, format) {
  3413. return new AudioStreamFormatImpl(samplesPerSecond, bitsPerSample, channels, format);
  3414. }
  3415. /**
  3416. * Creates an audio stream format object with the specified pcm waveformat characteristics.
  3417. * @member AudioStreamFormat.getWaveFormatPCM
  3418. * @function
  3419. * @public
  3420. * @param {number} samplesPerSecond - Sample rate, in samples per second (Hertz).
  3421. * @param {number} bitsPerSample - Bits per sample, typically 16.
  3422. * @param {number} channels - Number of channels in the waveform-audio data. Monaural data
  3423. * uses one channel and stereo data uses two channels.
  3424. * @returns {AudioStreamFormat} The audio stream format being created.
  3425. */
  3426. static getWaveFormatPCM(samplesPerSecond, bitsPerSample, channels) {
  3427. return new AudioStreamFormatImpl(samplesPerSecond, bitsPerSample, channels);
  3428. }
  3429. }
  3430. exports.AudioStreamFormat = AudioStreamFormat;
  3431. /**
  3432. * @private
  3433. * @class AudioStreamFormatImpl
  3434. */
  3435. class AudioStreamFormatImpl extends AudioStreamFormat {
  3436. /**
  3437. * Creates an instance with the given values.
  3438. * @constructor
  3439. * @param {number} samplesPerSec - Samples per second.
  3440. * @param {number} bitsPerSample - Bits per sample.
  3441. * @param {number} channels - Number of channels.
  3442. * @param {AudioFormatTag} format - Audio format (PCM, alaw or mulaw).
  3443. */
  3444. constructor(samplesPerSec = 16000, bitsPerSample = 16, channels = 1, format = AudioFormatTag.PCM) {
  3445. super();
  3446. let isWavFormat = true;
  3447. /* 1 for PCM; 6 for alaw; 7 for mulaw */
  3448. switch (format) {
  3449. case AudioFormatTag.PCM:
  3450. this.formatTag = 1;
  3451. break;
  3452. case AudioFormatTag.ALaw:
  3453. this.formatTag = 6;
  3454. break;
  3455. case AudioFormatTag.MuLaw:
  3456. this.formatTag = 7;
  3457. break;
  3458. default:
  3459. isWavFormat = false;
  3460. }
  3461. this.bitsPerSample = bitsPerSample;
  3462. this.samplesPerSec = samplesPerSec;
  3463. this.channels = channels;
  3464. this.avgBytesPerSec = this.samplesPerSec * this.channels * (this.bitsPerSample / 8);
  3465. this.blockAlign = this.channels * Math.max(this.bitsPerSample, 8);
  3466. if (isWavFormat) {
  3467. this.privHeader = new ArrayBuffer(44);
  3468. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
  3469. const view = new DataView(this.privHeader);
  3470. /* RIFF identifier */
  3471. this.setString(view, 0, "RIFF");
  3472. /* file length */
  3473. view.setUint32(4, 0, true);
  3474. /* RIFF type & Format */
  3475. this.setString(view, 8, "WAVEfmt ");
  3476. /* format chunk length */
  3477. view.setUint32(16, 16, true);
  3478. /* audio format */
  3479. view.setUint16(20, this.formatTag, true);
  3480. /* channel count */
  3481. view.setUint16(22, this.channels, true);
  3482. /* sample rate */
  3483. view.setUint32(24, this.samplesPerSec, true);
  3484. /* byte rate (sample rate * block align) */
  3485. view.setUint32(28, this.avgBytesPerSec, true);
  3486. /* block align (channel count * bytes per sample) */
  3487. view.setUint16(32, this.channels * (this.bitsPerSample / 8), true);
  3488. /* bits per sample */
  3489. view.setUint16(34, this.bitsPerSample, true);
  3490. /* data chunk identifier */
  3491. this.setString(view, 36, "data");
  3492. /* data chunk length */
  3493. view.setUint32(40, 0, true);
  3494. }
  3495. }
  3496. /**
  3497. * Retrieves the default input format.
  3498. * @member AudioStreamFormatImpl.getDefaultInputFormat
  3499. * @function
  3500. * @public
  3501. * @returns {AudioStreamFormatImpl} The default input format.
  3502. */
  3503. static getDefaultInputFormat() {
  3504. return new AudioStreamFormatImpl();
  3505. }
  3506. /**
  3507. * Creates an audio context appropriate to current browser
  3508. * @member AudioStreamFormatImpl.getAudioContext
  3509. * @function
  3510. * @public
  3511. * @returns {AudioContext} An audio context instance
  3512. */
  3513. /* eslint-disable */
  3514. static getAudioContext(sampleRate) {
  3515. // Workaround for Speech SDK bug in Safari.
  3516. const AudioContext = window.AudioContext // our preferred impl
  3517. || window.webkitAudioContext // fallback, mostly when on Safari
  3518. || false; // could not find.
  3519. // https://developer.mozilla.org/en-US/docs/Web/API/AudioContext
  3520. if (!!AudioContext) {
  3521. if (sampleRate !== undefined && navigator.mediaDevices.getSupportedConstraints().sampleRate) {
  3522. return new AudioContext({ sampleRate });
  3523. }
  3524. else {
  3525. return new AudioContext();
  3526. }
  3527. }
  3528. else {
  3529. throw new Error("Browser does not support Web Audio API (AudioContext is not available).");
  3530. }
  3531. }
  3532. /* eslint-enable */
  3533. /**
  3534. * Closes the configuration object.
  3535. * @member AudioStreamFormatImpl.prototype.close
  3536. * @function
  3537. * @public
  3538. */
  3539. close() {
  3540. return;
  3541. }
  3542. get header() {
  3543. return this.privHeader;
  3544. }
  3545. setString(view, offset, str) {
  3546. for (let i = 0; i < str.length; i++) {
  3547. view.setUint8(offset + i, str.charCodeAt(i));
  3548. }
  3549. }
  3550. }
  3551. exports.AudioStreamFormatImpl = AudioStreamFormatImpl;
  3552. /***/ }),
  3553. /* 68 */
  3554. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3555. "use strict";
  3556. // Copyright (c) Microsoft Corporation. All rights reserved.
  3557. // Licensed under the MIT license.
  3558. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3559. exports.FileAudioSource = void 0;
  3560. const Exports_js_1 = __webpack_require__(2);
  3561. const Exports_js_2 = __webpack_require__(4);
  3562. const AudioStreamFormat_js_1 = __webpack_require__(67);
  3563. class FileAudioSource {
  3564. constructor(file, filename, audioSourceId) {
  3565. this.privStreams = {};
  3566. this.privHeaderEnd = 44;
  3567. this.privId = audioSourceId ? audioSourceId : (0, Exports_js_2.createNoDashGuid)();
  3568. this.privEvents = new Exports_js_2.EventSource();
  3569. this.privSource = file;
  3570. if (typeof window !== "undefined" && typeof Blob !== "undefined" && this.privSource instanceof Blob) {
  3571. this.privFilename = file.name;
  3572. }
  3573. else {
  3574. this.privFilename = filename || "unknown.wav";
  3575. }
  3576. // Read the header.
  3577. this.privAudioFormatPromise = this.readHeader();
  3578. }
  3579. get format() {
  3580. return this.privAudioFormatPromise;
  3581. }
  3582. turnOn() {
  3583. if (this.privFilename.lastIndexOf(".wav") !== this.privFilename.length - 4) {
  3584. const errorMsg = this.privFilename + " is not supported. Only WAVE files are allowed at the moment.";
  3585. this.onEvent(new Exports_js_2.AudioSourceErrorEvent(errorMsg, ""));
  3586. return Promise.reject(errorMsg);
  3587. }
  3588. this.onEvent(new Exports_js_2.AudioSourceInitializingEvent(this.privId)); // no stream id
  3589. this.onEvent(new Exports_js_2.AudioSourceReadyEvent(this.privId));
  3590. return;
  3591. }
  3592. id() {
  3593. return this.privId;
  3594. }
  3595. async attach(audioNodeId) {
  3596. this.onEvent(new Exports_js_2.AudioStreamNodeAttachingEvent(this.privId, audioNodeId));
  3597. const stream = await this.upload(audioNodeId);
  3598. this.onEvent(new Exports_js_2.AudioStreamNodeAttachedEvent(this.privId, audioNodeId));
  3599. return Promise.resolve({
  3600. detach: async () => {
  3601. stream.readEnded();
  3602. delete this.privStreams[audioNodeId];
  3603. this.onEvent(new Exports_js_2.AudioStreamNodeDetachedEvent(this.privId, audioNodeId));
  3604. await this.turnOff();
  3605. },
  3606. id: () => audioNodeId,
  3607. read: () => stream.read(),
  3608. });
  3609. }
  3610. detach(audioNodeId) {
  3611. if (audioNodeId && this.privStreams[audioNodeId]) {
  3612. this.privStreams[audioNodeId].close();
  3613. delete this.privStreams[audioNodeId];
  3614. this.onEvent(new Exports_js_2.AudioStreamNodeDetachedEvent(this.privId, audioNodeId));
  3615. }
  3616. }
  3617. turnOff() {
  3618. for (const streamId in this.privStreams) {
  3619. if (streamId) {
  3620. const stream = this.privStreams[streamId];
  3621. if (stream && !stream.isClosed) {
  3622. stream.close();
  3623. }
  3624. }
  3625. }
  3626. this.onEvent(new Exports_js_2.AudioSourceOffEvent(this.privId)); // no stream now
  3627. return Promise.resolve();
  3628. }
  3629. get events() {
  3630. return this.privEvents;
  3631. }
  3632. get deviceInfo() {
  3633. return this.privAudioFormatPromise.then((result) => (Promise.resolve({
  3634. bitspersample: result.bitsPerSample,
  3635. channelcount: result.channels,
  3636. connectivity: Exports_js_1.connectivity.Unknown,
  3637. manufacturer: "Speech SDK",
  3638. model: "File",
  3639. samplerate: result.samplesPerSec,
  3640. type: Exports_js_1.type.File,
  3641. })));
  3642. }
  3643. readHeader() {
  3644. // Read the wave header.
  3645. const maxHeaderSize = 4296;
  3646. const header = this.privSource.slice(0, maxHeaderSize);
  3647. const headerResult = new Exports_js_2.Deferred();
  3648. const processHeader = (header) => {
  3649. const view = new DataView(header);
  3650. const getWord = (index) => String.fromCharCode(view.getUint8(index), view.getUint8(index + 1), view.getUint8(index + 2), view.getUint8(index + 3));
  3651. // RIFF 4 bytes.
  3652. if ("RIFF" !== getWord(0)) {
  3653. headerResult.reject("Invalid WAV header in file, RIFF was not found");
  3654. return;
  3655. }
  3656. // length, 4 bytes
  3657. // RIFF Type & fmt 8 bytes
  3658. if ("WAVE" !== getWord(8) || "fmt " !== getWord(12)) {
  3659. headerResult.reject("Invalid WAV header in file, WAVEfmt was not found");
  3660. return;
  3661. }
  3662. const formatSize = view.getInt32(16, true);
  3663. const channelCount = view.getUint16(22, true);
  3664. const sampleRate = view.getUint32(24, true);
  3665. const bitsPerSample = view.getUint16(34, true);
  3666. // Confirm if header is 44 bytes long.
  3667. let pos = 36 + Math.max(formatSize - 16, 0);
  3668. for (; getWord(pos) !== "data"; pos += 2) {
  3669. if (pos > maxHeaderSize - 8) {
  3670. headerResult.reject("Invalid WAV header in file, data block was not found");
  3671. return;
  3672. }
  3673. }
  3674. this.privHeaderEnd = pos + 8;
  3675. headerResult.resolve(AudioStreamFormat_js_1.AudioStreamFormat.getWaveFormatPCM(sampleRate, bitsPerSample, channelCount));
  3676. };
  3677. if (typeof window !== "undefined" && typeof Blob !== "undefined" && header instanceof Blob) {
  3678. const reader = new FileReader();
  3679. reader.onload = (event) => {
  3680. const header = event.target.result;
  3681. processHeader(header);
  3682. };
  3683. reader.readAsArrayBuffer(header);
  3684. }
  3685. else {
  3686. const h = header;
  3687. processHeader(h.buffer.slice(h.byteOffset, h.byteOffset + h.byteLength));
  3688. }
  3689. return headerResult.promise;
  3690. }
  3691. async upload(audioNodeId) {
  3692. const onerror = (error) => {
  3693. const errorMsg = `Error occurred while processing '${this.privFilename}'. ${error}`;
  3694. this.onEvent(new Exports_js_2.AudioStreamNodeErrorEvent(this.privId, audioNodeId, errorMsg));
  3695. throw new Error(errorMsg);
  3696. };
  3697. try {
  3698. await this.turnOn();
  3699. const format = await this.privAudioFormatPromise;
  3700. const stream = new Exports_js_2.ChunkedArrayBufferStream(format.avgBytesPerSec / 10, audioNodeId);
  3701. this.privStreams[audioNodeId] = stream;
  3702. const chunk = this.privSource.slice(this.privHeaderEnd);
  3703. const processFile = (buff) => {
  3704. if (stream.isClosed) {
  3705. return; // output stream was closed (somebody called TurnOff). We're done here.
  3706. }
  3707. stream.writeStreamChunk({
  3708. buffer: buff,
  3709. isEnd: false,
  3710. timeReceived: Date.now(),
  3711. });
  3712. stream.close();
  3713. };
  3714. if (typeof window !== "undefined" && typeof Blob !== "undefined" && chunk instanceof Blob) {
  3715. const reader = new FileReader();
  3716. reader.onerror = (ev) => onerror(ev.toString());
  3717. reader.onload = (event) => {
  3718. const fileBuffer = event.target.result;
  3719. processFile(fileBuffer);
  3720. };
  3721. reader.readAsArrayBuffer(chunk);
  3722. }
  3723. else {
  3724. const c = chunk;
  3725. processFile(c.buffer.slice(c.byteOffset, c.byteOffset + c.byteLength));
  3726. }
  3727. return stream;
  3728. }
  3729. catch (e) {
  3730. onerror(e);
  3731. }
  3732. }
  3733. onEvent(event) {
  3734. this.privEvents.onEvent(event);
  3735. Exports_js_2.Events.instance.onEvent(event);
  3736. }
  3737. }
  3738. exports.FileAudioSource = FileAudioSource;
  3739. /***/ }),
  3740. /* 69 */
  3741. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3742. "use strict";
  3743. // Copyright (c) Microsoft Corporation. All rights reserved.
  3744. // Licensed under the MIT license.
  3745. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3746. exports.PcmRecorder = void 0;
  3747. const Exports_1 = __webpack_require__(4);
  3748. class PcmRecorder {
  3749. constructor(stopInputOnRelease) {
  3750. this.privStopInputOnRelease = stopInputOnRelease;
  3751. }
  3752. record(context, mediaStream, outputStream) {
  3753. const desiredSampleRate = 16000;
  3754. const waveStreamEncoder = new Exports_1.RiffPcmEncoder(context.sampleRate, desiredSampleRate);
  3755. const micInput = context.createMediaStreamSource(mediaStream);
  3756. const attachScriptProcessor = () => {
  3757. // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
  3758. const scriptNode = (() => {
  3759. let bufferSize = 0;
  3760. try {
  3761. return context.createScriptProcessor(bufferSize, 1, 1);
  3762. }
  3763. catch (error) {
  3764. // Webkit (<= version 31) requires a valid bufferSize.
  3765. bufferSize = 2048;
  3766. let audioSampleRate = context.sampleRate;
  3767. while (bufferSize < 16384 && audioSampleRate >= (2 * desiredSampleRate)) {
  3768. bufferSize <<= 1;
  3769. audioSampleRate >>= 1;
  3770. }
  3771. return context.createScriptProcessor(bufferSize, 1, 1);
  3772. }
  3773. })();
  3774. scriptNode.onaudioprocess = (event) => {
  3775. const inputFrame = event.inputBuffer.getChannelData(0);
  3776. if (outputStream && !outputStream.isClosed) {
  3777. const waveFrame = waveStreamEncoder.encode(inputFrame);
  3778. if (!!waveFrame) {
  3779. outputStream.writeStreamChunk({
  3780. buffer: waveFrame,
  3781. isEnd: false,
  3782. timeReceived: Date.now(),
  3783. });
  3784. }
  3785. }
  3786. };
  3787. micInput.connect(scriptNode);
  3788. scriptNode.connect(context.destination);
  3789. this.privMediaResources = {
  3790. scriptProcessorNode: scriptNode,
  3791. source: micInput,
  3792. stream: mediaStream,
  3793. };
  3794. };
  3795. // https://webaudio.github.io/web-audio-api/#audioworklet
  3796. // Using AudioWorklet to improve audio quality and avoid audio glitches due to blocking the UI thread
  3797. const skipAudioWorklet = !!this.privSpeechProcessorScript && this.privSpeechProcessorScript.toLowerCase() === "ignore";
  3798. if (!!context.audioWorklet && !skipAudioWorklet) {
  3799. if (!this.privSpeechProcessorScript) {
  3800. const workletScript = `class SP extends AudioWorkletProcessor {
  3801. constructor(options) {
  3802. super(options);
  3803. }
  3804. process(inputs, outputs) {
  3805. const input = inputs[0];
  3806. const output = [];
  3807. for (let channel = 0; channel < input.length; channel += 1) {
  3808. output[channel] = input[channel];
  3809. }
  3810. this.port.postMessage(output[0]);
  3811. return true;
  3812. }
  3813. }
  3814. registerProcessor('speech-processor', SP);`;
  3815. const blob = new Blob([workletScript], { type: "application/javascript; charset=utf-8" });
  3816. this.privSpeechProcessorScript = URL.createObjectURL(blob);
  3817. }
  3818. context.audioWorklet
  3819. .addModule(this.privSpeechProcessorScript)
  3820. .then(() => {
  3821. const workletNode = new AudioWorkletNode(context, "speech-processor");
  3822. workletNode.port.onmessage = (ev) => {
  3823. const inputFrame = ev.data;
  3824. if (outputStream && !outputStream.isClosed) {
  3825. const waveFrame = waveStreamEncoder.encode(inputFrame);
  3826. if (!!waveFrame) {
  3827. outputStream.writeStreamChunk({
  3828. buffer: waveFrame,
  3829. isEnd: false,
  3830. timeReceived: Date.now(),
  3831. });
  3832. }
  3833. }
  3834. };
  3835. micInput.connect(workletNode);
  3836. workletNode.connect(context.destination);
  3837. this.privMediaResources = {
  3838. scriptProcessorNode: workletNode,
  3839. source: micInput,
  3840. stream: mediaStream,
  3841. };
  3842. })
  3843. .catch(() => {
  3844. attachScriptProcessor();
  3845. });
  3846. }
  3847. else {
  3848. try {
  3849. attachScriptProcessor();
  3850. }
  3851. catch (err) {
  3852. throw new Error(`Unable to start audio worklet node for PCMRecorder: ${err}`);
  3853. }
  3854. }
  3855. }
  3856. releaseMediaResources(context) {
  3857. if (this.privMediaResources) {
  3858. if (this.privMediaResources.scriptProcessorNode) {
  3859. this.privMediaResources.scriptProcessorNode.disconnect(context.destination);
  3860. this.privMediaResources.scriptProcessorNode = null;
  3861. }
  3862. if (this.privMediaResources.source) {
  3863. this.privMediaResources.source.disconnect();
  3864. if (this.privStopInputOnRelease) {
  3865. this.privMediaResources.stream.getTracks().forEach((track) => track.stop());
  3866. }
  3867. this.privMediaResources.source = null;
  3868. }
  3869. }
  3870. }
  3871. setWorkletUrl(url) {
  3872. this.privSpeechProcessorScript = url;
  3873. }
  3874. }
  3875. exports.PcmRecorder = PcmRecorder;
  3876. /***/ }),
  3877. /* 70 */
  3878. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3879. "use strict";
  3880. // Copyright (c) Microsoft Corporation. All rights reserved.
  3881. // Licensed under the MIT license.
  3882. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3883. exports.WebsocketConnection = void 0;
  3884. const Exports_js_1 = __webpack_require__(4);
  3885. const WebsocketMessageAdapter_js_1 = __webpack_require__(71);
  3886. class WebsocketConnection {
  3887. constructor(uri, queryParameters, headers, messageFormatter, proxyInfo, enableCompression = false, connectionId) {
  3888. this.privIsDisposed = false;
  3889. if (!uri) {
  3890. throw new Exports_js_1.ArgumentNullError("uri");
  3891. }
  3892. if (!messageFormatter) {
  3893. throw new Exports_js_1.ArgumentNullError("messageFormatter");
  3894. }
  3895. this.privMessageFormatter = messageFormatter;
  3896. let queryParams = "";
  3897. let i = 0;
  3898. if (queryParameters) {
  3899. for (const paramName in queryParameters) {
  3900. if (paramName) {
  3901. queryParams += ((i === 0) && (uri.indexOf("?") === -1)) ? "?" : "&";
  3902. const key = encodeURIComponent(paramName);
  3903. queryParams += key;
  3904. let val = queryParameters[paramName];
  3905. if (val) {
  3906. val = encodeURIComponent(val);
  3907. queryParams += `=${val}`;
  3908. }
  3909. i++;
  3910. }
  3911. }
  3912. }
  3913. if (headers) {
  3914. for (const headerName in headers) {
  3915. if (headerName) {
  3916. queryParams += ((i === 0) && (uri.indexOf("?") === -1)) ? "?" : "&";
  3917. const val = encodeURIComponent(headers[headerName]);
  3918. queryParams += `${headerName}=${val}`;
  3919. i++;
  3920. }
  3921. }
  3922. }
  3923. this.privUri = uri + queryParams;
  3924. this.privId = connectionId ? connectionId : (0, Exports_js_1.createNoDashGuid)();
  3925. this.privConnectionMessageAdapter = new WebsocketMessageAdapter_js_1.WebsocketMessageAdapter(this.privUri, this.id, this.privMessageFormatter, proxyInfo, headers, enableCompression);
  3926. }
  3927. async dispose() {
  3928. this.privIsDisposed = true;
  3929. if (this.privConnectionMessageAdapter) {
  3930. await this.privConnectionMessageAdapter.close();
  3931. }
  3932. }
  3933. isDisposed() {
  3934. return this.privIsDisposed;
  3935. }
  3936. get id() {
  3937. return this.privId;
  3938. }
  3939. get uri() {
  3940. return this.privUri;
  3941. }
  3942. state() {
  3943. return this.privConnectionMessageAdapter.state;
  3944. }
  3945. open() {
  3946. return this.privConnectionMessageAdapter.open();
  3947. }
  3948. send(message) {
  3949. return this.privConnectionMessageAdapter.send(message);
  3950. }
  3951. read() {
  3952. return this.privConnectionMessageAdapter.read();
  3953. }
  3954. get events() {
  3955. return this.privConnectionMessageAdapter.events;
  3956. }
  3957. }
  3958. exports.WebsocketConnection = WebsocketConnection;
  3959. /***/ }),
  3960. /* 71 */
  3961. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  3962. "use strict";
  3963. // Copyright (c) Microsoft Corporation. All rights reserved.
  3964. // Licensed under the MIT license.
  3965. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3966. if (k2 === undefined) k2 = k;
  3967. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  3968. }) : (function(o, m, k, k2) {
  3969. if (k2 === undefined) k2 = k;
  3970. o[k2] = m[k];
  3971. }));
  3972. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  3973. Object.defineProperty(o, "default", { enumerable: true, value: v });
  3974. }) : function(o, v) {
  3975. o["default"] = v;
  3976. });
  3977. var __importStar = (this && this.__importStar) || function (mod) {
  3978. if (mod && mod.__esModule) return mod;
  3979. var result = {};
  3980. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  3981. __setModuleDefault(result, mod);
  3982. return result;
  3983. };
  3984. var __importDefault = (this && this.__importDefault) || function (mod) {
  3985. return (mod && mod.__esModule) ? mod : { "default": mod };
  3986. };
  3987. Object.defineProperty(exports, "__esModule", ({ value: true }));
  3988. exports.WebsocketMessageAdapter = void 0;
  3989. const net = __importStar(__webpack_require__(72));
  3990. const tls = __importStar(__webpack_require__(73));
  3991. const agent_base_1 = __importDefault(__webpack_require__(74));
  3992. const https_proxy_agent_1 = __importDefault(__webpack_require__(75));
  3993. const ws_1 = __importDefault(__webpack_require__(76));
  3994. const HeaderNames_js_1 = __webpack_require__(54);
  3995. const Exports_js_1 = __webpack_require__(4);
  3996. class WebsocketMessageAdapter {
  3997. constructor(uri, connectionId, messageFormatter, proxyInfo, headers, enableCompression) {
  3998. if (!uri) {
  3999. throw new Exports_js_1.ArgumentNullError("uri");
  4000. }
  4001. if (!messageFormatter) {
  4002. throw new Exports_js_1.ArgumentNullError("messageFormatter");
  4003. }
  4004. this.proxyInfo = proxyInfo;
  4005. this.privConnectionEvents = new Exports_js_1.EventSource();
  4006. this.privConnectionId = connectionId;
  4007. this.privMessageFormatter = messageFormatter;
  4008. this.privConnectionState = Exports_js_1.ConnectionState.None;
  4009. this.privUri = uri;
  4010. this.privHeaders = headers;
  4011. this.privEnableCompression = enableCompression;
  4012. // Add the connection ID to the headers
  4013. this.privHeaders[HeaderNames_js_1.HeaderNames.ConnectionId] = this.privConnectionId;
  4014. this.privHeaders.connectionId = this.privConnectionId;
  4015. this.privLastErrorReceived = "";
  4016. }
  4017. get state() {
  4018. return this.privConnectionState;
  4019. }
  4020. open() {
  4021. if (this.privConnectionState === Exports_js_1.ConnectionState.Disconnected) {
  4022. return Promise.reject(`Cannot open a connection that is in ${this.privConnectionState} state`);
  4023. }
  4024. if (this.privConnectionEstablishDeferral) {
  4025. return this.privConnectionEstablishDeferral.promise;
  4026. }
  4027. this.privConnectionEstablishDeferral = new Exports_js_1.Deferred();
  4028. this.privCertificateValidatedDeferral = new Exports_js_1.Deferred();
  4029. this.privConnectionState = Exports_js_1.ConnectionState.Connecting;
  4030. try {
  4031. if (typeof WebSocket !== "undefined" && !WebsocketMessageAdapter.forceNpmWebSocket) {
  4032. // Browser handles cert checks.
  4033. this.privCertificateValidatedDeferral.resolve();
  4034. this.privWebsocketClient = new WebSocket(this.privUri);
  4035. }
  4036. else {
  4037. // Workaround for https://github.com/microsoft/cognitive-services-speech-sdk-js/issues/465
  4038. // Which is root caused by https://github.com/TooTallNate/node-agent-base/issues/61
  4039. const uri = new URL(this.privUri);
  4040. let protocol = uri.protocol;
  4041. if (protocol?.toLocaleLowerCase() === "wss:") {
  4042. protocol = "https:";
  4043. }
  4044. else if (protocol?.toLocaleLowerCase() === "ws:") {
  4045. protocol = "http:";
  4046. }
  4047. const options = { headers: this.privHeaders, perMessageDeflate: this.privEnableCompression, followRedirects: protocol.toLocaleLowerCase() === "https:" };
  4048. // The ocsp library will handle validation for us and fail the connection if needed.
  4049. this.privCertificateValidatedDeferral.resolve();
  4050. options.agent = this.getAgent();
  4051. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
  4052. options.agent.protocol = protocol;
  4053. this.privWebsocketClient = new ws_1.default(this.privUri, options);
  4054. this.privWebsocketClient.on("redirect", (redirectUrl) => {
  4055. const event = new Exports_js_1.ConnectionRedirectEvent(this.privConnectionId, redirectUrl, this.privUri, `Getting redirect URL from endpoint ${this.privUri} with redirect URL '${redirectUrl}'`);
  4056. Exports_js_1.Events.instance.onEvent(event);
  4057. });
  4058. }
  4059. this.privWebsocketClient.binaryType = "arraybuffer";
  4060. this.privReceivingMessageQueue = new Exports_js_1.Queue();
  4061. this.privDisconnectDeferral = new Exports_js_1.Deferred();
  4062. this.privSendMessageQueue = new Exports_js_1.Queue();
  4063. this.processSendQueue().catch((reason) => {
  4064. Exports_js_1.Events.instance.onEvent(new Exports_js_1.BackgroundEvent(reason));
  4065. });
  4066. }
  4067. catch (error) {
  4068. this.privConnectionEstablishDeferral.resolve(new Exports_js_1.ConnectionOpenResponse(500, error));
  4069. return this.privConnectionEstablishDeferral.promise;
  4070. }
  4071. this.onEvent(new Exports_js_1.ConnectionStartEvent(this.privConnectionId, this.privUri));
  4072. this.privWebsocketClient.onopen = () => {
  4073. this.privCertificateValidatedDeferral.promise.then(() => {
  4074. this.privConnectionState = Exports_js_1.ConnectionState.Connected;
  4075. this.onEvent(new Exports_js_1.ConnectionEstablishedEvent(this.privConnectionId));
  4076. this.privConnectionEstablishDeferral.resolve(new Exports_js_1.ConnectionOpenResponse(200, ""));
  4077. }, (error) => {
  4078. this.privConnectionEstablishDeferral.reject(error);
  4079. });
  4080. };
  4081. this.privWebsocketClient.onerror = (e) => {
  4082. this.onEvent(new Exports_js_1.ConnectionErrorEvent(this.privConnectionId, e.message, e.type));
  4083. this.privLastErrorReceived = e.message;
  4084. };
  4085. this.privWebsocketClient.onclose = (e) => {
  4086. if (this.privConnectionState === Exports_js_1.ConnectionState.Connecting) {
  4087. this.privConnectionState = Exports_js_1.ConnectionState.Disconnected;
  4088. // this.onEvent(new ConnectionEstablishErrorEvent(this.connectionId, e.code, e.reason));
  4089. this.privConnectionEstablishDeferral.resolve(new Exports_js_1.ConnectionOpenResponse(e.code, e.reason + " " + this.privLastErrorReceived));
  4090. }
  4091. else {
  4092. this.privConnectionState = Exports_js_1.ConnectionState.Disconnected;
  4093. this.privWebsocketClient = null;
  4094. this.onEvent(new Exports_js_1.ConnectionClosedEvent(this.privConnectionId, e.code, e.reason));
  4095. }
  4096. this.onClose(e.code, e.reason).catch((reason) => {
  4097. Exports_js_1.Events.instance.onEvent(new Exports_js_1.BackgroundEvent(reason));
  4098. });
  4099. };
  4100. this.privWebsocketClient.onmessage = (e) => {
  4101. const networkReceivedTime = new Date().toISOString();
  4102. if (this.privConnectionState === Exports_js_1.ConnectionState.Connected) {
  4103. const deferred = new Exports_js_1.Deferred();
  4104. // let id = ++this.idCounter;
  4105. this.privReceivingMessageQueue.enqueueFromPromise(deferred.promise);
  4106. if (e.data instanceof ArrayBuffer) {
  4107. const rawMessage = new Exports_js_1.RawWebsocketMessage(Exports_js_1.MessageType.Binary, e.data);
  4108. this.privMessageFormatter
  4109. .toConnectionMessage(rawMessage)
  4110. .then((connectionMessage) => {
  4111. this.onEvent(new Exports_js_1.ConnectionMessageReceivedEvent(this.privConnectionId, networkReceivedTime, connectionMessage));
  4112. deferred.resolve(connectionMessage);
  4113. }, (error) => {
  4114. // TODO: Events for these ?
  4115. deferred.reject(`Invalid binary message format. Error: ${error}`);
  4116. });
  4117. }
  4118. else {
  4119. const rawMessage = new Exports_js_1.RawWebsocketMessage(Exports_js_1.MessageType.Text, e.data);
  4120. this.privMessageFormatter
  4121. .toConnectionMessage(rawMessage)
  4122. .then((connectionMessage) => {
  4123. this.onEvent(new Exports_js_1.ConnectionMessageReceivedEvent(this.privConnectionId, networkReceivedTime, connectionMessage));
  4124. deferred.resolve(connectionMessage);
  4125. }, (error) => {
  4126. // TODO: Events for these ?
  4127. deferred.reject(`Invalid text message format. Error: ${error}`);
  4128. });
  4129. }
  4130. }
  4131. };
  4132. return this.privConnectionEstablishDeferral.promise;
  4133. }
  4134. send(message) {
  4135. if (this.privConnectionState !== Exports_js_1.ConnectionState.Connected) {
  4136. return Promise.reject(`Cannot send on connection that is in ${Exports_js_1.ConnectionState[this.privConnectionState]} state`);
  4137. }
  4138. const messageSendStatusDeferral = new Exports_js_1.Deferred();
  4139. const messageSendDeferral = new Exports_js_1.Deferred();
  4140. this.privSendMessageQueue.enqueueFromPromise(messageSendDeferral.promise);
  4141. this.privMessageFormatter
  4142. .fromConnectionMessage(message)
  4143. .then((rawMessage) => {
  4144. messageSendDeferral.resolve({
  4145. Message: message,
  4146. RawWebsocketMessage: rawMessage,
  4147. sendStatusDeferral: messageSendStatusDeferral,
  4148. });
  4149. }, (error) => {
  4150. messageSendDeferral.reject(`Error formatting the message. ${error}`);
  4151. });
  4152. return messageSendStatusDeferral.promise;
  4153. }
  4154. read() {
  4155. if (this.privConnectionState !== Exports_js_1.ConnectionState.Connected) {
  4156. return Promise.reject(`Cannot read on connection that is in ${this.privConnectionState} state`);
  4157. }
  4158. return this.privReceivingMessageQueue.dequeue();
  4159. }
  4160. close(reason) {
  4161. if (this.privWebsocketClient) {
  4162. if (this.privConnectionState !== Exports_js_1.ConnectionState.Disconnected) {
  4163. this.privWebsocketClient.close(1000, reason ? reason : "Normal closure by client");
  4164. }
  4165. }
  4166. else {
  4167. return Promise.resolve();
  4168. }
  4169. return this.privDisconnectDeferral.promise;
  4170. }
  4171. get events() {
  4172. return this.privConnectionEvents;
  4173. }
  4174. sendRawMessage(sendItem) {
  4175. try {
  4176. // indicates we are draining the queue and it came with no message;
  4177. if (!sendItem) {
  4178. return Promise.resolve();
  4179. }
  4180. this.onEvent(new Exports_js_1.ConnectionMessageSentEvent(this.privConnectionId, new Date().toISOString(), sendItem.Message));
  4181. // add a check for the ws readystate in order to stop the red console error 'WebSocket is already in CLOSING or CLOSED state' appearing
  4182. if (this.isWebsocketOpen) {
  4183. // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  4184. this.privWebsocketClient.send(sendItem.RawWebsocketMessage.payload);
  4185. }
  4186. else {
  4187. return Promise.reject("websocket send error: Websocket not ready " + this.privConnectionId + " " + sendItem.Message.id + " " + new Error().stack);
  4188. }
  4189. return Promise.resolve();
  4190. }
  4191. catch (e) {
  4192. return Promise.reject(`websocket send error: ${e}`);
  4193. }
  4194. }
  4195. async onClose(code, reason) {
  4196. const closeReason = `Connection closed. ${code}: ${reason}`;
  4197. this.privConnectionState = Exports_js_1.ConnectionState.Disconnected;
  4198. this.privDisconnectDeferral.resolve();
  4199. await this.privReceivingMessageQueue.drainAndDispose(() => {
  4200. // TODO: Events for these ?
  4201. // Logger.instance.onEvent(new LoggingEvent(LogType.Warning, null, `Failed to process received message. Reason: ${closeReason}, Message: ${JSON.stringify(pendingReceiveItem)}`));
  4202. }, closeReason);
  4203. await this.privSendMessageQueue.drainAndDispose((pendingSendItem) => {
  4204. pendingSendItem.sendStatusDeferral.reject(closeReason);
  4205. }, closeReason);
  4206. }
  4207. async processSendQueue() {
  4208. while (true) {
  4209. const itemToSend = this.privSendMessageQueue.dequeue();
  4210. const sendItem = await itemToSend;
  4211. // indicates we are draining the queue and it came with no message;
  4212. if (!sendItem) {
  4213. return;
  4214. }
  4215. try {
  4216. await this.sendRawMessage(sendItem);
  4217. sendItem.sendStatusDeferral.resolve();
  4218. }
  4219. catch (sendError) {
  4220. sendItem.sendStatusDeferral.reject(sendError);
  4221. }
  4222. }
  4223. }
  4224. onEvent(event) {
  4225. this.privConnectionEvents.onEvent(event);
  4226. Exports_js_1.Events.instance.onEvent(event);
  4227. }
  4228. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  4229. getAgent() {
  4230. // eslint-disable-next-line @typescript-eslint/unbound-method
  4231. const agent = new agent_base_1.default.Agent(this.createConnection);
  4232. if (this.proxyInfo !== undefined &&
  4233. this.proxyInfo.HostName !== undefined &&
  4234. this.proxyInfo.Port > 0) {
  4235. agent.proxyInfo = this.proxyInfo;
  4236. }
  4237. return agent;
  4238. }
  4239. static GetProxyAgent(proxyInfo) {
  4240. const httpProxyOptions = {
  4241. host: proxyInfo.HostName,
  4242. port: proxyInfo.Port,
  4243. };
  4244. if (!!proxyInfo.UserName) {
  4245. httpProxyOptions.headers = {
  4246. "Proxy-Authentication": "Basic " + new Buffer(`${proxyInfo.UserName}:${(proxyInfo.Password === undefined) ? "" : proxyInfo.Password}`).toString("base64"),
  4247. };
  4248. }
  4249. else {
  4250. httpProxyOptions.headers = {};
  4251. }
  4252. httpProxyOptions.headers.requestOCSP = "true";
  4253. const httpProxyAgent = new https_proxy_agent_1.default(httpProxyOptions);
  4254. return httpProxyAgent;
  4255. }
  4256. createConnection(request, options) {
  4257. let socketPromise;
  4258. options = {
  4259. ...options,
  4260. ...{
  4261. requestOCSP: true,
  4262. servername: options.host
  4263. }
  4264. };
  4265. if (!!this.proxyInfo) {
  4266. const httpProxyAgent = WebsocketMessageAdapter.GetProxyAgent(this.proxyInfo);
  4267. const baseAgent = httpProxyAgent;
  4268. socketPromise = new Promise((resolve, reject) => {
  4269. baseAgent.callback(request, options, (error, socket) => {
  4270. if (!!error) {
  4271. reject(error);
  4272. }
  4273. else {
  4274. resolve(socket);
  4275. }
  4276. });
  4277. });
  4278. }
  4279. else {
  4280. if (!!options.secureEndpoint) {
  4281. socketPromise = Promise.resolve(tls.connect(options));
  4282. }
  4283. else {
  4284. socketPromise = Promise.resolve(net.connect(options));
  4285. }
  4286. }
  4287. return socketPromise;
  4288. }
  4289. get isWebsocketOpen() {
  4290. return this.privWebsocketClient && this.privWebsocketClient.readyState === this.privWebsocketClient.OPEN;
  4291. }
  4292. }
  4293. exports.WebsocketMessageAdapter = WebsocketMessageAdapter;
  4294. WebsocketMessageAdapter.forceNpmWebSocket = false;
  4295. /***/ }),
  4296. /* 72 */
  4297. /***/ (() => {
  4298. /* (ignored) */
  4299. /***/ }),
  4300. /* 73 */
  4301. /***/ (() => {
  4302. /* (ignored) */
  4303. /***/ }),
  4304. /* 74 */
  4305. /***/ (() => {
  4306. /* (ignored) */
  4307. /***/ }),
  4308. /* 75 */
  4309. /***/ (() => {
  4310. /* (ignored) */
  4311. /***/ }),
  4312. /* 76 */
  4313. /***/ (() => {
  4314. /* (ignored) */
  4315. /***/ }),
  4316. /* 77 */
  4317. /***/ ((__unused_webpack_module, exports) => {
  4318. "use strict";
  4319. // Copyright (c) Microsoft Corporation. All rights reserved.
  4320. // Licensed under the MIT license.
  4321. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4322. exports.ReplayableAudioNode = void 0;
  4323. class ReplayableAudioNode {
  4324. constructor(audioSource, bytesPerSecond) {
  4325. this.privBuffers = [];
  4326. this.privReplayOffset = 0;
  4327. this.privLastShrinkOffset = 0;
  4328. this.privBufferStartOffset = 0;
  4329. this.privBufferSerial = 0;
  4330. this.privBufferedBytes = 0;
  4331. this.privReplay = false;
  4332. this.privLastChunkAcquiredTime = 0;
  4333. this.privAudioNode = audioSource;
  4334. this.privBytesPerSecond = bytesPerSecond;
  4335. }
  4336. id() {
  4337. return this.privAudioNode.id();
  4338. }
  4339. // Reads and returns the next chunk of audio buffer.
  4340. // If replay of existing buffers are needed, read() will first seek and replay
  4341. // existing content, and upoin completion it will read new content from the underlying
  4342. // audio node, saving that content into the replayable buffers.
  4343. read() {
  4344. // if there is a replay request to honor.
  4345. if (!!this.privReplay && this.privBuffers.length !== 0) {
  4346. // Find the start point in the buffers.
  4347. // Offsets are in 100ns increments.
  4348. // So how many bytes do we need to seek to get the right offset?
  4349. const offsetToSeek = this.privReplayOffset - this.privBufferStartOffset;
  4350. let bytesToSeek = Math.round(offsetToSeek * this.privBytesPerSecond * 1e-7);
  4351. if (0 !== (bytesToSeek % 2)) {
  4352. bytesToSeek++;
  4353. }
  4354. let i = 0;
  4355. while (i < this.privBuffers.length && bytesToSeek >= this.privBuffers[i].chunk.buffer.byteLength) {
  4356. bytesToSeek -= this.privBuffers[i++].chunk.buffer.byteLength;
  4357. }
  4358. if (i < this.privBuffers.length) {
  4359. const retVal = this.privBuffers[i].chunk.buffer.slice(bytesToSeek);
  4360. this.privReplayOffset += (retVal.byteLength / this.privBytesPerSecond) * 1e+7;
  4361. // If we've reached the end of the buffers, stop replaying.
  4362. if (i === this.privBuffers.length - 1) {
  4363. this.privReplay = false;
  4364. }
  4365. return Promise.resolve({
  4366. buffer: retVal,
  4367. isEnd: false,
  4368. timeReceived: this.privBuffers[i].chunk.timeReceived,
  4369. });
  4370. }
  4371. }
  4372. return this.privAudioNode.read()
  4373. .then((result) => {
  4374. if (result && result.buffer) {
  4375. this.privBuffers.push(new BufferEntry(result, this.privBufferSerial++, this.privBufferedBytes));
  4376. this.privBufferedBytes += result.buffer.byteLength;
  4377. }
  4378. return result;
  4379. });
  4380. }
  4381. detach() {
  4382. this.privBuffers = undefined;
  4383. return this.privAudioNode.detach();
  4384. }
  4385. replay() {
  4386. if (this.privBuffers && 0 !== this.privBuffers.length) {
  4387. this.privReplay = true;
  4388. this.privReplayOffset = this.privLastShrinkOffset;
  4389. }
  4390. }
  4391. // Shrinks the existing audio buffers to start at the new offset, or at the
  4392. // beginning of the buffer closest to the requested offset.
  4393. // A replay request will start from the last shrink point.
  4394. shrinkBuffers(offset) {
  4395. if (this.privBuffers === undefined || this.privBuffers.length === 0) {
  4396. return;
  4397. }
  4398. this.privLastShrinkOffset = offset;
  4399. // Find the start point in the buffers.
  4400. // Offsets are in 100ns increments.
  4401. // So how many bytes do we need to seek to get the right offset?
  4402. const offsetToSeek = offset - this.privBufferStartOffset;
  4403. let bytesToSeek = Math.round(offsetToSeek * this.privBytesPerSecond * 1e-7);
  4404. let i = 0;
  4405. while (i < this.privBuffers.length && bytesToSeek >= this.privBuffers[i].chunk.buffer.byteLength) {
  4406. bytesToSeek -= this.privBuffers[i++].chunk.buffer.byteLength;
  4407. }
  4408. this.privBufferStartOffset = Math.round(offset - ((bytesToSeek / this.privBytesPerSecond) * 1e+7));
  4409. this.privBuffers = this.privBuffers.slice(i);
  4410. }
  4411. // Finds the time a buffer of audio was first seen by offset.
  4412. findTimeAtOffset(offset) {
  4413. if (offset < this.privBufferStartOffset || this.privBuffers === undefined) {
  4414. return 0;
  4415. }
  4416. for (const value of this.privBuffers) {
  4417. const startOffset = (value.byteOffset / this.privBytesPerSecond) * 1e7;
  4418. const endOffset = startOffset + ((value.chunk.buffer.byteLength / this.privBytesPerSecond) * 1e7);
  4419. if (offset >= startOffset && offset <= endOffset) {
  4420. return value.chunk.timeReceived;
  4421. }
  4422. }
  4423. return 0;
  4424. }
  4425. }
  4426. exports.ReplayableAudioNode = ReplayableAudioNode;
  4427. // Primary use of this class is to help debugging problems with the replay
  4428. // code. If the memory cost of alloc / dealloc gets too much, drop it and just use
  4429. // the ArrayBuffer directly.
  4430. class BufferEntry {
  4431. constructor(chunk, serial, byteOffset) {
  4432. this.chunk = chunk;
  4433. this.serial = serial;
  4434. this.byteOffset = byteOffset;
  4435. }
  4436. }
  4437. /***/ }),
  4438. /* 78 */
  4439. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4440. "use strict";
  4441. // Copyright (c) Microsoft Corporation. All rights reserved.
  4442. // Licensed under the MIT license.
  4443. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4444. exports.ProxyInfo = void 0;
  4445. const Exports_js_1 = __webpack_require__(79);
  4446. class ProxyInfo {
  4447. constructor(proxyHostName, proxyPort, proxyUserName, proxyPassword) {
  4448. this.privProxyHostName = proxyHostName;
  4449. this.privProxyPort = proxyPort;
  4450. this.privProxyUserName = proxyUserName;
  4451. this.privProxyPassword = proxyPassword;
  4452. }
  4453. static fromParameters(parameters) {
  4454. return new ProxyInfo(parameters.getProperty(Exports_js_1.PropertyId.SpeechServiceConnection_ProxyHostName), parseInt(parameters.getProperty(Exports_js_1.PropertyId.SpeechServiceConnection_ProxyPort), 10), parameters.getProperty(Exports_js_1.PropertyId.SpeechServiceConnection_ProxyUserName), parameters.getProperty(Exports_js_1.PropertyId.SpeechServiceConnection_ProxyPassword));
  4455. }
  4456. static fromRecognizerConfig(config) {
  4457. return this.fromParameters(config.parameters);
  4458. }
  4459. get HostName() {
  4460. return this.privProxyHostName;
  4461. }
  4462. get Port() {
  4463. return this.privProxyPort;
  4464. }
  4465. get UserName() {
  4466. return this.privProxyUserName;
  4467. }
  4468. get Password() {
  4469. return this.privProxyPassword;
  4470. }
  4471. }
  4472. exports.ProxyInfo = ProxyInfo;
  4473. /***/ }),
  4474. /* 79 */
  4475. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4476. "use strict";
  4477. // Copyright (c) Microsoft Corporation. All rights reserved.
  4478. // Licensed under the MIT license.
  4479. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4480. exports.ConnectionEventArgs = exports.CancellationErrorCode = exports.CancellationDetails = exports.CancellationDetailsBase = exports.IntentRecognitionCanceledEventArgs = exports.TranslationRecognitionCanceledEventArgs = exports.NoMatchDetails = exports.NoMatchReason = exports.Translations = exports.TranslationRecognizer = exports.VoiceProfileType = exports.IntentRecognizer = exports.SpeechRecognizer = exports.Recognizer = exports.PropertyId = exports.PropertyCollection = exports.SpeechTranslationConfigImpl = exports.SpeechTranslationConfig = exports.SpeechConfigImpl = exports.SpeechConfig = exports.ResultReason = exports.TranslationSynthesisResult = exports.TranslationRecognitionResult = exports.TranslationSynthesisEventArgs = exports.TranslationRecognitionEventArgs = exports.SpeechRecognitionCanceledEventArgs = exports.MeetingTranscriptionEventArgs = exports.ConversationTranscriptionEventArgs = exports.SpeechRecognitionEventArgs = exports.LanguageUnderstandingModel = exports.IntentRecognitionResult = exports.SpeechRecognitionResult = exports.RecognitionResult = exports.IntentRecognitionEventArgs = exports.OutputFormat = exports.RecognitionEventArgs = exports.SessionEventArgs = exports.KeywordRecognitionModel = exports.PushAudioOutputStreamCallback = exports.PullAudioInputStreamCallback = exports.CancellationReason = exports.PushAudioOutputStream = exports.PullAudioOutputStream = exports.AudioOutputStream = exports.PushAudioInputStream = exports.PullAudioInputStream = exports.AudioInputStream = exports.AudioFormatTag = exports.AudioStreamFormat = exports.AudioConfig = void 0;
  4481. exports.SpeechSynthesisEventArgs = exports.SpeechSynthesisResult = exports.SynthesisResult = exports.SpeechSynthesizer = exports.SpeechSynthesisOutputFormat = exports.Synthesizer = exports.User = exports.ParticipantChangedReason = exports.Participant = exports.MeetingTranscriber = exports.Meeting = exports.ConversationTranscriptionResult = exports.ConversationTranscriber = exports.ConversationTranslator = exports.ConversationTranslationResult = exports.ConversationTranslationEventArgs = exports.ConversationTranslationCanceledEventArgs = exports.ConversationParticipantsChangedEventArgs = exports.ConversationExpirationEventArgs = exports.Conversation = exports.SpeakerRecognitionCancellationDetails = exports.SpeakerRecognitionResultType = exports.SpeakerRecognitionResult = exports.SourceLanguageConfig = exports.AutoDetectSourceLanguageResult = exports.AutoDetectSourceLanguageConfig = exports.SpeakerVerificationModel = exports.SpeakerIdentificationModel = exports.SpeakerRecognizer = exports.VoiceProfileClient = exports.VoiceProfilePhraseResult = exports.VoiceProfileCancellationDetails = exports.VoiceProfileResult = exports.VoiceProfileEnrollmentCancellationDetails = exports.VoiceProfileEnrollmentResult = exports.VoiceProfile = exports.ConnectionMessage = exports.ConnectionMessageEventArgs = exports.BaseAudioPlayer = exports.ProfanityOption = exports.ServicePropertyChannel = exports.TurnStatusReceivedEventArgs = exports.ActivityReceivedEventArgs = exports.DialogServiceConnector = exports.CustomCommandsConfig = exports.BotFrameworkConfig = exports.DialogServiceConfig = exports.PhraseListGrammar = exports.Connection = exports.ServiceEventArgs = void 0;
  4482. exports.LogLevel = exports.Diagnostics = exports.AvatarWebRTCConnectionResult = exports.Coordinate = exports.AvatarVideoFormat = exports.AvatarSynthesizer = exports.AvatarEventArgs = exports.AvatarConfig = exports.LanguageIdMode = exports.PronunciationAssessmentResult = exports.PronunciationAssessmentConfig = exports.PronunciationAssessmentGranularity = exports.PronunciationAssessmentGradingSystem = exports.MeetingTranscriptionCanceledEventArgs = exports.ConversationTranscriptionCanceledEventArgs = exports.SpeakerAudioDestination = exports.VoiceInfo = exports.SynthesisVoiceType = exports.SynthesisVoiceGender = exports.SynthesisVoicesResult = exports.SpeechSynthesisBoundaryType = exports.SpeechSynthesisVisemeEventArgs = exports.SpeechSynthesisBookmarkEventArgs = exports.SpeechSynthesisWordBoundaryEventArgs = void 0;
  4483. var AudioConfig_js_1 = __webpack_require__(80);
  4484. Object.defineProperty(exports, "AudioConfig", ({ enumerable: true, get: function () { return AudioConfig_js_1.AudioConfig; } }));
  4485. var AudioStreamFormat_js_1 = __webpack_require__(67);
  4486. Object.defineProperty(exports, "AudioStreamFormat", ({ enumerable: true, get: function () { return AudioStreamFormat_js_1.AudioStreamFormat; } }));
  4487. Object.defineProperty(exports, "AudioFormatTag", ({ enumerable: true, get: function () { return AudioStreamFormat_js_1.AudioFormatTag; } }));
  4488. var AudioInputStream_js_1 = __webpack_require__(83);
  4489. Object.defineProperty(exports, "AudioInputStream", ({ enumerable: true, get: function () { return AudioInputStream_js_1.AudioInputStream; } }));
  4490. Object.defineProperty(exports, "PullAudioInputStream", ({ enumerable: true, get: function () { return AudioInputStream_js_1.PullAudioInputStream; } }));
  4491. Object.defineProperty(exports, "PushAudioInputStream", ({ enumerable: true, get: function () { return AudioInputStream_js_1.PushAudioInputStream; } }));
  4492. var AudioOutputStream_js_1 = __webpack_require__(84);
  4493. Object.defineProperty(exports, "AudioOutputStream", ({ enumerable: true, get: function () { return AudioOutputStream_js_1.AudioOutputStream; } }));
  4494. Object.defineProperty(exports, "PullAudioOutputStream", ({ enumerable: true, get: function () { return AudioOutputStream_js_1.PullAudioOutputStream; } }));
  4495. Object.defineProperty(exports, "PushAudioOutputStream", ({ enumerable: true, get: function () { return AudioOutputStream_js_1.PushAudioOutputStream; } }));
  4496. var CancellationReason_js_1 = __webpack_require__(87);
  4497. Object.defineProperty(exports, "CancellationReason", ({ enumerable: true, get: function () { return CancellationReason_js_1.CancellationReason; } }));
  4498. var PullAudioInputStreamCallback_js_1 = __webpack_require__(88);
  4499. Object.defineProperty(exports, "PullAudioInputStreamCallback", ({ enumerable: true, get: function () { return PullAudioInputStreamCallback_js_1.PullAudioInputStreamCallback; } }));
  4500. var PushAudioOutputStreamCallback_js_1 = __webpack_require__(89);
  4501. Object.defineProperty(exports, "PushAudioOutputStreamCallback", ({ enumerable: true, get: function () { return PushAudioOutputStreamCallback_js_1.PushAudioOutputStreamCallback; } }));
  4502. var KeywordRecognitionModel_js_1 = __webpack_require__(90);
  4503. Object.defineProperty(exports, "KeywordRecognitionModel", ({ enumerable: true, get: function () { return KeywordRecognitionModel_js_1.KeywordRecognitionModel; } }));
  4504. var SessionEventArgs_js_1 = __webpack_require__(91);
  4505. Object.defineProperty(exports, "SessionEventArgs", ({ enumerable: true, get: function () { return SessionEventArgs_js_1.SessionEventArgs; } }));
  4506. var RecognitionEventArgs_js_1 = __webpack_require__(92);
  4507. Object.defineProperty(exports, "RecognitionEventArgs", ({ enumerable: true, get: function () { return RecognitionEventArgs_js_1.RecognitionEventArgs; } }));
  4508. var OutputFormat_js_1 = __webpack_require__(93);
  4509. Object.defineProperty(exports, "OutputFormat", ({ enumerable: true, get: function () { return OutputFormat_js_1.OutputFormat; } }));
  4510. var IntentRecognitionEventArgs_js_1 = __webpack_require__(94);
  4511. Object.defineProperty(exports, "IntentRecognitionEventArgs", ({ enumerable: true, get: function () { return IntentRecognitionEventArgs_js_1.IntentRecognitionEventArgs; } }));
  4512. var RecognitionResult_js_1 = __webpack_require__(95);
  4513. Object.defineProperty(exports, "RecognitionResult", ({ enumerable: true, get: function () { return RecognitionResult_js_1.RecognitionResult; } }));
  4514. var SpeechRecognitionResult_js_1 = __webpack_require__(96);
  4515. Object.defineProperty(exports, "SpeechRecognitionResult", ({ enumerable: true, get: function () { return SpeechRecognitionResult_js_1.SpeechRecognitionResult; } }));
  4516. var IntentRecognitionResult_js_1 = __webpack_require__(97);
  4517. Object.defineProperty(exports, "IntentRecognitionResult", ({ enumerable: true, get: function () { return IntentRecognitionResult_js_1.IntentRecognitionResult; } }));
  4518. var LanguageUnderstandingModel_js_1 = __webpack_require__(98);
  4519. Object.defineProperty(exports, "LanguageUnderstandingModel", ({ enumerable: true, get: function () { return LanguageUnderstandingModel_js_1.LanguageUnderstandingModel; } }));
  4520. var SpeechRecognitionEventArgs_js_1 = __webpack_require__(99);
  4521. Object.defineProperty(exports, "SpeechRecognitionEventArgs", ({ enumerable: true, get: function () { return SpeechRecognitionEventArgs_js_1.SpeechRecognitionEventArgs; } }));
  4522. Object.defineProperty(exports, "ConversationTranscriptionEventArgs", ({ enumerable: true, get: function () { return SpeechRecognitionEventArgs_js_1.ConversationTranscriptionEventArgs; } }));
  4523. Object.defineProperty(exports, "MeetingTranscriptionEventArgs", ({ enumerable: true, get: function () { return SpeechRecognitionEventArgs_js_1.MeetingTranscriptionEventArgs; } }));
  4524. var SpeechRecognitionCanceledEventArgs_js_1 = __webpack_require__(100);
  4525. Object.defineProperty(exports, "SpeechRecognitionCanceledEventArgs", ({ enumerable: true, get: function () { return SpeechRecognitionCanceledEventArgs_js_1.SpeechRecognitionCanceledEventArgs; } }));
  4526. var TranslationRecognitionEventArgs_js_1 = __webpack_require__(102);
  4527. Object.defineProperty(exports, "TranslationRecognitionEventArgs", ({ enumerable: true, get: function () { return TranslationRecognitionEventArgs_js_1.TranslationRecognitionEventArgs; } }));
  4528. var TranslationSynthesisEventArgs_js_1 = __webpack_require__(103);
  4529. Object.defineProperty(exports, "TranslationSynthesisEventArgs", ({ enumerable: true, get: function () { return TranslationSynthesisEventArgs_js_1.TranslationSynthesisEventArgs; } }));
  4530. var TranslationRecognitionResult_js_1 = __webpack_require__(104);
  4531. Object.defineProperty(exports, "TranslationRecognitionResult", ({ enumerable: true, get: function () { return TranslationRecognitionResult_js_1.TranslationRecognitionResult; } }));
  4532. var TranslationSynthesisResult_js_1 = __webpack_require__(105);
  4533. Object.defineProperty(exports, "TranslationSynthesisResult", ({ enumerable: true, get: function () { return TranslationSynthesisResult_js_1.TranslationSynthesisResult; } }));
  4534. var ResultReason_js_1 = __webpack_require__(106);
  4535. Object.defineProperty(exports, "ResultReason", ({ enumerable: true, get: function () { return ResultReason_js_1.ResultReason; } }));
  4536. var SpeechConfig_js_1 = __webpack_require__(107);
  4537. Object.defineProperty(exports, "SpeechConfig", ({ enumerable: true, get: function () { return SpeechConfig_js_1.SpeechConfig; } }));
  4538. Object.defineProperty(exports, "SpeechConfigImpl", ({ enumerable: true, get: function () { return SpeechConfig_js_1.SpeechConfigImpl; } }));
  4539. var SpeechTranslationConfig_js_1 = __webpack_require__(108);
  4540. Object.defineProperty(exports, "SpeechTranslationConfig", ({ enumerable: true, get: function () { return SpeechTranslationConfig_js_1.SpeechTranslationConfig; } }));
  4541. Object.defineProperty(exports, "SpeechTranslationConfigImpl", ({ enumerable: true, get: function () { return SpeechTranslationConfig_js_1.SpeechTranslationConfigImpl; } }));
  4542. var PropertyCollection_js_1 = __webpack_require__(109);
  4543. Object.defineProperty(exports, "PropertyCollection", ({ enumerable: true, get: function () { return PropertyCollection_js_1.PropertyCollection; } }));
  4544. var PropertyId_js_1 = __webpack_require__(110);
  4545. Object.defineProperty(exports, "PropertyId", ({ enumerable: true, get: function () { return PropertyId_js_1.PropertyId; } }));
  4546. var Recognizer_js_1 = __webpack_require__(111);
  4547. Object.defineProperty(exports, "Recognizer", ({ enumerable: true, get: function () { return Recognizer_js_1.Recognizer; } }));
  4548. var SpeechRecognizer_js_1 = __webpack_require__(112);
  4549. Object.defineProperty(exports, "SpeechRecognizer", ({ enumerable: true, get: function () { return SpeechRecognizer_js_1.SpeechRecognizer; } }));
  4550. var IntentRecognizer_js_1 = __webpack_require__(114);
  4551. Object.defineProperty(exports, "IntentRecognizer", ({ enumerable: true, get: function () { return IntentRecognizer_js_1.IntentRecognizer; } }));
  4552. var VoiceProfileType_js_1 = __webpack_require__(115);
  4553. Object.defineProperty(exports, "VoiceProfileType", ({ enumerable: true, get: function () { return VoiceProfileType_js_1.VoiceProfileType; } }));
  4554. var TranslationRecognizer_js_1 = __webpack_require__(116);
  4555. Object.defineProperty(exports, "TranslationRecognizer", ({ enumerable: true, get: function () { return TranslationRecognizer_js_1.TranslationRecognizer; } }));
  4556. var Translations_js_1 = __webpack_require__(119);
  4557. Object.defineProperty(exports, "Translations", ({ enumerable: true, get: function () { return Translations_js_1.Translations; } }));
  4558. var NoMatchReason_js_1 = __webpack_require__(120);
  4559. Object.defineProperty(exports, "NoMatchReason", ({ enumerable: true, get: function () { return NoMatchReason_js_1.NoMatchReason; } }));
  4560. var NoMatchDetails_js_1 = __webpack_require__(121);
  4561. Object.defineProperty(exports, "NoMatchDetails", ({ enumerable: true, get: function () { return NoMatchDetails_js_1.NoMatchDetails; } }));
  4562. var TranslationRecognitionCanceledEventArgs_js_1 = __webpack_require__(122);
  4563. Object.defineProperty(exports, "TranslationRecognitionCanceledEventArgs", ({ enumerable: true, get: function () { return TranslationRecognitionCanceledEventArgs_js_1.TranslationRecognitionCanceledEventArgs; } }));
  4564. var IntentRecognitionCanceledEventArgs_js_1 = __webpack_require__(123);
  4565. Object.defineProperty(exports, "IntentRecognitionCanceledEventArgs", ({ enumerable: true, get: function () { return IntentRecognitionCanceledEventArgs_js_1.IntentRecognitionCanceledEventArgs; } }));
  4566. var CancellationDetailsBase_js_1 = __webpack_require__(124);
  4567. Object.defineProperty(exports, "CancellationDetailsBase", ({ enumerable: true, get: function () { return CancellationDetailsBase_js_1.CancellationDetailsBase; } }));
  4568. var CancellationDetails_js_1 = __webpack_require__(125);
  4569. Object.defineProperty(exports, "CancellationDetails", ({ enumerable: true, get: function () { return CancellationDetails_js_1.CancellationDetails; } }));
  4570. var CancellationErrorCodes_js_1 = __webpack_require__(126);
  4571. Object.defineProperty(exports, "CancellationErrorCode", ({ enumerable: true, get: function () { return CancellationErrorCodes_js_1.CancellationErrorCode; } }));
  4572. var ConnectionEventArgs_js_1 = __webpack_require__(127);
  4573. Object.defineProperty(exports, "ConnectionEventArgs", ({ enumerable: true, get: function () { return ConnectionEventArgs_js_1.ConnectionEventArgs; } }));
  4574. var ServiceEventArgs_js_1 = __webpack_require__(128);
  4575. Object.defineProperty(exports, "ServiceEventArgs", ({ enumerable: true, get: function () { return ServiceEventArgs_js_1.ServiceEventArgs; } }));
  4576. var Connection_js_1 = __webpack_require__(117);
  4577. Object.defineProperty(exports, "Connection", ({ enumerable: true, get: function () { return Connection_js_1.Connection; } }));
  4578. var PhraseListGrammar_js_1 = __webpack_require__(129);
  4579. Object.defineProperty(exports, "PhraseListGrammar", ({ enumerable: true, get: function () { return PhraseListGrammar_js_1.PhraseListGrammar; } }));
  4580. var DialogServiceConfig_js_1 = __webpack_require__(130);
  4581. Object.defineProperty(exports, "DialogServiceConfig", ({ enumerable: true, get: function () { return DialogServiceConfig_js_1.DialogServiceConfig; } }));
  4582. var BotFrameworkConfig_js_1 = __webpack_require__(131);
  4583. Object.defineProperty(exports, "BotFrameworkConfig", ({ enumerable: true, get: function () { return BotFrameworkConfig_js_1.BotFrameworkConfig; } }));
  4584. var CustomCommandsConfig_js_1 = __webpack_require__(132);
  4585. Object.defineProperty(exports, "CustomCommandsConfig", ({ enumerable: true, get: function () { return CustomCommandsConfig_js_1.CustomCommandsConfig; } }));
  4586. var DialogServiceConnector_js_1 = __webpack_require__(133);
  4587. Object.defineProperty(exports, "DialogServiceConnector", ({ enumerable: true, get: function () { return DialogServiceConnector_js_1.DialogServiceConnector; } }));
  4588. var ActivityReceivedEventArgs_js_1 = __webpack_require__(137);
  4589. Object.defineProperty(exports, "ActivityReceivedEventArgs", ({ enumerable: true, get: function () { return ActivityReceivedEventArgs_js_1.ActivityReceivedEventArgs; } }));
  4590. var TurnStatusReceivedEventArgs_js_1 = __webpack_require__(138);
  4591. Object.defineProperty(exports, "TurnStatusReceivedEventArgs", ({ enumerable: true, get: function () { return TurnStatusReceivedEventArgs_js_1.TurnStatusReceivedEventArgs; } }));
  4592. var ServicePropertyChannel_js_1 = __webpack_require__(140);
  4593. Object.defineProperty(exports, "ServicePropertyChannel", ({ enumerable: true, get: function () { return ServicePropertyChannel_js_1.ServicePropertyChannel; } }));
  4594. var ProfanityOption_js_1 = __webpack_require__(141);
  4595. Object.defineProperty(exports, "ProfanityOption", ({ enumerable: true, get: function () { return ProfanityOption_js_1.ProfanityOption; } }));
  4596. var BaseAudioPlayer_js_1 = __webpack_require__(142);
  4597. Object.defineProperty(exports, "BaseAudioPlayer", ({ enumerable: true, get: function () { return BaseAudioPlayer_js_1.BaseAudioPlayer; } }));
  4598. var ConnectionMessageEventArgs_js_1 = __webpack_require__(143);
  4599. Object.defineProperty(exports, "ConnectionMessageEventArgs", ({ enumerable: true, get: function () { return ConnectionMessageEventArgs_js_1.ConnectionMessageEventArgs; } }));
  4600. var ConnectionMessage_js_1 = __webpack_require__(118);
  4601. Object.defineProperty(exports, "ConnectionMessage", ({ enumerable: true, get: function () { return ConnectionMessage_js_1.ConnectionMessage; } }));
  4602. var VoiceProfile_js_1 = __webpack_require__(144);
  4603. Object.defineProperty(exports, "VoiceProfile", ({ enumerable: true, get: function () { return VoiceProfile_js_1.VoiceProfile; } }));
  4604. var VoiceProfileEnrollmentResult_js_1 = __webpack_require__(145);
  4605. Object.defineProperty(exports, "VoiceProfileEnrollmentResult", ({ enumerable: true, get: function () { return VoiceProfileEnrollmentResult_js_1.VoiceProfileEnrollmentResult; } }));
  4606. Object.defineProperty(exports, "VoiceProfileEnrollmentCancellationDetails", ({ enumerable: true, get: function () { return VoiceProfileEnrollmentResult_js_1.VoiceProfileEnrollmentCancellationDetails; } }));
  4607. var VoiceProfileResult_js_1 = __webpack_require__(146);
  4608. Object.defineProperty(exports, "VoiceProfileResult", ({ enumerable: true, get: function () { return VoiceProfileResult_js_1.VoiceProfileResult; } }));
  4609. Object.defineProperty(exports, "VoiceProfileCancellationDetails", ({ enumerable: true, get: function () { return VoiceProfileResult_js_1.VoiceProfileCancellationDetails; } }));
  4610. var VoiceProfilePhraseResult_js_1 = __webpack_require__(147);
  4611. Object.defineProperty(exports, "VoiceProfilePhraseResult", ({ enumerable: true, get: function () { return VoiceProfilePhraseResult_js_1.VoiceProfilePhraseResult; } }));
  4612. var VoiceProfileClient_js_1 = __webpack_require__(148);
  4613. Object.defineProperty(exports, "VoiceProfileClient", ({ enumerable: true, get: function () { return VoiceProfileClient_js_1.VoiceProfileClient; } }));
  4614. var SpeakerRecognizer_js_1 = __webpack_require__(149);
  4615. Object.defineProperty(exports, "SpeakerRecognizer", ({ enumerable: true, get: function () { return SpeakerRecognizer_js_1.SpeakerRecognizer; } }));
  4616. var SpeakerIdentificationModel_js_1 = __webpack_require__(150);
  4617. Object.defineProperty(exports, "SpeakerIdentificationModel", ({ enumerable: true, get: function () { return SpeakerIdentificationModel_js_1.SpeakerIdentificationModel; } }));
  4618. var SpeakerVerificationModel_js_1 = __webpack_require__(151);
  4619. Object.defineProperty(exports, "SpeakerVerificationModel", ({ enumerable: true, get: function () { return SpeakerVerificationModel_js_1.SpeakerVerificationModel; } }));
  4620. var AutoDetectSourceLanguageConfig_js_1 = __webpack_require__(152);
  4621. Object.defineProperty(exports, "AutoDetectSourceLanguageConfig", ({ enumerable: true, get: function () { return AutoDetectSourceLanguageConfig_js_1.AutoDetectSourceLanguageConfig; } }));
  4622. var AutoDetectSourceLanguageResult_js_1 = __webpack_require__(154);
  4623. Object.defineProperty(exports, "AutoDetectSourceLanguageResult", ({ enumerable: true, get: function () { return AutoDetectSourceLanguageResult_js_1.AutoDetectSourceLanguageResult; } }));
  4624. var SourceLanguageConfig_js_1 = __webpack_require__(155);
  4625. Object.defineProperty(exports, "SourceLanguageConfig", ({ enumerable: true, get: function () { return SourceLanguageConfig_js_1.SourceLanguageConfig; } }));
  4626. var SpeakerRecognitionResult_js_1 = __webpack_require__(156);
  4627. Object.defineProperty(exports, "SpeakerRecognitionResult", ({ enumerable: true, get: function () { return SpeakerRecognitionResult_js_1.SpeakerRecognitionResult; } }));
  4628. Object.defineProperty(exports, "SpeakerRecognitionResultType", ({ enumerable: true, get: function () { return SpeakerRecognitionResult_js_1.SpeakerRecognitionResultType; } }));
  4629. Object.defineProperty(exports, "SpeakerRecognitionCancellationDetails", ({ enumerable: true, get: function () { return SpeakerRecognitionResult_js_1.SpeakerRecognitionCancellationDetails; } }));
  4630. var Exports_js_1 = __webpack_require__(157);
  4631. Object.defineProperty(exports, "Conversation", ({ enumerable: true, get: function () { return Exports_js_1.Conversation; } }));
  4632. Object.defineProperty(exports, "ConversationExpirationEventArgs", ({ enumerable: true, get: function () { return Exports_js_1.ConversationExpirationEventArgs; } }));
  4633. Object.defineProperty(exports, "ConversationParticipantsChangedEventArgs", ({ enumerable: true, get: function () { return Exports_js_1.ConversationParticipantsChangedEventArgs; } }));
  4634. Object.defineProperty(exports, "ConversationTranslationCanceledEventArgs", ({ enumerable: true, get: function () { return Exports_js_1.ConversationTranslationCanceledEventArgs; } }));
  4635. Object.defineProperty(exports, "ConversationTranslationEventArgs", ({ enumerable: true, get: function () { return Exports_js_1.ConversationTranslationEventArgs; } }));
  4636. Object.defineProperty(exports, "ConversationTranslationResult", ({ enumerable: true, get: function () { return Exports_js_1.ConversationTranslationResult; } }));
  4637. Object.defineProperty(exports, "ConversationTranslator", ({ enumerable: true, get: function () { return Exports_js_1.ConversationTranslator; } }));
  4638. Object.defineProperty(exports, "ConversationTranscriber", ({ enumerable: true, get: function () { return Exports_js_1.ConversationTranscriber; } }));
  4639. Object.defineProperty(exports, "ConversationTranscriptionResult", ({ enumerable: true, get: function () { return Exports_js_1.ConversationTranscriptionResult; } }));
  4640. Object.defineProperty(exports, "Meeting", ({ enumerable: true, get: function () { return Exports_js_1.Meeting; } }));
  4641. Object.defineProperty(exports, "MeetingTranscriber", ({ enumerable: true, get: function () { return Exports_js_1.MeetingTranscriber; } }));
  4642. Object.defineProperty(exports, "Participant", ({ enumerable: true, get: function () { return Exports_js_1.Participant; } }));
  4643. Object.defineProperty(exports, "ParticipantChangedReason", ({ enumerable: true, get: function () { return Exports_js_1.ParticipantChangedReason; } }));
  4644. Object.defineProperty(exports, "User", ({ enumerable: true, get: function () { return Exports_js_1.User; } }));
  4645. var Synthesizer_js_1 = __webpack_require__(175);
  4646. Object.defineProperty(exports, "Synthesizer", ({ enumerable: true, get: function () { return Synthesizer_js_1.Synthesizer; } }));
  4647. var SpeechSynthesisOutputFormat_js_1 = __webpack_require__(86);
  4648. Object.defineProperty(exports, "SpeechSynthesisOutputFormat", ({ enumerable: true, get: function () { return SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat; } }));
  4649. var SpeechSynthesizer_js_1 = __webpack_require__(176);
  4650. Object.defineProperty(exports, "SpeechSynthesizer", ({ enumerable: true, get: function () { return SpeechSynthesizer_js_1.SpeechSynthesizer; } }));
  4651. var SynthesisResult_js_1 = __webpack_require__(177);
  4652. Object.defineProperty(exports, "SynthesisResult", ({ enumerable: true, get: function () { return SynthesisResult_js_1.SynthesisResult; } }));
  4653. var SpeechSynthesisResult_js_1 = __webpack_require__(178);
  4654. Object.defineProperty(exports, "SpeechSynthesisResult", ({ enumerable: true, get: function () { return SpeechSynthesisResult_js_1.SpeechSynthesisResult; } }));
  4655. var SpeechSynthesisEventArgs_js_1 = __webpack_require__(179);
  4656. Object.defineProperty(exports, "SpeechSynthesisEventArgs", ({ enumerable: true, get: function () { return SpeechSynthesisEventArgs_js_1.SpeechSynthesisEventArgs; } }));
  4657. var SpeechSynthesisWordBoundaryEventArgs_js_1 = __webpack_require__(180);
  4658. Object.defineProperty(exports, "SpeechSynthesisWordBoundaryEventArgs", ({ enumerable: true, get: function () { return SpeechSynthesisWordBoundaryEventArgs_js_1.SpeechSynthesisWordBoundaryEventArgs; } }));
  4659. var SpeechSynthesisBookmarkEventArgs_js_1 = __webpack_require__(181);
  4660. Object.defineProperty(exports, "SpeechSynthesisBookmarkEventArgs", ({ enumerable: true, get: function () { return SpeechSynthesisBookmarkEventArgs_js_1.SpeechSynthesisBookmarkEventArgs; } }));
  4661. var SpeechSynthesisVisemeEventArgs_js_1 = __webpack_require__(182);
  4662. Object.defineProperty(exports, "SpeechSynthesisVisemeEventArgs", ({ enumerable: true, get: function () { return SpeechSynthesisVisemeEventArgs_js_1.SpeechSynthesisVisemeEventArgs; } }));
  4663. var SpeechSynthesisBoundaryType_js_1 = __webpack_require__(183);
  4664. Object.defineProperty(exports, "SpeechSynthesisBoundaryType", ({ enumerable: true, get: function () { return SpeechSynthesisBoundaryType_js_1.SpeechSynthesisBoundaryType; } }));
  4665. var SynthesisVoicesResult_js_1 = __webpack_require__(184);
  4666. Object.defineProperty(exports, "SynthesisVoicesResult", ({ enumerable: true, get: function () { return SynthesisVoicesResult_js_1.SynthesisVoicesResult; } }));
  4667. var VoiceInfo_js_1 = __webpack_require__(185);
  4668. Object.defineProperty(exports, "SynthesisVoiceGender", ({ enumerable: true, get: function () { return VoiceInfo_js_1.SynthesisVoiceGender; } }));
  4669. Object.defineProperty(exports, "SynthesisVoiceType", ({ enumerable: true, get: function () { return VoiceInfo_js_1.SynthesisVoiceType; } }));
  4670. Object.defineProperty(exports, "VoiceInfo", ({ enumerable: true, get: function () { return VoiceInfo_js_1.VoiceInfo; } }));
  4671. var SpeakerAudioDestination_js_1 = __webpack_require__(186);
  4672. Object.defineProperty(exports, "SpeakerAudioDestination", ({ enumerable: true, get: function () { return SpeakerAudioDestination_js_1.SpeakerAudioDestination; } }));
  4673. var ConversationTranscriptionCanceledEventArgs_js_1 = __webpack_require__(187);
  4674. Object.defineProperty(exports, "ConversationTranscriptionCanceledEventArgs", ({ enumerable: true, get: function () { return ConversationTranscriptionCanceledEventArgs_js_1.ConversationTranscriptionCanceledEventArgs; } }));
  4675. var MeetingTranscriptionCanceledEventArgs_js_1 = __webpack_require__(188);
  4676. Object.defineProperty(exports, "MeetingTranscriptionCanceledEventArgs", ({ enumerable: true, get: function () { return MeetingTranscriptionCanceledEventArgs_js_1.MeetingTranscriptionCanceledEventArgs; } }));
  4677. var PronunciationAssessmentGradingSystem_js_1 = __webpack_require__(189);
  4678. Object.defineProperty(exports, "PronunciationAssessmentGradingSystem", ({ enumerable: true, get: function () { return PronunciationAssessmentGradingSystem_js_1.PronunciationAssessmentGradingSystem; } }));
  4679. var PronunciationAssessmentGranularity_js_1 = __webpack_require__(190);
  4680. Object.defineProperty(exports, "PronunciationAssessmentGranularity", ({ enumerable: true, get: function () { return PronunciationAssessmentGranularity_js_1.PronunciationAssessmentGranularity; } }));
  4681. var PronunciationAssessmentConfig_js_1 = __webpack_require__(191);
  4682. Object.defineProperty(exports, "PronunciationAssessmentConfig", ({ enumerable: true, get: function () { return PronunciationAssessmentConfig_js_1.PronunciationAssessmentConfig; } }));
  4683. var PronunciationAssessmentResult_js_1 = __webpack_require__(192);
  4684. Object.defineProperty(exports, "PronunciationAssessmentResult", ({ enumerable: true, get: function () { return PronunciationAssessmentResult_js_1.PronunciationAssessmentResult; } }));
  4685. var LanguageIdMode_js_1 = __webpack_require__(153);
  4686. Object.defineProperty(exports, "LanguageIdMode", ({ enumerable: true, get: function () { return LanguageIdMode_js_1.LanguageIdMode; } }));
  4687. var AvatarConfig_js_1 = __webpack_require__(193);
  4688. Object.defineProperty(exports, "AvatarConfig", ({ enumerable: true, get: function () { return AvatarConfig_js_1.AvatarConfig; } }));
  4689. var AvatarEventArgs_js_1 = __webpack_require__(194);
  4690. Object.defineProperty(exports, "AvatarEventArgs", ({ enumerable: true, get: function () { return AvatarEventArgs_js_1.AvatarEventArgs; } }));
  4691. var AvatarSynthesizer_js_1 = __webpack_require__(195);
  4692. Object.defineProperty(exports, "AvatarSynthesizer", ({ enumerable: true, get: function () { return AvatarSynthesizer_js_1.AvatarSynthesizer; } }));
  4693. var AvatarVideoFormat_js_1 = __webpack_require__(197);
  4694. Object.defineProperty(exports, "AvatarVideoFormat", ({ enumerable: true, get: function () { return AvatarVideoFormat_js_1.AvatarVideoFormat; } }));
  4695. Object.defineProperty(exports, "Coordinate", ({ enumerable: true, get: function () { return AvatarVideoFormat_js_1.Coordinate; } }));
  4696. var AvatarWebRTCConnectionResult_js_1 = __webpack_require__(198);
  4697. Object.defineProperty(exports, "AvatarWebRTCConnectionResult", ({ enumerable: true, get: function () { return AvatarWebRTCConnectionResult_js_1.AvatarWebRTCConnectionResult; } }));
  4698. var Diagnostics_js_1 = __webpack_require__(199);
  4699. Object.defineProperty(exports, "Diagnostics", ({ enumerable: true, get: function () { return Diagnostics_js_1.Diagnostics; } }));
  4700. var LogLevel_js_1 = __webpack_require__(63);
  4701. Object.defineProperty(exports, "LogLevel", ({ enumerable: true, get: function () { return LogLevel_js_1.LogLevel; } }));
  4702. /***/ }),
  4703. /* 80 */
  4704. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4705. "use strict";
  4706. // Copyright (c) Microsoft Corporation. All rights reserved.
  4707. // Licensed under the MIT license.
  4708. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4709. exports.AudioOutputConfigImpl = exports.AudioConfigImpl = exports.AudioConfig = void 0;
  4710. const Exports_js_1 = __webpack_require__(60);
  4711. const Contracts_js_1 = __webpack_require__(64);
  4712. const Exports_js_2 = __webpack_require__(79);
  4713. const AudioFileWriter_js_1 = __webpack_require__(81);
  4714. const AudioInputStream_js_1 = __webpack_require__(83);
  4715. const AudioOutputStream_js_1 = __webpack_require__(84);
  4716. /**
  4717. * Represents audio input configuration used for specifying what type of input to use (microphone, file, stream).
  4718. * @class AudioConfig
  4719. * Updated in version 1.11.0
  4720. */
  4721. class AudioConfig {
  4722. /**
  4723. * Creates an AudioConfig object representing the default microphone on the system.
  4724. * @member AudioConfig.fromDefaultMicrophoneInput
  4725. * @function
  4726. * @public
  4727. * @returns {AudioConfig} The audio input configuration being created.
  4728. */
  4729. static fromDefaultMicrophoneInput() {
  4730. const pcmRecorder = new Exports_js_1.PcmRecorder(true);
  4731. return new AudioConfigImpl(new Exports_js_1.MicAudioSource(pcmRecorder));
  4732. }
  4733. /**
  4734. * Creates an AudioConfig object representing a microphone with the specified device ID.
  4735. * @member AudioConfig.fromMicrophoneInput
  4736. * @function
  4737. * @public
  4738. * @param {string | undefined} deviceId - Specifies the device ID of the microphone to be used.
  4739. * Default microphone is used the value is omitted.
  4740. * @returns {AudioConfig} The audio input configuration being created.
  4741. */
  4742. static fromMicrophoneInput(deviceId) {
  4743. const pcmRecorder = new Exports_js_1.PcmRecorder(true);
  4744. return new AudioConfigImpl(new Exports_js_1.MicAudioSource(pcmRecorder, deviceId));
  4745. }
  4746. /**
  4747. * Creates an AudioConfig object representing the specified file.
  4748. * @member AudioConfig.fromWavFileInput
  4749. * @function
  4750. * @public
  4751. * @param {File} fileName - Specifies the audio input file. Currently, only WAV / PCM is supported.
  4752. * @returns {AudioConfig} The audio input configuration being created.
  4753. */
  4754. static fromWavFileInput(file, name = "unnamedBuffer.wav") {
  4755. return new AudioConfigImpl(new Exports_js_1.FileAudioSource(file, name));
  4756. }
  4757. /**
  4758. * Creates an AudioConfig object representing the specified stream.
  4759. * @member AudioConfig.fromStreamInput
  4760. * @function
  4761. * @public
  4762. * @param {AudioInputStream | PullAudioInputStreamCallback | MediaStream} audioStream - Specifies the custom audio input
  4763. * stream. Currently, only WAV / PCM is supported.
  4764. * @returns {AudioConfig} The audio input configuration being created.
  4765. */
  4766. static fromStreamInput(audioStream) {
  4767. if (audioStream instanceof Exports_js_2.PullAudioInputStreamCallback) {
  4768. return new AudioConfigImpl(new AudioInputStream_js_1.PullAudioInputStreamImpl(audioStream));
  4769. }
  4770. if (audioStream instanceof Exports_js_2.AudioInputStream) {
  4771. return new AudioConfigImpl(audioStream);
  4772. }
  4773. if (typeof MediaStream !== "undefined" && audioStream instanceof MediaStream) {
  4774. const pcmRecorder = new Exports_js_1.PcmRecorder(false);
  4775. return new AudioConfigImpl(new Exports_js_1.MicAudioSource(pcmRecorder, null, null, audioStream));
  4776. }
  4777. throw new Error("Not Supported Type");
  4778. }
  4779. /**
  4780. * Creates an AudioConfig object representing the default speaker.
  4781. * @member AudioConfig.fromDefaultSpeakerOutput
  4782. * @function
  4783. * @public
  4784. * @returns {AudioConfig} The audio output configuration being created.
  4785. * Added in version 1.11.0
  4786. */
  4787. static fromDefaultSpeakerOutput() {
  4788. return new AudioOutputConfigImpl(new Exports_js_2.SpeakerAudioDestination());
  4789. }
  4790. /**
  4791. * Creates an AudioConfig object representing the custom IPlayer object.
  4792. * You can use the IPlayer object to control pause, resume, etc.
  4793. * @member AudioConfig.fromSpeakerOutput
  4794. * @function
  4795. * @public
  4796. * @param {IPlayer} player - the IPlayer object for playback.
  4797. * @returns {AudioConfig} The audio output configuration being created.
  4798. * Added in version 1.12.0
  4799. */
  4800. static fromSpeakerOutput(player) {
  4801. if (player === undefined) {
  4802. return AudioConfig.fromDefaultSpeakerOutput();
  4803. }
  4804. if (player instanceof Exports_js_2.SpeakerAudioDestination) {
  4805. return new AudioOutputConfigImpl(player);
  4806. }
  4807. throw new Error("Not Supported Type");
  4808. }
  4809. /**
  4810. * Creates an AudioConfig object representing a specified output audio file
  4811. * @member AudioConfig.fromAudioFileOutput
  4812. * @function
  4813. * @public
  4814. * @param {PathLike} filename - the filename of the output audio file
  4815. * @returns {AudioConfig} The audio output configuration being created.
  4816. * Added in version 1.11.0
  4817. */
  4818. static fromAudioFileOutput(filename) {
  4819. return new AudioOutputConfigImpl(new AudioFileWriter_js_1.AudioFileWriter(filename));
  4820. }
  4821. /**
  4822. * Creates an AudioConfig object representing a specified audio output stream
  4823. * @member AudioConfig.fromStreamOutput
  4824. * @function
  4825. * @public
  4826. * @param {AudioOutputStream | PushAudioOutputStreamCallback} audioStream - Specifies the custom audio output
  4827. * stream.
  4828. * @returns {AudioConfig} The audio output configuration being created.
  4829. * Added in version 1.11.0
  4830. */
  4831. static fromStreamOutput(audioStream) {
  4832. if (audioStream instanceof Exports_js_2.PushAudioOutputStreamCallback) {
  4833. return new AudioOutputConfigImpl(new AudioOutputStream_js_1.PushAudioOutputStreamImpl(audioStream));
  4834. }
  4835. if (audioStream instanceof Exports_js_2.PushAudioOutputStream) {
  4836. return new AudioOutputConfigImpl(audioStream);
  4837. }
  4838. if (audioStream instanceof Exports_js_2.PullAudioOutputStream) {
  4839. return new AudioOutputConfigImpl(audioStream);
  4840. }
  4841. throw new Error("Not Supported Type");
  4842. }
  4843. }
  4844. exports.AudioConfig = AudioConfig;
  4845. /**
  4846. * Represents audio input stream used for custom audio input configurations.
  4847. * @private
  4848. * @class AudioConfigImpl
  4849. */
  4850. class AudioConfigImpl extends AudioConfig {
  4851. /**
  4852. * Creates and initializes an instance of this class.
  4853. * @constructor
  4854. * @param {IAudioSource} source - An audio source.
  4855. */
  4856. constructor(source) {
  4857. super();
  4858. this.privSource = source;
  4859. }
  4860. /**
  4861. * Format information for the audio
  4862. */
  4863. get format() {
  4864. return this.privSource.format;
  4865. }
  4866. /**
  4867. * @member AudioConfigImpl.prototype.close
  4868. * @function
  4869. * @public
  4870. */
  4871. close(cb, err) {
  4872. this.privSource.turnOff().then(() => {
  4873. if (!!cb) {
  4874. cb();
  4875. }
  4876. }, (error) => {
  4877. if (!!err) {
  4878. err(error);
  4879. }
  4880. });
  4881. }
  4882. /**
  4883. * @member AudioConfigImpl.prototype.id
  4884. * @function
  4885. * @public
  4886. */
  4887. id() {
  4888. return this.privSource.id();
  4889. }
  4890. /**
  4891. * @member AudioConfigImpl.prototype.turnOn
  4892. * @function
  4893. * @public
  4894. * @returns {Promise<void>} A promise.
  4895. */
  4896. turnOn() {
  4897. return this.privSource.turnOn();
  4898. }
  4899. /**
  4900. * @member AudioConfigImpl.prototype.attach
  4901. * @function
  4902. * @public
  4903. * @param {string} audioNodeId - The audio node id.
  4904. * @returns {Promise<IAudioStreamNode>} A promise.
  4905. */
  4906. attach(audioNodeId) {
  4907. return this.privSource.attach(audioNodeId);
  4908. }
  4909. /**
  4910. * @member AudioConfigImpl.prototype.detach
  4911. * @function
  4912. * @public
  4913. * @param {string} audioNodeId - The audio node id.
  4914. */
  4915. detach(audioNodeId) {
  4916. return this.privSource.detach(audioNodeId);
  4917. }
  4918. /**
  4919. * @member AudioConfigImpl.prototype.turnOff
  4920. * @function
  4921. * @public
  4922. * @returns {Promise<void>} A promise.
  4923. */
  4924. turnOff() {
  4925. return this.privSource.turnOff();
  4926. }
  4927. /**
  4928. * @member AudioConfigImpl.prototype.events
  4929. * @function
  4930. * @public
  4931. * @returns {EventSource<AudioSourceEvent>} An event source for audio events.
  4932. */
  4933. get events() {
  4934. return this.privSource.events;
  4935. }
  4936. setProperty(name, value) {
  4937. Contracts_js_1.Contracts.throwIfNull(value, "value");
  4938. if (undefined !== this.privSource.setProperty) {
  4939. this.privSource.setProperty(name, value);
  4940. }
  4941. else {
  4942. throw new Error("This AudioConfig instance does not support setting properties.");
  4943. }
  4944. }
  4945. getProperty(name, def) {
  4946. if (undefined !== this.privSource.getProperty) {
  4947. return this.privSource.getProperty(name, def);
  4948. }
  4949. else {
  4950. throw new Error("This AudioConfig instance does not support getting properties.");
  4951. }
  4952. return def;
  4953. }
  4954. get deviceInfo() {
  4955. return this.privSource.deviceInfo;
  4956. }
  4957. }
  4958. exports.AudioConfigImpl = AudioConfigImpl;
  4959. class AudioOutputConfigImpl extends AudioConfig {
  4960. /**
  4961. * Creates and initializes an instance of this class.
  4962. * @constructor
  4963. * @param {IAudioDestination} destination - An audio destination.
  4964. */
  4965. constructor(destination) {
  4966. super();
  4967. this.privDestination = destination;
  4968. }
  4969. set format(format) {
  4970. this.privDestination.format = format;
  4971. }
  4972. write(buffer) {
  4973. this.privDestination.write(buffer);
  4974. }
  4975. close() {
  4976. this.privDestination.close();
  4977. }
  4978. id() {
  4979. return this.privDestination.id();
  4980. }
  4981. setProperty() {
  4982. throw new Error("This AudioConfig instance does not support setting properties.");
  4983. }
  4984. getProperty() {
  4985. throw new Error("This AudioConfig instance does not support getting properties.");
  4986. }
  4987. }
  4988. exports.AudioOutputConfigImpl = AudioOutputConfigImpl;
  4989. /***/ }),
  4990. /* 81 */
  4991. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  4992. "use strict";
  4993. // Copyright (c) Microsoft Corporation. All rights reserved.
  4994. // Licensed under the MIT license.
  4995. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  4996. if (k2 === undefined) k2 = k;
  4997. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  4998. }) : (function(o, m, k, k2) {
  4999. if (k2 === undefined) k2 = k;
  5000. o[k2] = m[k];
  5001. }));
  5002. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  5003. Object.defineProperty(o, "default", { enumerable: true, value: v });
  5004. }) : function(o, v) {
  5005. o["default"] = v;
  5006. });
  5007. var __importStar = (this && this.__importStar) || function (mod) {
  5008. if (mod && mod.__esModule) return mod;
  5009. var result = {};
  5010. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  5011. __setModuleDefault(result, mod);
  5012. return result;
  5013. };
  5014. Object.defineProperty(exports, "__esModule", ({ value: true }));
  5015. exports.AudioFileWriter = void 0;
  5016. const fs = __importStar(__webpack_require__(82));
  5017. const Contracts_js_1 = __webpack_require__(64);
  5018. class AudioFileWriter {
  5019. constructor(filename) {
  5020. Contracts_js_1.Contracts.throwIfNullOrUndefined(fs.openSync, "\nFile System access not available, please use Push or PullAudioOutputStream");
  5021. this.privFd = fs.openSync(filename, "w");
  5022. }
  5023. set format(format) {
  5024. Contracts_js_1.Contracts.throwIfNotUndefined(this.privAudioFormat, "format is already set");
  5025. this.privAudioFormat = format;
  5026. let headerOffset = 0;
  5027. if (this.privAudioFormat.hasHeader) {
  5028. headerOffset = this.privAudioFormat.header.byteLength;
  5029. }
  5030. if (this.privFd !== undefined) {
  5031. this.privWriteStream = fs.createWriteStream("", { fd: this.privFd, start: headerOffset, autoClose: false });
  5032. }
  5033. }
  5034. write(buffer) {
  5035. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privAudioFormat, "must set format before writing.");
  5036. if (this.privWriteStream !== undefined) {
  5037. this.privWriteStream.write(new Uint8Array(buffer.slice(0)));
  5038. }
  5039. }
  5040. close() {
  5041. if (this.privFd !== undefined) {
  5042. this.privWriteStream.on("finish", () => {
  5043. if (this.privAudioFormat.hasHeader) {
  5044. this.privAudioFormat.updateHeader(this.privWriteStream.bytesWritten);
  5045. fs.writeSync(this.privFd, new Int8Array(this.privAudioFormat.header), 0, this.privAudioFormat.header.byteLength, 0);
  5046. }
  5047. fs.closeSync(this.privFd);
  5048. this.privFd = undefined;
  5049. });
  5050. this.privWriteStream.end();
  5051. }
  5052. }
  5053. id() {
  5054. return this.privId;
  5055. }
  5056. }
  5057. exports.AudioFileWriter = AudioFileWriter;
  5058. /***/ }),
  5059. /* 82 */
  5060. /***/ (() => {
  5061. /* (ignored) */
  5062. /***/ }),
  5063. /* 83 */
  5064. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5065. "use strict";
  5066. // Copyright (c) Microsoft Corporation. All rights reserved.
  5067. // Licensed under the MIT license.
  5068. Object.defineProperty(exports, "__esModule", ({ value: true }));
  5069. exports.PullAudioInputStreamImpl = exports.PullAudioInputStream = exports.PushAudioInputStreamImpl = exports.PushAudioInputStream = exports.AudioInputStream = void 0;
  5070. /* eslint-disable max-classes-per-file */
  5071. const Exports_js_1 = __webpack_require__(2);
  5072. const Exports_js_2 = __webpack_require__(4);
  5073. const Guid_js_1 = __webpack_require__(7);
  5074. const Exports_js_3 = __webpack_require__(79);
  5075. const AudioStreamFormat_js_1 = __webpack_require__(67);
  5076. /**
  5077. * Represents audio input stream used for custom audio input configurations.
  5078. * @class AudioInputStream
  5079. */
  5080. class AudioInputStream {
  5081. /**
  5082. * Creates and initializes an instance.
  5083. * @constructor
  5084. */
  5085. constructor() {
  5086. return;
  5087. }
  5088. /**
  5089. * Creates a memory backed PushAudioInputStream with the specified audio format.
  5090. * @member AudioInputStream.createPushStream
  5091. * @function
  5092. * @public
  5093. * @param {AudioStreamFormat} format - The audio data format in which audio will be
  5094. * written to the push audio stream's write() method (Required if format is not 16 kHz 16bit mono PCM).
  5095. * @returns {PushAudioInputStream} The audio input stream being created.
  5096. */
  5097. static createPushStream(format) {
  5098. return PushAudioInputStream.create(format);
  5099. }
  5100. /**
  5101. * Creates a PullAudioInputStream that delegates to the specified callback interface for read()
  5102. * and close() methods.
  5103. * @member AudioInputStream.createPullStream
  5104. * @function
  5105. * @public
  5106. * @param {PullAudioInputStreamCallback} callback - The custom audio input object, derived from
  5107. * PullAudioInputStreamCallback
  5108. * @param {AudioStreamFormat} format - The audio data format in which audio will be returned from
  5109. * the callback's read() method (Required if format is not 16 kHz 16bit mono PCM).
  5110. * @returns {PullAudioInputStream} The audio input stream being created.
  5111. */
  5112. static createPullStream(callback, format) {
  5113. return PullAudioInputStream.create(callback, format);
  5114. // throw new Error("Oops");
  5115. }
  5116. }
  5117. exports.AudioInputStream = AudioInputStream;
  5118. /**
  5119. * Represents memory backed push audio input stream used for custom audio input configurations.
  5120. * @class PushAudioInputStream
  5121. */
  5122. class PushAudioInputStream extends AudioInputStream {
  5123. /**
  5124. * Creates a memory backed PushAudioInputStream with the specified audio format.
  5125. * @member PushAudioInputStream.create
  5126. * @function
  5127. * @public
  5128. * @param {AudioStreamFormat} format - The audio data format in which audio will be written to the
  5129. * push audio stream's write() method (Required if format is not 16 kHz 16bit mono PCM).
  5130. * @returns {PushAudioInputStream} The push audio input stream being created.
  5131. */
  5132. static create(format) {
  5133. return new PushAudioInputStreamImpl(format);
  5134. }
  5135. }
  5136. exports.PushAudioInputStream = PushAudioInputStream;
  5137. /**
  5138. * Represents memory backed push audio input stream used for custom audio input configurations.
  5139. * @private
  5140. * @class PushAudioInputStreamImpl
  5141. */
  5142. class PushAudioInputStreamImpl extends PushAudioInputStream {
  5143. /**
  5144. * Creates and initalizes an instance with the given values.
  5145. * @constructor
  5146. * @param {AudioStreamFormat} format - The audio stream format.
  5147. */
  5148. constructor(format) {
  5149. super();
  5150. if (format === undefined) {
  5151. this.privFormat = AudioStreamFormat_js_1.AudioStreamFormatImpl.getDefaultInputFormat();
  5152. }
  5153. else {
  5154. this.privFormat = format;
  5155. }
  5156. this.privEvents = new Exports_js_2.EventSource();
  5157. this.privId = (0, Guid_js_1.createNoDashGuid)();
  5158. this.privStream = new Exports_js_2.ChunkedArrayBufferStream(this.privFormat.avgBytesPerSec / 10);
  5159. }
  5160. /**
  5161. * Format information for the audio
  5162. */
  5163. get format() {
  5164. return Promise.resolve(this.privFormat);
  5165. }
  5166. /**
  5167. * Writes the audio data specified by making an internal copy of the data.
  5168. * @member PushAudioInputStreamImpl.prototype.write
  5169. * @function
  5170. * @public
  5171. * @param {ArrayBuffer} dataBuffer - The audio buffer of which this function will make a copy.
  5172. */
  5173. write(dataBuffer) {
  5174. this.privStream.writeStreamChunk({
  5175. buffer: dataBuffer,
  5176. isEnd: false,
  5177. timeReceived: Date.now()
  5178. });
  5179. }
  5180. /**
  5181. * Closes the stream.
  5182. * @member PushAudioInputStreamImpl.prototype.close
  5183. * @function
  5184. * @public
  5185. */
  5186. close() {
  5187. this.privStream.close();
  5188. }
  5189. id() {
  5190. return this.privId;
  5191. }
  5192. turnOn() {
  5193. this.onEvent(new Exports_js_2.AudioSourceInitializingEvent(this.privId)); // no stream id
  5194. this.onEvent(new Exports_js_2.AudioSourceReadyEvent(this.privId));
  5195. return;
  5196. }
  5197. async attach(audioNodeId) {
  5198. this.onEvent(new Exports_js_2.AudioStreamNodeAttachingEvent(this.privId, audioNodeId));
  5199. await this.turnOn();
  5200. const stream = this.privStream;
  5201. this.onEvent(new Exports_js_2.AudioStreamNodeAttachedEvent(this.privId, audioNodeId));
  5202. return {
  5203. detach: async () => {
  5204. this.onEvent(new Exports_js_2.AudioStreamNodeDetachedEvent(this.privId, audioNodeId));
  5205. return this.turnOff();
  5206. },
  5207. id: () => audioNodeId,
  5208. read: () => stream.read(),
  5209. };
  5210. }
  5211. detach(audioNodeId) {
  5212. this.onEvent(new Exports_js_2.AudioStreamNodeDetachedEvent(this.privId, audioNodeId));
  5213. }
  5214. turnOff() {
  5215. return;
  5216. }
  5217. get events() {
  5218. return this.privEvents;
  5219. }
  5220. get deviceInfo() {
  5221. return Promise.resolve({
  5222. bitspersample: this.privFormat.bitsPerSample,
  5223. channelcount: this.privFormat.channels,
  5224. connectivity: Exports_js_1.connectivity.Unknown,
  5225. manufacturer: "Speech SDK",
  5226. model: "PushStream",
  5227. samplerate: this.privFormat.samplesPerSec,
  5228. type: Exports_js_1.type.Stream,
  5229. });
  5230. }
  5231. onEvent(event) {
  5232. this.privEvents.onEvent(event);
  5233. Exports_js_2.Events.instance.onEvent(event);
  5234. }
  5235. toBuffer(arrayBuffer) {
  5236. const buf = Buffer.alloc(arrayBuffer.byteLength);
  5237. const view = new Uint8Array(arrayBuffer);
  5238. for (let i = 0; i < buf.length; ++i) {
  5239. buf[i] = view[i];
  5240. }
  5241. return buf;
  5242. }
  5243. }
  5244. exports.PushAudioInputStreamImpl = PushAudioInputStreamImpl;
  5245. /*
  5246. * Represents audio input stream used for custom audio input configurations.
  5247. * @class PullAudioInputStream
  5248. */
  5249. class PullAudioInputStream extends AudioInputStream {
  5250. /**
  5251. * Creates and initializes and instance.
  5252. * @constructor
  5253. */
  5254. constructor() {
  5255. super();
  5256. }
  5257. /**
  5258. * Creates a PullAudioInputStream that delegates to the specified callback interface for
  5259. * read() and close() methods, using the default format (16 kHz 16bit mono PCM).
  5260. * @member PullAudioInputStream.create
  5261. * @function
  5262. * @public
  5263. * @param {PullAudioInputStreamCallback} callback - The custom audio input object,
  5264. * derived from PullAudioInputStreamCustomCallback
  5265. * @param {AudioStreamFormat} format - The audio data format in which audio will be
  5266. * returned from the callback's read() method (Required if format is not 16 kHz 16bit mono PCM).
  5267. * @returns {PullAudioInputStream} The push audio input stream being created.
  5268. */
  5269. static create(callback, format) {
  5270. return new PullAudioInputStreamImpl(callback, format);
  5271. }
  5272. }
  5273. exports.PullAudioInputStream = PullAudioInputStream;
  5274. /**
  5275. * Represents audio input stream used for custom audio input configurations.
  5276. * @private
  5277. * @class PullAudioInputStreamImpl
  5278. */
  5279. class PullAudioInputStreamImpl extends PullAudioInputStream {
  5280. /**
  5281. * Creates a PullAudioInputStream that delegates to the specified callback interface for
  5282. * read() and close() methods, using the default format (16 kHz 16bit mono PCM).
  5283. * @constructor
  5284. * @param {PullAudioInputStreamCallback} callback - The custom audio input object,
  5285. * derived from PullAudioInputStreamCustomCallback
  5286. * @param {AudioStreamFormat} format - The audio data format in which audio will be
  5287. * returned from the callback's read() method (Required if format is not 16 kHz 16bit mono PCM).
  5288. */
  5289. constructor(callback, format) {
  5290. super();
  5291. if (undefined === format) {
  5292. this.privFormat = Exports_js_3.AudioStreamFormat.getDefaultInputFormat();
  5293. }
  5294. else {
  5295. this.privFormat = format;
  5296. }
  5297. this.privEvents = new Exports_js_2.EventSource();
  5298. this.privId = (0, Guid_js_1.createNoDashGuid)();
  5299. this.privCallback = callback;
  5300. this.privIsClosed = false;
  5301. this.privBufferSize = this.privFormat.avgBytesPerSec / 10;
  5302. }
  5303. /**
  5304. * Format information for the audio
  5305. */
  5306. get format() {
  5307. return Promise.resolve(this.privFormat);
  5308. }
  5309. /**
  5310. * Closes the stream.
  5311. * @member PullAudioInputStreamImpl.prototype.close
  5312. * @function
  5313. * @public
  5314. */
  5315. close() {
  5316. this.privIsClosed = true;
  5317. this.privCallback.close();
  5318. }
  5319. id() {
  5320. return this.privId;
  5321. }
  5322. turnOn() {
  5323. this.onEvent(new Exports_js_2.AudioSourceInitializingEvent(this.privId)); // no stream id
  5324. this.onEvent(new Exports_js_2.AudioSourceReadyEvent(this.privId));
  5325. return;
  5326. }
  5327. async attach(audioNodeId) {
  5328. this.onEvent(new Exports_js_2.AudioStreamNodeAttachingEvent(this.privId, audioNodeId));
  5329. await this.turnOn();
  5330. this.onEvent(new Exports_js_2.AudioStreamNodeAttachedEvent(this.privId, audioNodeId));
  5331. return {
  5332. detach: () => {
  5333. this.privCallback.close();
  5334. this.onEvent(new Exports_js_2.AudioStreamNodeDetachedEvent(this.privId, audioNodeId));
  5335. return this.turnOff();
  5336. },
  5337. id: () => audioNodeId,
  5338. read: () => {
  5339. let totalBytes = 0;
  5340. let transmitBuff;
  5341. // Until we have the minimum number of bytes to send in a transmission, keep asking for more.
  5342. while (totalBytes < this.privBufferSize) {
  5343. // Sizing the read buffer to the delta between the perfect size and what's left means we won't ever get too much
  5344. // data back.
  5345. const readBuff = new ArrayBuffer(this.privBufferSize - totalBytes);
  5346. const pulledBytes = this.privCallback.read(readBuff);
  5347. // If there is no return buffer yet defined, set the return buffer to the that was just populated.
  5348. // This was, if we have enough data there's no copy penalty, but if we don't we have a buffer that's the
  5349. // preferred size allocated.
  5350. if (undefined === transmitBuff) {
  5351. transmitBuff = readBuff;
  5352. }
  5353. else {
  5354. // Not the first bite at the apple, so fill the return buffer with the data we got back.
  5355. const intView = new Int8Array(transmitBuff);
  5356. intView.set(new Int8Array(readBuff), totalBytes);
  5357. }
  5358. // If there are no bytes to read, just break out and be done.
  5359. if (0 === pulledBytes) {
  5360. break;
  5361. }
  5362. totalBytes += pulledBytes;
  5363. }
  5364. return Promise.resolve({
  5365. buffer: transmitBuff.slice(0, totalBytes),
  5366. isEnd: this.privIsClosed || totalBytes === 0,
  5367. timeReceived: Date.now(),
  5368. });
  5369. },
  5370. };
  5371. }
  5372. detach(audioNodeId) {
  5373. this.onEvent(new Exports_js_2.AudioStreamNodeDetachedEvent(this.privId, audioNodeId));
  5374. }
  5375. turnOff() {
  5376. return;
  5377. }
  5378. get events() {
  5379. return this.privEvents;
  5380. }
  5381. get deviceInfo() {
  5382. return Promise.resolve({
  5383. bitspersample: this.privFormat.bitsPerSample,
  5384. channelcount: this.privFormat.channels,
  5385. connectivity: Exports_js_1.connectivity.Unknown,
  5386. manufacturer: "Speech SDK",
  5387. model: "PullStream",
  5388. samplerate: this.privFormat.samplesPerSec,
  5389. type: Exports_js_1.type.Stream,
  5390. });
  5391. }
  5392. onEvent(event) {
  5393. this.privEvents.onEvent(event);
  5394. Exports_js_2.Events.instance.onEvent(event);
  5395. }
  5396. }
  5397. exports.PullAudioInputStreamImpl = PullAudioInputStreamImpl;
  5398. /***/ }),
  5399. /* 84 */
  5400. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5401. "use strict";
  5402. // Copyright (c) Microsoft Corporation. All rights reserved.
  5403. // Licensed under the MIT license.
  5404. Object.defineProperty(exports, "__esModule", ({ value: true }));
  5405. exports.PushAudioOutputStreamImpl = exports.PushAudioOutputStream = exports.PullAudioOutputStreamImpl = exports.PullAudioOutputStream = exports.AudioOutputStream = void 0;
  5406. /* eslint-disable max-classes-per-file */
  5407. const Exports_js_1 = __webpack_require__(4);
  5408. const Contracts_js_1 = __webpack_require__(64);
  5409. const AudioOutputFormat_js_1 = __webpack_require__(85);
  5410. /**
  5411. * Represents audio output stream used for custom audio output configurations.
  5412. * @class AudioOutputStream
  5413. */
  5414. class AudioOutputStream {
  5415. /**
  5416. * Creates and initializes an instance.
  5417. * @constructor
  5418. */
  5419. constructor() {
  5420. return;
  5421. }
  5422. /**
  5423. * Creates a memory backed PullAudioOutputStream with the specified audio format.
  5424. * @member AudioOutputStream.createPullStream
  5425. * @function
  5426. * @public
  5427. * @returns {PullAudioOutputStream} The audio output stream being created.
  5428. */
  5429. static createPullStream() {
  5430. return PullAudioOutputStream.create();
  5431. }
  5432. }
  5433. exports.AudioOutputStream = AudioOutputStream;
  5434. /**
  5435. * Represents memory backed push audio output stream used for custom audio output configurations.
  5436. * @class PullAudioOutputStream
  5437. */
  5438. class PullAudioOutputStream extends AudioOutputStream {
  5439. /**
  5440. * Creates a memory backed PullAudioOutputStream with the specified audio format.
  5441. * @member PullAudioOutputStream.create
  5442. * @function
  5443. * @public
  5444. * @returns {PullAudioOutputStream} The push audio output stream being created.
  5445. */
  5446. static create() {
  5447. return new PullAudioOutputStreamImpl();
  5448. }
  5449. }
  5450. exports.PullAudioOutputStream = PullAudioOutputStream;
  5451. /**
  5452. * Represents memory backed push audio output stream used for custom audio output configurations.
  5453. * @private
  5454. * @class PullAudioOutputStreamImpl
  5455. */
  5456. class PullAudioOutputStreamImpl extends PullAudioOutputStream {
  5457. /**
  5458. * Creates and initializes an instance with the given values.
  5459. * @constructor
  5460. */
  5461. constructor() {
  5462. super();
  5463. this.privId = (0, Exports_js_1.createNoDashGuid)();
  5464. this.privStream = new Exports_js_1.Stream();
  5465. }
  5466. /**
  5467. * Sets the format information to the stream. For internal use only.
  5468. * @param {AudioStreamFormat} format - the format to be set.
  5469. */
  5470. set format(format) {
  5471. if (format === undefined || format === null) {
  5472. this.privFormat = AudioOutputFormat_js_1.AudioOutputFormatImpl.getDefaultOutputFormat();
  5473. }
  5474. this.privFormat = format;
  5475. }
  5476. /**
  5477. * Format information for the audio
  5478. */
  5479. get format() {
  5480. return this.privFormat;
  5481. }
  5482. /**
  5483. * Checks if the stream is closed
  5484. * @member PullAudioOutputStreamImpl.prototype.isClosed
  5485. * @property
  5486. * @public
  5487. */
  5488. get isClosed() {
  5489. return this.privStream.isClosed;
  5490. }
  5491. /**
  5492. * Gets the id of the stream
  5493. * @member PullAudioOutputStreamImpl.prototype.id
  5494. * @property
  5495. * @public
  5496. */
  5497. id() {
  5498. return this.privId;
  5499. }
  5500. /**
  5501. * Reads audio data from the internal buffer.
  5502. * @member PullAudioOutputStreamImpl.prototype.read
  5503. * @function
  5504. * @public
  5505. * @param {ArrayBuffer} dataBuffer - An ArrayBuffer to store the read data.
  5506. * @returns {Promise<number>} - Audio buffer length has been read.
  5507. */
  5508. async read(dataBuffer) {
  5509. const intView = new Int8Array(dataBuffer);
  5510. let totalBytes = 0;
  5511. if (this.privLastChunkView !== undefined) {
  5512. if (this.privLastChunkView.length > dataBuffer.byteLength) {
  5513. intView.set(this.privLastChunkView.slice(0, dataBuffer.byteLength));
  5514. this.privLastChunkView = this.privLastChunkView.slice(dataBuffer.byteLength);
  5515. return Promise.resolve(dataBuffer.byteLength);
  5516. }
  5517. intView.set(this.privLastChunkView);
  5518. totalBytes = this.privLastChunkView.length;
  5519. this.privLastChunkView = undefined;
  5520. }
  5521. // Until we have the minimum number of bytes to send in a transmission, keep asking for more.
  5522. while (totalBytes < dataBuffer.byteLength && !this.privStream.isReadEnded) {
  5523. const chunk = await this.privStream.read();
  5524. if (chunk !== undefined && !chunk.isEnd) {
  5525. let tmpBuffer;
  5526. if (chunk.buffer.byteLength > dataBuffer.byteLength - totalBytes) {
  5527. tmpBuffer = chunk.buffer.slice(0, dataBuffer.byteLength - totalBytes);
  5528. this.privLastChunkView = new Int8Array(chunk.buffer.slice(dataBuffer.byteLength - totalBytes));
  5529. }
  5530. else {
  5531. tmpBuffer = chunk.buffer;
  5532. }
  5533. intView.set(new Int8Array(tmpBuffer), totalBytes);
  5534. totalBytes += tmpBuffer.byteLength;
  5535. }
  5536. else {
  5537. this.privStream.readEnded();
  5538. }
  5539. }
  5540. return totalBytes;
  5541. }
  5542. /**
  5543. * Writes the audio data specified by making an internal copy of the data.
  5544. * @member PullAudioOutputStreamImpl.prototype.write
  5545. * @function
  5546. * @public
  5547. * @param {ArrayBuffer} dataBuffer - The audio buffer of which this function will make a copy.
  5548. */
  5549. write(dataBuffer) {
  5550. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privStream, "must set format before writing");
  5551. this.privStream.writeStreamChunk({
  5552. buffer: dataBuffer,
  5553. isEnd: false,
  5554. timeReceived: Date.now()
  5555. });
  5556. }
  5557. /**
  5558. * Closes the stream.
  5559. * @member PullAudioOutputStreamImpl.prototype.close
  5560. * @function
  5561. * @public
  5562. */
  5563. close() {
  5564. this.privStream.close();
  5565. }
  5566. }
  5567. exports.PullAudioOutputStreamImpl = PullAudioOutputStreamImpl;
  5568. /*
  5569. * Represents audio output stream used for custom audio output configurations.
  5570. * @class PushAudioOutputStream
  5571. */
  5572. class PushAudioOutputStream extends AudioOutputStream {
  5573. /**
  5574. * Creates and initializes and instance.
  5575. * @constructor
  5576. */
  5577. constructor() {
  5578. super();
  5579. }
  5580. /**
  5581. * Creates a PushAudioOutputStream that delegates to the specified callback interface for
  5582. * write() and close() methods.
  5583. * @member PushAudioOutputStream.create
  5584. * @function
  5585. * @public
  5586. * @param {PushAudioOutputStreamCallback} callback - The custom audio output object,
  5587. * derived from PushAudioOutputStreamCallback
  5588. * @returns {PushAudioOutputStream} The push audio output stream being created.
  5589. */
  5590. static create(callback) {
  5591. return new PushAudioOutputStreamImpl(callback);
  5592. }
  5593. }
  5594. exports.PushAudioOutputStream = PushAudioOutputStream;
  5595. /**
  5596. * Represents audio output stream used for custom audio output configurations.
  5597. * @private
  5598. * @class PushAudioOutputStreamImpl
  5599. */
  5600. class PushAudioOutputStreamImpl extends PushAudioOutputStream {
  5601. /**
  5602. * Creates a PushAudioOutputStream that delegates to the specified callback interface for
  5603. * read() and close() methods.
  5604. * @constructor
  5605. * @param {PushAudioOutputStreamCallback} callback - The custom audio output object,
  5606. * derived from PushAudioOutputStreamCallback
  5607. */
  5608. constructor(callback) {
  5609. super();
  5610. this.privId = (0, Exports_js_1.createNoDashGuid)();
  5611. this.privCallback = callback;
  5612. }
  5613. // eslint-disable-next-line @typescript-eslint/no-empty-function
  5614. set format(format) { }
  5615. write(buffer) {
  5616. if (!!this.privCallback.write) {
  5617. this.privCallback.write(buffer);
  5618. }
  5619. }
  5620. close() {
  5621. if (!!this.privCallback.close) {
  5622. this.privCallback.close();
  5623. }
  5624. }
  5625. id() {
  5626. return this.privId;
  5627. }
  5628. }
  5629. exports.PushAudioOutputStreamImpl = PushAudioOutputStreamImpl;
  5630. /***/ }),
  5631. /* 85 */
  5632. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5633. "use strict";
  5634. // Copyright (c) Microsoft Corporation. All rights reserved.
  5635. // Licensed under the MIT license.
  5636. Object.defineProperty(exports, "__esModule", ({ value: true }));
  5637. exports.AudioOutputFormatImpl = void 0;
  5638. const SpeechSynthesisOutputFormat_js_1 = __webpack_require__(86);
  5639. const AudioStreamFormat_js_1 = __webpack_require__(67);
  5640. /**
  5641. * @private
  5642. * @class AudioOutputFormatImpl
  5643. * Updated in version 1.17.0
  5644. */
  5645. // eslint-disable-next-line max-classes-per-file
  5646. class AudioOutputFormatImpl extends AudioStreamFormat_js_1.AudioStreamFormatImpl {
  5647. /**
  5648. * Creates an instance with the given values.
  5649. * @constructor
  5650. * @param formatTag
  5651. * @param {number} channels - Number of channels.
  5652. * @param {number} samplesPerSec - Samples per second.
  5653. * @param {number} avgBytesPerSec - Average bytes per second.
  5654. * @param {number} blockAlign - Block alignment.
  5655. * @param {number} bitsPerSample - Bits per sample.
  5656. * @param {string} audioFormatString - Audio format string
  5657. * @param {string} requestAudioFormatString - Audio format string sent to service.
  5658. * @param {boolean} hasHeader - If the format has header or not.
  5659. */
  5660. constructor(formatTag, channels, samplesPerSec, avgBytesPerSec, blockAlign, bitsPerSample, audioFormatString, requestAudioFormatString, hasHeader) {
  5661. super(samplesPerSec, bitsPerSample, channels, formatTag);
  5662. this.formatTag = formatTag;
  5663. this.avgBytesPerSec = avgBytesPerSec;
  5664. this.blockAlign = blockAlign;
  5665. this.priAudioFormatString = audioFormatString;
  5666. this.priRequestAudioFormatString = requestAudioFormatString;
  5667. this.priHasHeader = hasHeader;
  5668. }
  5669. static fromSpeechSynthesisOutputFormat(speechSynthesisOutputFormat) {
  5670. if (speechSynthesisOutputFormat === undefined) {
  5671. return AudioOutputFormatImpl.getDefaultOutputFormat();
  5672. }
  5673. return AudioOutputFormatImpl.fromSpeechSynthesisOutputFormatString(AudioOutputFormatImpl.SpeechSynthesisOutputFormatToString[speechSynthesisOutputFormat]);
  5674. }
  5675. static fromSpeechSynthesisOutputFormatString(speechSynthesisOutputFormatString) {
  5676. switch (speechSynthesisOutputFormatString) {
  5677. case "raw-8khz-8bit-mono-mulaw":
  5678. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MuLaw, 1, 8000, 8000, 1, 8, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5679. case "riff-16khz-16kbps-mono-siren":
  5680. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.Siren, 1, 16000, 2000, 40, 0, speechSynthesisOutputFormatString, "audio-16khz-16kbps-mono-siren", true);
  5681. case "audio-16khz-16kbps-mono-siren":
  5682. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.Siren, 1, 16000, 2000, 40, 0, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5683. case "audio-16khz-32kbitrate-mono-mp3":
  5684. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MP3, 1, 16000, 32 << 7, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5685. case "audio-16khz-128kbitrate-mono-mp3":
  5686. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MP3, 1, 16000, 128 << 7, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5687. case "audio-16khz-64kbitrate-mono-mp3":
  5688. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MP3, 1, 16000, 64 << 7, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5689. case "audio-24khz-48kbitrate-mono-mp3":
  5690. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MP3, 1, 24000, 48 << 7, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5691. case "audio-24khz-96kbitrate-mono-mp3":
  5692. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MP3, 1, 24000, 96 << 7, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5693. case "audio-24khz-160kbitrate-mono-mp3":
  5694. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MP3, 1, 24000, 160 << 7, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5695. case "raw-16khz-16bit-mono-truesilk":
  5696. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.SILKSkype, 1, 16000, 32000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5697. case "riff-8khz-16bit-mono-pcm":
  5698. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 8000, 16000, 2, 16, speechSynthesisOutputFormatString, "raw-8khz-16bit-mono-pcm", true);
  5699. case "riff-24khz-16bit-mono-pcm":
  5700. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 24000, 48000, 2, 16, speechSynthesisOutputFormatString, "raw-24khz-16bit-mono-pcm", true);
  5701. case "riff-8khz-8bit-mono-mulaw":
  5702. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MuLaw, 1, 8000, 8000, 1, 8, speechSynthesisOutputFormatString, "raw-8khz-8bit-mono-mulaw", true);
  5703. case "raw-16khz-16bit-mono-pcm":
  5704. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 16000, 32000, 2, 16, speechSynthesisOutputFormatString, "raw-16khz-16bit-mono-pcm", false);
  5705. case "raw-24khz-16bit-mono-pcm":
  5706. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 24000, 48000, 2, 16, speechSynthesisOutputFormatString, "raw-24khz-16bit-mono-pcm", false);
  5707. case "raw-8khz-16bit-mono-pcm":
  5708. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 8000, 16000, 2, 16, speechSynthesisOutputFormatString, "raw-8khz-16bit-mono-pcm", false);
  5709. case "ogg-16khz-16bit-mono-opus":
  5710. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.OGG_OPUS, 1, 16000, 8192, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5711. case "ogg-24khz-16bit-mono-opus":
  5712. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.OGG_OPUS, 1, 24000, 8192, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5713. case "raw-48khz-16bit-mono-pcm":
  5714. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 48000, 96000, 2, 16, speechSynthesisOutputFormatString, "raw-48khz-16bit-mono-pcm", false);
  5715. case "riff-48khz-16bit-mono-pcm":
  5716. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 48000, 96000, 2, 16, speechSynthesisOutputFormatString, "raw-48khz-16bit-mono-pcm", true);
  5717. case "audio-48khz-96kbitrate-mono-mp3":
  5718. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MP3, 1, 48000, 96 << 7, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5719. case "audio-48khz-192kbitrate-mono-mp3":
  5720. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.MP3, 1, 48000, 192 << 7, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5721. case "ogg-48khz-16bit-mono-opus":
  5722. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.OGG_OPUS, 1, 48000, 12000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5723. case "webm-16khz-16bit-mono-opus":
  5724. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.WEBM_OPUS, 1, 16000, 4000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5725. case "webm-24khz-16bit-mono-opus":
  5726. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.WEBM_OPUS, 1, 24000, 6000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5727. case "webm-24khz-16bit-24kbps-mono-opus":
  5728. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.WEBM_OPUS, 1, 24000, 3000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5729. case "audio-16khz-16bit-32kbps-mono-opus":
  5730. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.OPUS, 1, 16000, 4000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5731. case "audio-24khz-16bit-48kbps-mono-opus":
  5732. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.OPUS, 1, 24000, 6000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5733. case "audio-24khz-16bit-24kbps-mono-opus":
  5734. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.OPUS, 1, 24000, 3000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5735. case "audio-24khz-16bit-mono-flac":
  5736. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.FLAC, 1, 24000, 24000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5737. case "audio-48khz-16bit-mono-flac":
  5738. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.FLAC, 1, 48000, 30000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5739. case "raw-24khz-16bit-mono-truesilk":
  5740. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.SILKSkype, 1, 24000, 48000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5741. case "raw-8khz-8bit-mono-alaw":
  5742. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.ALaw, 1, 8000, 8000, 1, 8, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5743. case "riff-8khz-8bit-mono-alaw":
  5744. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.ALaw, 1, 8000, 8000, 1, 8, speechSynthesisOutputFormatString, "raw-8khz-8bit-mono-alaw", true);
  5745. case "raw-22050hz-16bit-mono-pcm":
  5746. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 22050, 44100, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5747. case "riff-22050hz-16bit-mono-pcm":
  5748. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 22050, 44100, 2, 16, speechSynthesisOutputFormatString, "raw-22050hz-16bit-mono-pcm", true);
  5749. case "raw-44100hz-16bit-mono-pcm":
  5750. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 44100, 88200, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5751. case "riff-44100hz-16bit-mono-pcm":
  5752. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 44100, 88200, 2, 16, speechSynthesisOutputFormatString, "raw-44100hz-16bit-mono-pcm", true);
  5753. case "amr-wb-16000h":
  5754. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.AMR_WB, 1, 16000, 3052, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5755. case "g722-16khz-64kbps":
  5756. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.G722, 1, 16000, 8000, 2, 16, speechSynthesisOutputFormatString, speechSynthesisOutputFormatString, false);
  5757. case "riff-16khz-16bit-mono-pcm":
  5758. default:
  5759. return new AudioOutputFormatImpl(AudioStreamFormat_js_1.AudioFormatTag.PCM, 1, 16000, 32000, 2, 16, "riff-16khz-16bit-mono-pcm", "raw-16khz-16bit-mono-pcm", true);
  5760. }
  5761. }
  5762. static getDefaultOutputFormat() {
  5763. return AudioOutputFormatImpl.fromSpeechSynthesisOutputFormatString((typeof window !== "undefined") ? "audio-24khz-48kbitrate-mono-mp3" : "riff-16khz-16bit-mono-pcm");
  5764. }
  5765. /**
  5766. * Specifies if this audio output format has a header
  5767. * @boolean AudioOutputFormatImpl.prototype.hasHeader
  5768. * @function
  5769. * @public
  5770. */
  5771. get hasHeader() {
  5772. return this.priHasHeader;
  5773. }
  5774. /**
  5775. * Specifies the header of this format
  5776. * @ArrayBuffer AudioOutputFormatImpl.prototype.header
  5777. * @function
  5778. * @public
  5779. */
  5780. get header() {
  5781. if (this.hasHeader) {
  5782. return this.privHeader;
  5783. }
  5784. return undefined;
  5785. }
  5786. /**
  5787. * Updates the header based on the audio length
  5788. * @member AudioOutputFormatImpl.updateHeader
  5789. * @function
  5790. * @public
  5791. * @param {number} audioLength - the audio length
  5792. */
  5793. updateHeader(audioLength) {
  5794. if (this.priHasHeader) {
  5795. const view = new DataView(this.privHeader);
  5796. view.setUint32(4, audioLength + this.privHeader.byteLength - 8, true);
  5797. view.setUint32(40, audioLength, true);
  5798. }
  5799. }
  5800. /**
  5801. * Specifies the audio format string to be sent to the service
  5802. * @string AudioOutputFormatImpl.prototype.requestAudioFormatString
  5803. * @function
  5804. * @public
  5805. */
  5806. get requestAudioFormatString() {
  5807. return this.priRequestAudioFormatString;
  5808. }
  5809. /**
  5810. * Adds audio header
  5811. * @param audio the raw audio without header
  5812. * @returns the audio with header if applicable
  5813. */
  5814. addHeader(audio) {
  5815. if (!this.hasHeader) {
  5816. return audio;
  5817. }
  5818. this.updateHeader(audio.byteLength);
  5819. const tmp = new Uint8Array(audio.byteLength + this.header.byteLength);
  5820. tmp.set(new Uint8Array(this.header), 0);
  5821. tmp.set(new Uint8Array(audio), this.header.byteLength);
  5822. return tmp.buffer;
  5823. }
  5824. }
  5825. exports.AudioOutputFormatImpl = AudioOutputFormatImpl;
  5826. AudioOutputFormatImpl.SpeechSynthesisOutputFormatToString = {
  5827. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw8Khz8BitMonoMULaw]: "raw-8khz-8bit-mono-mulaw",
  5828. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Riff16Khz16KbpsMonoSiren]: "riff-16khz-16kbps-mono-siren",
  5829. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio16Khz16KbpsMonoSiren]: "audio-16khz-16kbps-mono-siren",
  5830. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3]: "audio-16khz-32kbitrate-mono-mp3",
  5831. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio16Khz128KBitRateMonoMp3]: "audio-16khz-128kbitrate-mono-mp3",
  5832. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio16Khz64KBitRateMonoMp3]: "audio-16khz-64kbitrate-mono-mp3",
  5833. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio24Khz48KBitRateMonoMp3]: "audio-24khz-48kbitrate-mono-mp3",
  5834. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio24Khz96KBitRateMonoMp3]: "audio-24khz-96kbitrate-mono-mp3",
  5835. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio24Khz160KBitRateMonoMp3]: "audio-24khz-160kbitrate-mono-mp3",
  5836. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw16Khz16BitMonoTrueSilk]: "raw-16khz-16bit-mono-truesilk",
  5837. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Riff16Khz16BitMonoPcm]: "riff-16khz-16bit-mono-pcm",
  5838. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Riff8Khz16BitMonoPcm]: "riff-8khz-16bit-mono-pcm",
  5839. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Riff24Khz16BitMonoPcm]: "riff-24khz-16bit-mono-pcm",
  5840. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Riff8Khz8BitMonoMULaw]: "riff-8khz-8bit-mono-mulaw",
  5841. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw16Khz16BitMonoPcm]: "raw-16khz-16bit-mono-pcm",
  5842. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw24Khz16BitMonoPcm]: "raw-24khz-16bit-mono-pcm",
  5843. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw8Khz16BitMonoPcm]: "raw-8khz-16bit-mono-pcm",
  5844. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Ogg16Khz16BitMonoOpus]: "ogg-16khz-16bit-mono-opus",
  5845. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Ogg24Khz16BitMonoOpus]: "ogg-24khz-16bit-mono-opus",
  5846. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw48Khz16BitMonoPcm]: "raw-48khz-16bit-mono-pcm",
  5847. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Riff48Khz16BitMonoPcm]: "riff-48khz-16bit-mono-pcm",
  5848. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio48Khz96KBitRateMonoMp3]: "audio-48khz-96kbitrate-mono-mp3",
  5849. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio48Khz192KBitRateMonoMp3]: "audio-48khz-192kbitrate-mono-mp3",
  5850. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Ogg48Khz16BitMonoOpus]: "ogg-48khz-16bit-mono-opus",
  5851. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Webm16Khz16BitMonoOpus]: "webm-16khz-16bit-mono-opus",
  5852. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Webm24Khz16BitMonoOpus]: "webm-24khz-16bit-mono-opus",
  5853. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Webm24Khz16Bit24KbpsMonoOpus]: "webm-24khz-16bit-24kbps-mono-opus",
  5854. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw24Khz16BitMonoTrueSilk]: "raw-24khz-16bit-mono-truesilk",
  5855. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw8Khz8BitMonoALaw]: "raw-8khz-8bit-mono-alaw",
  5856. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Riff8Khz8BitMonoALaw]: "riff-8khz-8bit-mono-alaw",
  5857. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio16Khz16Bit32KbpsMonoOpus]: "audio-16khz-16bit-32kbps-mono-opus",
  5858. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio24Khz16Bit48KbpsMonoOpus]: "audio-24khz-16bit-48kbps-mono-opus",
  5859. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Audio24Khz16Bit24KbpsMonoOpus]: "audio-24khz-16bit-24kbps-mono-opus",
  5860. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw22050Hz16BitMonoPcm]: "raw-22050hz-16bit-mono-pcm",
  5861. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Riff22050Hz16BitMonoPcm]: "riff-22050hz-16bit-mono-pcm",
  5862. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Raw44100Hz16BitMonoPcm]: "raw-44100hz-16bit-mono-pcm",
  5863. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.Riff44100Hz16BitMonoPcm]: "riff-44100hz-16bit-mono-pcm",
  5864. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.AmrWb16000Hz]: "amr-wb-16000hz",
  5865. [SpeechSynthesisOutputFormat_js_1.SpeechSynthesisOutputFormat.G72216Khz64Kbps]: "g722-16khz-64kbps",
  5866. };
  5867. /***/ }),
  5868. /* 86 */
  5869. /***/ ((__unused_webpack_module, exports) => {
  5870. "use strict";
  5871. // Copyright (c) Microsoft Corporation. All rights reserved.
  5872. // Licensed under the MIT license.
  5873. Object.defineProperty(exports, "__esModule", ({ value: true }));
  5874. exports.SpeechSynthesisOutputFormat = void 0;
  5875. /**
  5876. * Define speech synthesis audio output formats.
  5877. * @enum SpeechSynthesisOutputFormat
  5878. * Updated in version 1.17.0
  5879. */
  5880. var SpeechSynthesisOutputFormat;
  5881. (function (SpeechSynthesisOutputFormat) {
  5882. /**
  5883. * raw-8khz-8bit-mono-mulaw
  5884. * @member SpeechSynthesisOutputFormat.Raw8Khz8BitMonoMULaw,
  5885. */
  5886. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw8Khz8BitMonoMULaw"] = 0] = "Raw8Khz8BitMonoMULaw";
  5887. /**
  5888. * riff-16khz-16kbps-mono-siren
  5889. * @note Unsupported by the service. Do not use this value.
  5890. * @member SpeechSynthesisOutputFormat.Riff16Khz16KbpsMonoSiren
  5891. */
  5892. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Riff16Khz16KbpsMonoSiren"] = 1] = "Riff16Khz16KbpsMonoSiren";
  5893. /**
  5894. * audio-16khz-16kbps-mono-siren
  5895. * @note Unsupported by the service. Do not use this value.
  5896. * @member SpeechSynthesisOutputFormat.Audio16Khz16KbpsMonoSiren
  5897. */
  5898. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio16Khz16KbpsMonoSiren"] = 2] = "Audio16Khz16KbpsMonoSiren";
  5899. /**
  5900. * audio-16khz-32kbitrate-mono-mp3
  5901. * @member SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3
  5902. */
  5903. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio16Khz32KBitRateMonoMp3"] = 3] = "Audio16Khz32KBitRateMonoMp3";
  5904. /**
  5905. * audio-16khz-128kbitrate-mono-mp3
  5906. * @member SpeechSynthesisOutputFormat.Audio16Khz128KBitRateMonoMp3
  5907. */
  5908. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio16Khz128KBitRateMonoMp3"] = 4] = "Audio16Khz128KBitRateMonoMp3";
  5909. /**
  5910. * audio-16khz-64kbitrate-mono-mp3
  5911. * @member SpeechSynthesisOutputFormat.Audio16Khz64KBitRateMonoMp3
  5912. */
  5913. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio16Khz64KBitRateMonoMp3"] = 5] = "Audio16Khz64KBitRateMonoMp3";
  5914. /**
  5915. * audio-24khz-48kbitrate-mono-mp3
  5916. * @member SpeechSynthesisOutputFormat.Audio24Khz48KBitRateMonoMp3
  5917. */
  5918. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio24Khz48KBitRateMonoMp3"] = 6] = "Audio24Khz48KBitRateMonoMp3";
  5919. /**
  5920. * audio-24khz-96kbitrate-mono-mp3
  5921. * @member SpeechSynthesisOutputFormat.Audio24Khz96KBitRateMonoMp3
  5922. */
  5923. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio24Khz96KBitRateMonoMp3"] = 7] = "Audio24Khz96KBitRateMonoMp3";
  5924. /**
  5925. * audio-24khz-160kbitrate-mono-mp3
  5926. * @member SpeechSynthesisOutputFormat.Audio24Khz160KBitRateMonoMp3
  5927. */
  5928. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio24Khz160KBitRateMonoMp3"] = 8] = "Audio24Khz160KBitRateMonoMp3";
  5929. /**
  5930. * raw-16khz-16bit-mono-truesilk
  5931. * @member SpeechSynthesisOutputFormat.Raw16Khz16BitMonoTrueSilk
  5932. */
  5933. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw16Khz16BitMonoTrueSilk"] = 9] = "Raw16Khz16BitMonoTrueSilk";
  5934. /**
  5935. * riff-16khz-16bit-mono-pcm
  5936. * @member SpeechSynthesisOutputFormat.Riff16Khz16BitMonoPcm
  5937. */
  5938. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Riff16Khz16BitMonoPcm"] = 10] = "Riff16Khz16BitMonoPcm";
  5939. /**
  5940. * riff-8khz-16bit-mono-pcm
  5941. * @member SpeechSynthesisOutputFormat.Riff8Khz16BitMonoPcm
  5942. */
  5943. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Riff8Khz16BitMonoPcm"] = 11] = "Riff8Khz16BitMonoPcm";
  5944. /**
  5945. * riff-24khz-16bit-mono-pcm
  5946. * @member SpeechSynthesisOutputFormat.Riff24Khz16BitMonoPcm
  5947. */
  5948. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Riff24Khz16BitMonoPcm"] = 12] = "Riff24Khz16BitMonoPcm";
  5949. /**
  5950. * riff-8khz-8bit-mono-mulaw
  5951. * @member SpeechSynthesisOutputFormat.Riff8Khz8BitMonoMULaw
  5952. */
  5953. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Riff8Khz8BitMonoMULaw"] = 13] = "Riff8Khz8BitMonoMULaw";
  5954. /**
  5955. * raw-16khz-16bit-mono-pcm
  5956. * @member SpeechSynthesisOutputFormat.Raw16Khz16BitMonoPcm
  5957. */
  5958. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw16Khz16BitMonoPcm"] = 14] = "Raw16Khz16BitMonoPcm";
  5959. /**
  5960. * raw-24khz-16bit-mono-pcm
  5961. * @member SpeechSynthesisOutputFormat.Raw24Khz16BitMonoPcm
  5962. */
  5963. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw24Khz16BitMonoPcm"] = 15] = "Raw24Khz16BitMonoPcm";
  5964. /**
  5965. * raw-8khz-16bit-mono-pcm
  5966. * @member SpeechSynthesisOutputFormat.Raw8Khz16BitMonoPcm
  5967. */
  5968. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw8Khz16BitMonoPcm"] = 16] = "Raw8Khz16BitMonoPcm";
  5969. /**
  5970. * ogg-16khz-16bit-mono-opus
  5971. * @member SpeechSynthesisOutputFormat.Ogg16Khz16BitMonoOpus
  5972. */
  5973. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Ogg16Khz16BitMonoOpus"] = 17] = "Ogg16Khz16BitMonoOpus";
  5974. /**
  5975. * ogg-24khz-16bit-mono-opus
  5976. * @member SpeechSynthesisOutputFormat.Ogg24Khz16BitMonoOpus
  5977. */
  5978. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Ogg24Khz16BitMonoOpus"] = 18] = "Ogg24Khz16BitMonoOpus";
  5979. /**
  5980. * raw-48khz-16bit-mono-pcm
  5981. * @member SpeechSynthesisOutputFormat.Raw48Khz16BitMonoPcm
  5982. */
  5983. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw48Khz16BitMonoPcm"] = 19] = "Raw48Khz16BitMonoPcm";
  5984. /**
  5985. * riff-48khz-16bit-mono-pcm
  5986. * @member SpeechSynthesisOutputFormat.Riff48Khz16BitMonoPcm
  5987. */
  5988. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Riff48Khz16BitMonoPcm"] = 20] = "Riff48Khz16BitMonoPcm";
  5989. /**
  5990. * audio-48khz-96kbitrate-mono-mp3
  5991. * @member SpeechSynthesisOutputFormat.Audio48Khz96KBitRateMonoMp3
  5992. */
  5993. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio48Khz96KBitRateMonoMp3"] = 21] = "Audio48Khz96KBitRateMonoMp3";
  5994. /**
  5995. * audio-48khz-192kbitrate-mono-mp3
  5996. * @member SpeechSynthesisOutputFormat.Audio48Khz192KBitRateMonoMp3
  5997. */
  5998. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio48Khz192KBitRateMonoMp3"] = 22] = "Audio48Khz192KBitRateMonoMp3";
  5999. /**
  6000. * ogg-48khz-16bit-mono-opus
  6001. * Added in version 1.16.0
  6002. * @member SpeechSynthesisOutputFormat.Ogg48Khz16BitMonoOpus
  6003. */
  6004. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Ogg48Khz16BitMonoOpus"] = 23] = "Ogg48Khz16BitMonoOpus";
  6005. /**
  6006. * webm-16khz-16bit-mono-opus
  6007. * Added in version 1.16.0
  6008. * @member SpeechSynthesisOutputFormat.Webm16Khz16BitMonoOpus
  6009. */
  6010. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Webm16Khz16BitMonoOpus"] = 24] = "Webm16Khz16BitMonoOpus";
  6011. /**
  6012. * webm-24khz-16bit-mono-opus
  6013. * Added in version 1.16.0
  6014. * @member SpeechSynthesisOutputFormat.Webm24Khz16BitMonoOpus
  6015. */
  6016. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Webm24Khz16BitMonoOpus"] = 25] = "Webm24Khz16BitMonoOpus";
  6017. /**
  6018. * raw-24khz-16bit-mono-truesilk
  6019. * Added in version 1.17.0
  6020. * @member SpeechSynthesisOutputFormat.Raw24Khz16BitMonoTrueSilk
  6021. */
  6022. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw24Khz16BitMonoTrueSilk"] = 26] = "Raw24Khz16BitMonoTrueSilk";
  6023. /**
  6024. * raw-8khz-8bit-mono-alaw
  6025. * Added in version 1.17.0
  6026. * @member SpeechSynthesisOutputFormat.Raw8Khz8BitMonoALaw
  6027. */
  6028. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw8Khz8BitMonoALaw"] = 27] = "Raw8Khz8BitMonoALaw";
  6029. /**
  6030. * riff-8khz-8bit-mono-alaw
  6031. * Added in version 1.17.0
  6032. * @member SpeechSynthesisOutputFormat.Riff8Khz8BitMonoALaw
  6033. */
  6034. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Riff8Khz8BitMonoALaw"] = 28] = "Riff8Khz8BitMonoALaw";
  6035. /**
  6036. * webm-24khz-16bit-24kbps-mono-opus
  6037. * Audio compressed by OPUS codec in a webm container, with bitrate of 24kbps, optimized for IoT scenario.
  6038. * Added in version 1.19.0
  6039. * @member SpeechSynthesisOutputFormat.Webm24Khz16Bit24KbpsMonoOpus
  6040. */
  6041. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Webm24Khz16Bit24KbpsMonoOpus"] = 29] = "Webm24Khz16Bit24KbpsMonoOpus";
  6042. /**
  6043. * audio-16khz-16bit-32kbps-mono-opus
  6044. * Audio compressed by OPUS codec without container, with bitrate of 32kbps.
  6045. * Added in version 1.20.0
  6046. * @member SpeechSynthesisOutputFormat.Audio16Khz16Bit32KbpsMonoOpus
  6047. */
  6048. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio16Khz16Bit32KbpsMonoOpus"] = 30] = "Audio16Khz16Bit32KbpsMonoOpus";
  6049. /**
  6050. * audio-24khz-16bit-48kbps-mono-opus
  6051. * Audio compressed by OPUS codec without container, with bitrate of 48kbps.
  6052. * Added in version 1.20.0
  6053. * @member SpeechSynthesisOutputFormat.Audio24Khz16Bit48KbpsMonoOpus
  6054. */
  6055. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio24Khz16Bit48KbpsMonoOpus"] = 31] = "Audio24Khz16Bit48KbpsMonoOpus";
  6056. /**
  6057. * audio-24khz-16bit-24kbps-mono-opus
  6058. * Audio compressed by OPUS codec without container, with bitrate of 24kbps.
  6059. * Added in version 1.20.0
  6060. * @member SpeechSynthesisOutputFormat.Audio24Khz16Bit24KbpsMonoOpus
  6061. */
  6062. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Audio24Khz16Bit24KbpsMonoOpus"] = 32] = "Audio24Khz16Bit24KbpsMonoOpus";
  6063. /**
  6064. * raw-22050hz-16bit-mono-pcm
  6065. * Raw PCM audio at 22050Hz sampling rate and 16-bit depth.
  6066. * Added in version 1.22.0
  6067. * @member SpeechSynthesisOutputFormat.Raw22050Hz16BitMonoPcm
  6068. */
  6069. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw22050Hz16BitMonoPcm"] = 33] = "Raw22050Hz16BitMonoPcm";
  6070. /**
  6071. * riff-22050hz-16bit-mono-pcm
  6072. * PCM audio at 22050Hz sampling rate and 16-bit depth, with RIFF header.
  6073. * Added in version 1.22.0
  6074. * @member SpeechSynthesisOutputFormat.Riff22050Hz16BitMonoPcm
  6075. */
  6076. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Riff22050Hz16BitMonoPcm"] = 34] = "Riff22050Hz16BitMonoPcm";
  6077. /**
  6078. * raw-44100hz-16bit-mono-pcm
  6079. * Raw PCM audio at 44100Hz sampling rate and 16-bit depth.
  6080. * Added in version 1.22.0
  6081. * @member SpeechSynthesisOutputFormat.Raw44100Hz16BitMonoPcm
  6082. */
  6083. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Raw44100Hz16BitMonoPcm"] = 35] = "Raw44100Hz16BitMonoPcm";
  6084. /**
  6085. * riff-44100hz-16bit-mono-pcm
  6086. * PCM audio at 44100Hz sampling rate and 16-bit depth, with RIFF header.
  6087. * Added in version 1.22.0
  6088. * @member SpeechSynthesisOutputFormat.Riff44100Hz16BitMonoPcm
  6089. */
  6090. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["Riff44100Hz16BitMonoPcm"] = 36] = "Riff44100Hz16BitMonoPcm";
  6091. /**
  6092. * amr-wb-16000hz
  6093. * AMR-WB audio at 16kHz sampling rate.
  6094. * Added in version 1.38.0
  6095. * @member SpeechSynthesisOutputFormat.AmrWb16000Hz
  6096. */
  6097. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["AmrWb16000Hz"] = 37] = "AmrWb16000Hz";
  6098. /**
  6099. * g722-16khz-64kbps
  6100. * G.722 audio at 16kHz sampling rate and 64kbps bitrate.
  6101. * Added in version 1.38.0
  6102. */
  6103. SpeechSynthesisOutputFormat[SpeechSynthesisOutputFormat["G72216Khz64Kbps"] = 38] = "G72216Khz64Kbps";
  6104. })(SpeechSynthesisOutputFormat = exports.SpeechSynthesisOutputFormat || (exports.SpeechSynthesisOutputFormat = {}));
  6105. /***/ }),
  6106. /* 87 */
  6107. /***/ ((__unused_webpack_module, exports) => {
  6108. "use strict";
  6109. // Copyright (c) Microsoft Corporation. All rights reserved.
  6110. // Licensed under the MIT license.
  6111. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6112. exports.CancellationReason = void 0;
  6113. /**
  6114. * Defines the possible reasons a recognition result might be canceled.
  6115. * @class CancellationReason
  6116. */
  6117. var CancellationReason;
  6118. (function (CancellationReason) {
  6119. /**
  6120. * Indicates that an error occurred during speech recognition.
  6121. * @member CancellationReason.Error
  6122. */
  6123. CancellationReason[CancellationReason["Error"] = 0] = "Error";
  6124. /**
  6125. * Indicates that the end of the audio stream was reached.
  6126. * @member CancellationReason.EndOfStream
  6127. */
  6128. CancellationReason[CancellationReason["EndOfStream"] = 1] = "EndOfStream";
  6129. })(CancellationReason = exports.CancellationReason || (exports.CancellationReason = {}));
  6130. /***/ }),
  6131. /* 88 */
  6132. /***/ ((__unused_webpack_module, exports) => {
  6133. "use strict";
  6134. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6135. exports.PullAudioInputStreamCallback = void 0;
  6136. // Copyright (c) Microsoft Corporation. All rights reserved.
  6137. // Licensed under the MIT license.
  6138. /**
  6139. * An abstract base class that defines callback methods (read() and close()) for
  6140. * custom audio input streams).
  6141. * @class PullAudioInputStreamCallback
  6142. */
  6143. class PullAudioInputStreamCallback {
  6144. }
  6145. exports.PullAudioInputStreamCallback = PullAudioInputStreamCallback;
  6146. /***/ }),
  6147. /* 89 */
  6148. /***/ ((__unused_webpack_module, exports) => {
  6149. "use strict";
  6150. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6151. exports.PushAudioOutputStreamCallback = void 0;
  6152. // Copyright (c) Microsoft Corporation. All rights reserved.
  6153. // Licensed under the MIT license.
  6154. /**
  6155. * An abstract base class that defines callback methods (write() and close()) for
  6156. * custom audio output streams).
  6157. * @class PushAudioOutputStreamCallback
  6158. */
  6159. class PushAudioOutputStreamCallback {
  6160. }
  6161. exports.PushAudioOutputStreamCallback = PushAudioOutputStreamCallback;
  6162. /***/ }),
  6163. /* 90 */
  6164. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6165. "use strict";
  6166. // Copyright (c) Microsoft Corporation. All rights reserved.
  6167. // Licensed under the MIT license.
  6168. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6169. exports.KeywordRecognitionModel = void 0;
  6170. const Contracts_js_1 = __webpack_require__(64);
  6171. /**
  6172. * Represents a keyword recognition model for recognizing when
  6173. * the user says a keyword to initiate further speech recognition.
  6174. * @class KeywordRecognitionModel
  6175. */
  6176. class KeywordRecognitionModel {
  6177. /**
  6178. * Create and initializes a new instance.
  6179. * @constructor
  6180. */
  6181. constructor() {
  6182. this.privDisposed = false;
  6183. return;
  6184. }
  6185. /**
  6186. * Creates a keyword recognition model using the specified filename.
  6187. * @member KeywordRecognitionModel.fromFile
  6188. * @function
  6189. * @public
  6190. * @param {string} fileName - A string that represents file name for the keyword recognition model.
  6191. * Note, the file can point to a zip file in which case the model
  6192. * will be extracted from the zip.
  6193. * @returns {KeywordRecognitionModel} The keyword recognition model being created.
  6194. */
  6195. static fromFile(fileName) {
  6196. Contracts_js_1.Contracts.throwIfFileDoesNotExist(fileName, "fileName");
  6197. throw new Error("Not yet implemented.");
  6198. }
  6199. /**
  6200. * Creates a keyword recognition model using the specified filename.
  6201. * @member KeywordRecognitionModel.fromStream
  6202. * @function
  6203. * @public
  6204. * @param {string} file - A File that represents file for the keyword recognition model.
  6205. * Note, the file can point to a zip file in which case the model will be extracted from the zip.
  6206. * @returns {KeywordRecognitionModel} The keyword recognition model being created.
  6207. */
  6208. static fromStream(file) {
  6209. Contracts_js_1.Contracts.throwIfNull(file, "file");
  6210. throw new Error("Not yet implemented.");
  6211. }
  6212. /**
  6213. * Dispose of associated resources.
  6214. * @member KeywordRecognitionModel.prototype.close
  6215. * @function
  6216. * @public
  6217. */
  6218. close() {
  6219. if (this.privDisposed) {
  6220. return;
  6221. }
  6222. this.privDisposed = true;
  6223. }
  6224. }
  6225. exports.KeywordRecognitionModel = KeywordRecognitionModel;
  6226. /***/ }),
  6227. /* 91 */
  6228. /***/ ((__unused_webpack_module, exports) => {
  6229. "use strict";
  6230. // Copyright (c) Microsoft Corporation. All rights reserved.
  6231. // Licensed under the MIT license.
  6232. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6233. exports.SessionEventArgs = void 0;
  6234. /**
  6235. * Defines content for session events like SessionStarted/Stopped, SoundStarted/Stopped.
  6236. * @class SessionEventArgs
  6237. */
  6238. class SessionEventArgs {
  6239. /**
  6240. * Creates and initializes an instance of this class.
  6241. * @constructor
  6242. * @param {string} sessionId - The session id.
  6243. */
  6244. constructor(sessionId) {
  6245. this.privSessionId = sessionId;
  6246. }
  6247. /**
  6248. * Represents the session identifier.
  6249. * @member SessionEventArgs.prototype.sessionId
  6250. * @function
  6251. * @public
  6252. * @returns {string} Represents the session identifier.
  6253. */
  6254. get sessionId() {
  6255. return this.privSessionId;
  6256. }
  6257. }
  6258. exports.SessionEventArgs = SessionEventArgs;
  6259. /***/ }),
  6260. /* 92 */
  6261. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6262. "use strict";
  6263. // Copyright (c) Microsoft Corporation. All rights reserved.
  6264. // Licensed under the MIT license.
  6265. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6266. exports.RecognitionEventArgs = void 0;
  6267. const Exports_js_1 = __webpack_require__(79);
  6268. /**
  6269. * Defines payload for session events like Speech Start/End Detected
  6270. * @class
  6271. */
  6272. class RecognitionEventArgs extends Exports_js_1.SessionEventArgs {
  6273. /**
  6274. * Creates and initializes an instance of this class.
  6275. * @constructor
  6276. * @param {number} offset - The offset.
  6277. * @param {string} sessionId - The session id.
  6278. */
  6279. constructor(offset, sessionId) {
  6280. super(sessionId);
  6281. this.privOffset = offset;
  6282. }
  6283. /**
  6284. * Represents the message offset
  6285. * @member RecognitionEventArgs.prototype.offset
  6286. * @function
  6287. * @public
  6288. */
  6289. get offset() {
  6290. return this.privOffset;
  6291. }
  6292. }
  6293. exports.RecognitionEventArgs = RecognitionEventArgs;
  6294. /***/ }),
  6295. /* 93 */
  6296. /***/ ((__unused_webpack_module, exports) => {
  6297. "use strict";
  6298. // Copyright (c) Microsoft Corporation. All rights reserved.
  6299. // Licensed under the MIT license.
  6300. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6301. exports.OutputFormat = void 0;
  6302. /**
  6303. * Define Speech Recognizer output formats.
  6304. * @class OutputFormat
  6305. */
  6306. var OutputFormat;
  6307. (function (OutputFormat) {
  6308. /**
  6309. * @member OutputFormat.Simple
  6310. */
  6311. OutputFormat[OutputFormat["Simple"] = 0] = "Simple";
  6312. /**
  6313. * @member OutputFormat.Detailed
  6314. */
  6315. OutputFormat[OutputFormat["Detailed"] = 1] = "Detailed";
  6316. })(OutputFormat = exports.OutputFormat || (exports.OutputFormat = {}));
  6317. /***/ }),
  6318. /* 94 */
  6319. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6320. "use strict";
  6321. // Copyright (c) Microsoft Corporation. All rights reserved.
  6322. // Licensed under the MIT license.
  6323. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6324. exports.IntentRecognitionEventArgs = void 0;
  6325. const Exports_js_1 = __webpack_require__(79);
  6326. /**
  6327. * Intent recognition result event arguments.
  6328. * @class
  6329. */
  6330. class IntentRecognitionEventArgs extends Exports_js_1.RecognitionEventArgs {
  6331. /**
  6332. * Creates and initializes an instance of this class.
  6333. * @constructor
  6334. * @param result - The result of the intent recognition.
  6335. * @param offset - The offset.
  6336. * @param sessionId - The session id.
  6337. */
  6338. constructor(result, offset, sessionId) {
  6339. super(offset, sessionId);
  6340. this.privResult = result;
  6341. }
  6342. /**
  6343. * Represents the intent recognition result.
  6344. * @member IntentRecognitionEventArgs.prototype.result
  6345. * @function
  6346. * @public
  6347. * @returns {IntentRecognitionResult} Represents the intent recognition result.
  6348. */
  6349. get result() {
  6350. return this.privResult;
  6351. }
  6352. }
  6353. exports.IntentRecognitionEventArgs = IntentRecognitionEventArgs;
  6354. /***/ }),
  6355. /* 95 */
  6356. /***/ ((__unused_webpack_module, exports) => {
  6357. "use strict";
  6358. // Copyright (c) Microsoft Corporation. All rights reserved.
  6359. // Licensed under the MIT license.
  6360. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6361. exports.RecognitionResult = void 0;
  6362. /**
  6363. * Defines result of speech recognition.
  6364. * @class RecognitionResult
  6365. */
  6366. class RecognitionResult {
  6367. /**
  6368. * Creates and initializes an instance of this class.
  6369. * @constructor
  6370. * @param {string} resultId - The result id.
  6371. * @param {ResultReason} reason - The reason.
  6372. * @param {string} text - The recognized text.
  6373. * @param {number} duration - The duration.
  6374. * @param {number} offset - The offset into the stream.
  6375. * @param {string} language - Primary Language detected, if provided.
  6376. * @param {string} languageDetectionConfidence - Primary Language confidence ("Unknown," "Low," "Medium," "High"...), if provided.
  6377. * @param {string} errorDetails - Error details, if provided.
  6378. * @param {string} json - Additional Json, if provided.
  6379. * @param {PropertyCollection} properties - Additional properties, if provided.
  6380. */
  6381. constructor(resultId, reason, text, duration, offset, language, languageDetectionConfidence, errorDetails, json, properties) {
  6382. this.privResultId = resultId;
  6383. this.privReason = reason;
  6384. this.privText = text;
  6385. this.privDuration = duration;
  6386. this.privOffset = offset;
  6387. this.privLanguage = language;
  6388. this.privLanguageDetectionConfidence = languageDetectionConfidence;
  6389. this.privErrorDetails = errorDetails;
  6390. this.privJson = json;
  6391. this.privProperties = properties;
  6392. }
  6393. /**
  6394. * Specifies the result identifier.
  6395. * @member RecognitionResult.prototype.resultId
  6396. * @function
  6397. * @public
  6398. * @returns {string} Specifies the result identifier.
  6399. */
  6400. get resultId() {
  6401. return this.privResultId;
  6402. }
  6403. /**
  6404. * Specifies status of the result.
  6405. * @member RecognitionResult.prototype.reason
  6406. * @function
  6407. * @public
  6408. * @returns {ResultReason} Specifies status of the result.
  6409. */
  6410. get reason() {
  6411. return this.privReason;
  6412. }
  6413. /**
  6414. * Presents the recognized text in the result.
  6415. * @member RecognitionResult.prototype.text
  6416. * @function
  6417. * @public
  6418. * @returns {string} Presents the recognized text in the result.
  6419. */
  6420. get text() {
  6421. return this.privText;
  6422. }
  6423. /**
  6424. * Duration of recognized speech in 100 nano second increments.
  6425. * @member RecognitionResult.prototype.duration
  6426. * @function
  6427. * @public
  6428. * @returns {number} Duration of recognized speech in 100 nano second increments.
  6429. */
  6430. get duration() {
  6431. return this.privDuration;
  6432. }
  6433. /**
  6434. * Offset of recognized speech in 100 nano second increments.
  6435. * @member RecognitionResult.prototype.offset
  6436. * @function
  6437. * @public
  6438. * @returns {number} Offset of recognized speech in 100 nano second increments.
  6439. */
  6440. get offset() {
  6441. return this.privOffset;
  6442. }
  6443. /**
  6444. * Primary Language detected.
  6445. * @member RecognitionResult.prototype.language
  6446. * @function
  6447. * @public
  6448. * @returns {string} language detected.
  6449. */
  6450. get language() {
  6451. return this.privLanguage;
  6452. }
  6453. /**
  6454. * Primary Language detection confidence (Unknown, Low, Medium, High).
  6455. * @member RecognitionResult.prototype.languageDetectionConfidence
  6456. * @function
  6457. * @public
  6458. * @returns {string} detection confidence strength.
  6459. */
  6460. get languageDetectionConfidence() {
  6461. return this.privLanguageDetectionConfidence;
  6462. }
  6463. /**
  6464. * In case of an unsuccessful recognition, provides details of the occurred error.
  6465. * @member RecognitionResult.prototype.errorDetails
  6466. * @function
  6467. * @public
  6468. * @returns {string} a brief description of an error.
  6469. */
  6470. get errorDetails() {
  6471. return this.privErrorDetails;
  6472. }
  6473. /**
  6474. * A string containing Json serialized recognition result as it was received from the service.
  6475. * @member RecognitionResult.prototype.json
  6476. * @function
  6477. * @private
  6478. * @returns {string} Json serialized representation of the result.
  6479. */
  6480. get json() {
  6481. return this.privJson;
  6482. }
  6483. /**
  6484. * The set of properties exposed in the result.
  6485. * @member RecognitionResult.prototype.properties
  6486. * @function
  6487. * @public
  6488. * @returns {PropertyCollection} The set of properties exposed in the result.
  6489. */
  6490. get properties() {
  6491. return this.privProperties;
  6492. }
  6493. }
  6494. exports.RecognitionResult = RecognitionResult;
  6495. /***/ }),
  6496. /* 96 */
  6497. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6498. "use strict";
  6499. // Copyright (c) Microsoft Corporation. All rights reserved.
  6500. // Licensed under the MIT license.
  6501. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6502. exports.SpeechRecognitionResult = void 0;
  6503. const Exports_js_1 = __webpack_require__(79);
  6504. /**
  6505. * Defines result of speech recognition.
  6506. * @class SpeechRecognitionResult
  6507. */
  6508. class SpeechRecognitionResult extends Exports_js_1.RecognitionResult {
  6509. /**
  6510. * Creates and initializes an instance of this class.
  6511. * @constructor
  6512. * @public
  6513. * @param {string} resultId - The result id.
  6514. * @param {ResultReason} reason - The reason.
  6515. * @param {string} text - The recognized text.
  6516. * @param {number} duration - The duration.
  6517. * @param {number} offset - The offset into the stream.
  6518. * @param {string} language - Primary Language detected, if provided.
  6519. * @param {string} languageDetectionConfidence - Primary Language confidence ("Unknown," "Low," "Medium," "High"...), if provided.
  6520. * @param {string} speakerId - speaker id for conversation transcription, if provided.
  6521. * @param {string} errorDetails - Error details, if provided.
  6522. * @param {string} json - Additional Json, if provided.
  6523. * @param {PropertyCollection} properties - Additional properties, if provided.
  6524. */
  6525. constructor(resultId, reason, text, duration, offset, language, languageDetectionConfidence, speakerId, errorDetails, json, properties) {
  6526. super(resultId, reason, text, duration, offset, language, languageDetectionConfidence, errorDetails, json, properties);
  6527. this.privSpeakerId = speakerId;
  6528. }
  6529. /**
  6530. * speaker id from conversation transcription/id scenarios
  6531. * @member SpeechRecognitionResult.prototype.speakerId
  6532. * @function
  6533. * @public
  6534. * @returns {string} id of speaker in given result
  6535. */
  6536. get speakerId() {
  6537. return this.privSpeakerId;
  6538. }
  6539. }
  6540. exports.SpeechRecognitionResult = SpeechRecognitionResult;
  6541. /***/ }),
  6542. /* 97 */
  6543. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6544. "use strict";
  6545. // Copyright (c) Microsoft Corporation. All rights reserved.
  6546. // Licensed under the MIT license.
  6547. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6548. exports.IntentRecognitionResult = void 0;
  6549. const Exports_js_1 = __webpack_require__(79);
  6550. /**
  6551. * Intent recognition result.
  6552. * @class
  6553. */
  6554. class IntentRecognitionResult extends Exports_js_1.SpeechRecognitionResult {
  6555. /**
  6556. * Creates and initializes an instance of this class.
  6557. * @constructor
  6558. * @param intentId - The intent id.
  6559. * @param resultId - The result id.
  6560. * @param reason - The reason.
  6561. * @param text - The recognized text.
  6562. * @param duration - The duration.
  6563. * @param offset - The offset into the stream.
  6564. * @param language - Primary Language detected, if provided.
  6565. * @param languageDetectionConfidence - Primary Language confidence ("Unknown," "Low," "Medium," "High"...), if provided.
  6566. * @param errorDetails - Error details, if provided.
  6567. * @param json - Additional Json, if provided.
  6568. * @param properties - Additional properties, if provided.
  6569. */
  6570. constructor(intentId, resultId, reason, text, duration, offset, language, languageDetectionConfidence, errorDetails, json, properties) {
  6571. super(resultId, reason, text, duration, offset, language, languageDetectionConfidence, undefined, errorDetails, json, properties);
  6572. this.privIntentId = intentId;
  6573. }
  6574. /**
  6575. * A String that represents the intent identifier being recognized.
  6576. * @member IntentRecognitionResult.prototype.intentId
  6577. * @function
  6578. * @public
  6579. * @returns {string} A String that represents the intent identifier being recognized.
  6580. */
  6581. get intentId() {
  6582. return this.privIntentId;
  6583. }
  6584. }
  6585. exports.IntentRecognitionResult = IntentRecognitionResult;
  6586. /***/ }),
  6587. /* 98 */
  6588. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6589. "use strict";
  6590. // Copyright (c) Microsoft Corporation. All rights reserved.
  6591. // Licensed under the MIT license.
  6592. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6593. exports.LanguageUnderstandingModelImpl = exports.LanguageUnderstandingModel = void 0;
  6594. // eslint-disable-next-line max-classes-per-file
  6595. const Contracts_js_1 = __webpack_require__(64);
  6596. /**
  6597. * Language understanding model
  6598. * @class LanguageUnderstandingModel
  6599. */
  6600. class LanguageUnderstandingModel {
  6601. /**
  6602. * Creates and initializes a new instance
  6603. * @constructor
  6604. */
  6605. constructor() {
  6606. return;
  6607. }
  6608. /**
  6609. * Creates an language understanding model using the specified endpoint.
  6610. * @member LanguageUnderstandingModel.fromEndpoint
  6611. * @function
  6612. * @public
  6613. * @param {URL} uri - A String that represents the endpoint of the language understanding model.
  6614. * @returns {LanguageUnderstandingModel} The language understanding model being created.
  6615. */
  6616. static fromEndpoint(uri) {
  6617. Contracts_js_1.Contracts.throwIfNull(uri, "uri");
  6618. Contracts_js_1.Contracts.throwIfNullOrWhitespace(uri.hostname, "uri");
  6619. const langModelImp = new LanguageUnderstandingModelImpl();
  6620. // Need to extract the app ID from the URL.
  6621. // URL is in the format: https://<region>.api.cognitive.microsoft.com/luis/v2.0/apps/<Guid>?subscription-key=<key>&timezoneOffset=-360
  6622. // Start tearing the string apart.
  6623. // region can be extracted from the host name.
  6624. const firstDot = uri.host.indexOf(".");
  6625. if (-1 === firstDot) {
  6626. throw new Error("Could not determine region from endpoint");
  6627. }
  6628. langModelImp.region = uri.host.substr(0, firstDot);
  6629. // Now the app ID.
  6630. const lastSegment = uri.pathname.lastIndexOf("/") + 1;
  6631. if (-1 === lastSegment) {
  6632. throw new Error("Could not determine appId from endpoint");
  6633. }
  6634. langModelImp.appId = uri.pathname.substr(lastSegment);
  6635. // And finally the key.
  6636. langModelImp.subscriptionKey = uri.searchParams.get("subscription-key");
  6637. if (undefined === langModelImp.subscriptionKey) {
  6638. throw new Error("Could not determine subscription key from endpoint");
  6639. }
  6640. return langModelImp;
  6641. }
  6642. /**
  6643. * Creates an language understanding model using the application id of Language Understanding service.
  6644. * @member LanguageUnderstandingModel.fromAppId
  6645. * @function
  6646. * @public
  6647. * @param {string} appId - A String that represents the application id of Language Understanding service.
  6648. * @returns {LanguageUnderstandingModel} The language understanding model being created.
  6649. */
  6650. static fromAppId(appId) {
  6651. Contracts_js_1.Contracts.throwIfNullOrWhitespace(appId, "appId");
  6652. const langModelImp = new LanguageUnderstandingModelImpl();
  6653. langModelImp.appId = appId;
  6654. return langModelImp;
  6655. }
  6656. /**
  6657. * Creates a language understanding model using hostname, subscription key and application
  6658. * id of Language Understanding service.
  6659. * @member LanguageUnderstandingModel.fromSubscription
  6660. * @function
  6661. * @public
  6662. * @param {string} subscriptionKey - A String that represents the subscription key of
  6663. * Language Understanding service.
  6664. * @param {string} appId - A String that represents the application id of Language
  6665. * Understanding service.
  6666. * @param {LanguageUnderstandingModel} region - A String that represents the region
  6667. * of the Language Understanding service (see the <a href="https://aka.ms/csspeech/region">region page</a>).
  6668. * @returns {LanguageUnderstandingModel} The language understanding model being created.
  6669. */
  6670. static fromSubscription(subscriptionKey, appId, region) {
  6671. Contracts_js_1.Contracts.throwIfNullOrWhitespace(subscriptionKey, "subscriptionKey");
  6672. Contracts_js_1.Contracts.throwIfNullOrWhitespace(appId, "appId");
  6673. Contracts_js_1.Contracts.throwIfNullOrWhitespace(region, "region");
  6674. const langModelImp = new LanguageUnderstandingModelImpl();
  6675. langModelImp.appId = appId;
  6676. langModelImp.region = region;
  6677. langModelImp.subscriptionKey = subscriptionKey;
  6678. return langModelImp;
  6679. }
  6680. }
  6681. exports.LanguageUnderstandingModel = LanguageUnderstandingModel;
  6682. /**
  6683. * @private
  6684. * @class LanguageUnderstandingModelImpl
  6685. */
  6686. class LanguageUnderstandingModelImpl extends LanguageUnderstandingModel {
  6687. }
  6688. exports.LanguageUnderstandingModelImpl = LanguageUnderstandingModelImpl;
  6689. /***/ }),
  6690. /* 99 */
  6691. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6692. "use strict";
  6693. // Copyright (c) Microsoft Corporation. All rights reserved.
  6694. // Licensed under the MIT license.
  6695. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6696. exports.MeetingTranscriptionEventArgs = exports.ConversationTranscriptionEventArgs = exports.SpeechRecognitionEventArgs = void 0;
  6697. /* eslint-disable max-classes-per-file */
  6698. const Exports_js_1 = __webpack_require__(79);
  6699. /**
  6700. * Defines contents of speech recognizing/recognized event.
  6701. * @class SpeechRecognitionEventArgs
  6702. */
  6703. class SpeechRecognitionEventArgs extends Exports_js_1.RecognitionEventArgs {
  6704. /**
  6705. * Creates and initializes an instance of this class.
  6706. * @constructor
  6707. * @param {SpeechRecognitionResult} result - The speech recognition result.
  6708. * @param {number} offset - The offset.
  6709. * @param {string} sessionId - The session id.
  6710. */
  6711. constructor(result, offset, sessionId) {
  6712. super(offset, sessionId);
  6713. this.privResult = result;
  6714. }
  6715. /**
  6716. * Specifies the recognition result.
  6717. * @member SpeechRecognitionEventArgs.prototype.result
  6718. * @function
  6719. * @public
  6720. * @returns {SpeechRecognitionResult} the recognition result.
  6721. */
  6722. get result() {
  6723. return this.privResult;
  6724. }
  6725. }
  6726. exports.SpeechRecognitionEventArgs = SpeechRecognitionEventArgs;
  6727. /**
  6728. * Defines contents of conversation transcribed/transcribing event.
  6729. * @class ConversationTranscriptionEventArgs
  6730. */
  6731. class ConversationTranscriptionEventArgs extends Exports_js_1.RecognitionEventArgs {
  6732. /**
  6733. * Creates and initializes an instance of this class.
  6734. * @constructor
  6735. * @param {ConversationTranscriptionResult} result - The conversation transcription result.
  6736. * @param {number} offset - The offset.
  6737. * @param {string} sessionId - The session id.
  6738. */
  6739. constructor(result, offset, sessionId) {
  6740. super(offset, sessionId);
  6741. this.privResult = result;
  6742. }
  6743. /**
  6744. * Specifies the transcription result.
  6745. * @member ConversationTranscription1EventArgs.prototype.result
  6746. * @function
  6747. * @public
  6748. * @returns {ConversationTranscriptionResult} the recognition result.
  6749. */
  6750. get result() {
  6751. return this.privResult;
  6752. }
  6753. }
  6754. exports.ConversationTranscriptionEventArgs = ConversationTranscriptionEventArgs;
  6755. /**
  6756. * Defines contents of meeting transcribed/transcribing event.
  6757. * @class MeetingTranscriptionEventArgs
  6758. */
  6759. class MeetingTranscriptionEventArgs extends SpeechRecognitionEventArgs {
  6760. }
  6761. exports.MeetingTranscriptionEventArgs = MeetingTranscriptionEventArgs;
  6762. /***/ }),
  6763. /* 100 */
  6764. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6765. "use strict";
  6766. // Copyright (c) Microsoft Corporation. All rights reserved.
  6767. // Licensed under the MIT license.
  6768. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6769. exports.SpeechRecognitionCanceledEventArgs = void 0;
  6770. const CancellationEventArgsBase_js_1 = __webpack_require__(101);
  6771. class SpeechRecognitionCanceledEventArgs extends CancellationEventArgsBase_js_1.CancellationEventArgsBase {
  6772. }
  6773. exports.SpeechRecognitionCanceledEventArgs = SpeechRecognitionCanceledEventArgs;
  6774. /***/ }),
  6775. /* 101 */
  6776. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6777. "use strict";
  6778. // Copyright (c) Microsoft Corporation. All rights reserved.
  6779. // Licensed under the MIT license.
  6780. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6781. exports.CancellationEventArgsBase = void 0;
  6782. const Exports_js_1 = __webpack_require__(79);
  6783. /**
  6784. * Defines content of a CancellationEvent.
  6785. * @class CancellationEventArgsBase
  6786. */
  6787. class CancellationEventArgsBase extends Exports_js_1.RecognitionEventArgs {
  6788. /**
  6789. * Creates and initializes an instance of this class.
  6790. * @constructor
  6791. * @param {CancellationReason} reason - The cancellation reason.
  6792. * @param {string} errorDetails - Error details, if provided.
  6793. * @param {number} offset - The offset.
  6794. * @param {string} sessionId - The session id.
  6795. */
  6796. constructor(reason, errorDetails, errorCode, offset, sessionId) {
  6797. super(offset, sessionId);
  6798. this.privReason = reason;
  6799. this.privErrorDetails = errorDetails;
  6800. this.privErrorCode = errorCode;
  6801. }
  6802. /**
  6803. * The reason the recognition was canceled.
  6804. * @member CancellationEventArgsBase.prototype.reason
  6805. * @function
  6806. * @public
  6807. * @returns {CancellationReason} Specifies the reason canceled.
  6808. */
  6809. get reason() {
  6810. return this.privReason;
  6811. }
  6812. /**
  6813. * The error code in case of an unsuccessful operation.
  6814. * @return An error code that represents the error reason.
  6815. */
  6816. get errorCode() {
  6817. return this.privErrorCode;
  6818. }
  6819. /**
  6820. * In case of an unsuccessful operation, provides details of the occurred error.
  6821. * @member CancellationEventArgsBase.prototype.errorDetails
  6822. * @function
  6823. * @public
  6824. * @returns {string} A String that represents the error details.
  6825. */
  6826. get errorDetails() {
  6827. return this.privErrorDetails;
  6828. }
  6829. }
  6830. exports.CancellationEventArgsBase = CancellationEventArgsBase;
  6831. /***/ }),
  6832. /* 102 */
  6833. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6834. "use strict";
  6835. // Copyright (c) Microsoft Corporation. All rights reserved.
  6836. // Licensed under the MIT license.
  6837. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6838. exports.TranslationRecognitionEventArgs = void 0;
  6839. const Exports_js_1 = __webpack_require__(79);
  6840. /**
  6841. * Translation text result event arguments.
  6842. * @class TranslationRecognitionEventArgs
  6843. */
  6844. class TranslationRecognitionEventArgs extends Exports_js_1.RecognitionEventArgs {
  6845. /**
  6846. * Creates and initializes an instance of this class.
  6847. * @constructor
  6848. * @param {TranslationRecognitionResult} result - The translation recognition result.
  6849. * @param {number} offset - The offset.
  6850. * @param {string} sessionId - The session id.
  6851. */
  6852. constructor(result, offset, sessionId) {
  6853. super(offset, sessionId);
  6854. this.privResult = result;
  6855. }
  6856. /**
  6857. * Specifies the recognition result.
  6858. * @member TranslationRecognitionEventArgs.prototype.result
  6859. * @function
  6860. * @public
  6861. * @returns {TranslationRecognitionResult} the recognition result.
  6862. */
  6863. get result() {
  6864. return this.privResult;
  6865. }
  6866. }
  6867. exports.TranslationRecognitionEventArgs = TranslationRecognitionEventArgs;
  6868. /***/ }),
  6869. /* 103 */
  6870. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6871. "use strict";
  6872. // Copyright (c) Microsoft Corporation. All rights reserved.
  6873. // Licensed under the MIT license.
  6874. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6875. exports.TranslationSynthesisEventArgs = void 0;
  6876. const Exports_js_1 = __webpack_require__(79);
  6877. /**
  6878. * Translation Synthesis event arguments
  6879. * @class TranslationSynthesisEventArgs
  6880. */
  6881. class TranslationSynthesisEventArgs extends Exports_js_1.SessionEventArgs {
  6882. /**
  6883. * Creates and initializes an instance of this class.
  6884. * @constructor
  6885. * @param {TranslationSynthesisResult} result - The translation synthesis result.
  6886. * @param {string} sessionId - The session id.
  6887. */
  6888. constructor(result, sessionId) {
  6889. super(sessionId);
  6890. this.privResult = result;
  6891. }
  6892. /**
  6893. * Specifies the translation synthesis result.
  6894. * @member TranslationSynthesisEventArgs.prototype.result
  6895. * @function
  6896. * @public
  6897. * @returns {TranslationSynthesisResult} Specifies the translation synthesis result.
  6898. */
  6899. get result() {
  6900. return this.privResult;
  6901. }
  6902. }
  6903. exports.TranslationSynthesisEventArgs = TranslationSynthesisEventArgs;
  6904. /***/ }),
  6905. /* 104 */
  6906. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6907. "use strict";
  6908. // Copyright (c) Microsoft Corporation. All rights reserved.
  6909. // Licensed under the MIT license.
  6910. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6911. exports.TranslationRecognitionResult = void 0;
  6912. const Exports_js_1 = __webpack_require__(79);
  6913. /**
  6914. * Translation text result.
  6915. * @class TranslationRecognitionResult
  6916. */
  6917. class TranslationRecognitionResult extends Exports_js_1.SpeechRecognitionResult {
  6918. /**
  6919. * Creates and initializes an instance of this class.
  6920. * @constructor
  6921. * @param {Translations} translations - The translations.
  6922. * @param {string} resultId - The result id.
  6923. * @param {ResultReason} reason - The reason.
  6924. * @param {string} text - The recognized text.
  6925. * @param {number} duration - The duration.
  6926. * @param {number} offset - The offset into the stream.
  6927. * @param {string} language - Primary Language detected, if provided.
  6928. * @param {string} languageDetectionConfidence - Primary Language confidence ("Unknown," "Low," "Medium," "High"...), if provided.
  6929. * @param {string} errorDetails - Error details, if provided.
  6930. * @param {string} json - Additional Json, if provided.
  6931. * @param {PropertyCollection} properties - Additional properties, if provided.
  6932. */
  6933. constructor(translations, resultId, reason, text, duration, offset, language, languageDetectionConfidence, errorDetails, json, properties) {
  6934. super(resultId, reason, text, duration, offset, language, languageDetectionConfidence, undefined, errorDetails, json, properties);
  6935. this.privTranslations = translations;
  6936. }
  6937. static fromSpeechRecognitionResult(result) {
  6938. return new TranslationRecognitionResult(undefined, result.resultId, result.reason, result.text, result.duration, result.offset, result.language, result.languageDetectionConfidence, result.errorDetails, result.json, result.properties);
  6939. }
  6940. /**
  6941. * Presents the translation results. Each item in the dictionary represents
  6942. * a translation result in one of target languages, where the key is the name
  6943. * of the target language, in BCP-47 format, and the value is the translation
  6944. * text in the specified language.
  6945. * @member TranslationRecognitionResult.prototype.translations
  6946. * @function
  6947. * @public
  6948. * @returns {Translations} the current translation map that holds all translations requested.
  6949. */
  6950. get translations() {
  6951. return this.privTranslations;
  6952. }
  6953. }
  6954. exports.TranslationRecognitionResult = TranslationRecognitionResult;
  6955. /***/ }),
  6956. /* 105 */
  6957. /***/ ((__unused_webpack_module, exports) => {
  6958. "use strict";
  6959. // Copyright (c) Microsoft Corporation. All rights reserved.
  6960. // Licensed under the MIT license.
  6961. Object.defineProperty(exports, "__esModule", ({ value: true }));
  6962. exports.TranslationSynthesisResult = void 0;
  6963. /**
  6964. * Defines translation synthesis result, i.e. the voice output of the translated
  6965. * text in the target language.
  6966. * @class TranslationSynthesisResult
  6967. */
  6968. class TranslationSynthesisResult {
  6969. /**
  6970. * Creates and initializes an instance of this class.
  6971. * @constructor
  6972. * @param {ResultReason} reason - The synthesis reason.
  6973. * @param {ArrayBuffer} audio - The audio data.
  6974. */
  6975. constructor(reason, audio) {
  6976. this.privReason = reason;
  6977. this.privAudio = audio;
  6978. }
  6979. /**
  6980. * Translated text in the target language.
  6981. * @member TranslationSynthesisResult.prototype.audio
  6982. * @function
  6983. * @public
  6984. * @returns {ArrayBuffer} Translated audio in the target language.
  6985. */
  6986. get audio() {
  6987. return this.privAudio;
  6988. }
  6989. /**
  6990. * The synthesis status.
  6991. * @member TranslationSynthesisResult.prototype.reason
  6992. * @function
  6993. * @public
  6994. * @returns {ResultReason} The synthesis status.
  6995. */
  6996. get reason() {
  6997. return this.privReason;
  6998. }
  6999. }
  7000. exports.TranslationSynthesisResult = TranslationSynthesisResult;
  7001. /***/ }),
  7002. /* 106 */
  7003. /***/ ((__unused_webpack_module, exports) => {
  7004. "use strict";
  7005. // Copyright (c) Microsoft Corporation. All rights reserved.
  7006. // Licensed under the MIT license.
  7007. Object.defineProperty(exports, "__esModule", ({ value: true }));
  7008. exports.ResultReason = void 0;
  7009. /**
  7010. * Defines the possible reasons a recognition result might be generated.
  7011. * @class ResultReason
  7012. */
  7013. var ResultReason;
  7014. (function (ResultReason) {
  7015. /**
  7016. * Indicates speech could not be recognized. More details
  7017. * can be found in the NoMatchDetails object.
  7018. * @member ResultReason.NoMatch
  7019. */
  7020. ResultReason[ResultReason["NoMatch"] = 0] = "NoMatch";
  7021. /**
  7022. * Indicates that the recognition was canceled. More details
  7023. * can be found using the CancellationDetails object.
  7024. * @member ResultReason.Canceled
  7025. */
  7026. ResultReason[ResultReason["Canceled"] = 1] = "Canceled";
  7027. /**
  7028. * Indicates the speech result contains hypothesis text.
  7029. * @member ResultReason.RecognizedSpeech
  7030. */
  7031. ResultReason[ResultReason["RecognizingSpeech"] = 2] = "RecognizingSpeech";
  7032. /**
  7033. * Indicates the speech result contains final text that has been recognized.
  7034. * Speech Recognition is now complete for this phrase.
  7035. * @member ResultReason.RecognizedSpeech
  7036. */
  7037. ResultReason[ResultReason["RecognizedSpeech"] = 3] = "RecognizedSpeech";
  7038. /**
  7039. * Indicates the speech result contains a finalized acceptance of a provided keyword.
  7040. * Speech recognition will continue unless otherwise configured.
  7041. * @member ResultReason.RecognizedKeyword
  7042. */
  7043. ResultReason[ResultReason["RecognizedKeyword"] = 4] = "RecognizedKeyword";
  7044. /**
  7045. * Indicates the intent result contains hypothesis text and intent.
  7046. * @member ResultReason.RecognizingIntent
  7047. */
  7048. ResultReason[ResultReason["RecognizingIntent"] = 5] = "RecognizingIntent";
  7049. /**
  7050. * Indicates the intent result contains final text and intent.
  7051. * Speech Recognition and Intent determination are now complete for this phrase.
  7052. * @member ResultReason.RecognizedIntent
  7053. */
  7054. ResultReason[ResultReason["RecognizedIntent"] = 6] = "RecognizedIntent";
  7055. /**
  7056. * Indicates the translation result contains hypothesis text and its translation(s).
  7057. * @member ResultReason.TranslatingSpeech
  7058. */
  7059. ResultReason[ResultReason["TranslatingSpeech"] = 7] = "TranslatingSpeech";
  7060. /**
  7061. * Indicates the translation result contains final text and corresponding translation(s).
  7062. * Speech Recognition and Translation are now complete for this phrase.
  7063. * @member ResultReason.TranslatedSpeech
  7064. */
  7065. ResultReason[ResultReason["TranslatedSpeech"] = 8] = "TranslatedSpeech";
  7066. /**
  7067. * Indicates the synthesized audio result contains a non-zero amount of audio data
  7068. * @member ResultReason.SynthesizingAudio
  7069. */
  7070. ResultReason[ResultReason["SynthesizingAudio"] = 9] = "SynthesizingAudio";
  7071. /**
  7072. * Indicates the synthesized audio is now complete for this phrase.
  7073. * @member ResultReason.SynthesizingAudioCompleted
  7074. */
  7075. ResultReason[ResultReason["SynthesizingAudioCompleted"] = 10] = "SynthesizingAudioCompleted";
  7076. /**
  7077. * Indicates the speech synthesis is now started
  7078. * @member ResultReason.SynthesizingAudioStarted
  7079. */
  7080. ResultReason[ResultReason["SynthesizingAudioStarted"] = 11] = "SynthesizingAudioStarted";
  7081. /**
  7082. * Indicates the voice profile is being enrolled and customers need to send more audio to create a voice profile.
  7083. * @member ResultReason.EnrollingVoiceProfile
  7084. */
  7085. ResultReason[ResultReason["EnrollingVoiceProfile"] = 12] = "EnrollingVoiceProfile";
  7086. /**
  7087. * Indicates the voice profile has been enrolled.
  7088. * @member ResultReason.EnrolledVoiceProfile
  7089. */
  7090. ResultReason[ResultReason["EnrolledVoiceProfile"] = 13] = "EnrolledVoiceProfile";
  7091. /**
  7092. * Indicates successful identification of some speakers.
  7093. * @member ResultReason.RecognizedSpeakers
  7094. */
  7095. ResultReason[ResultReason["RecognizedSpeakers"] = 14] = "RecognizedSpeakers";
  7096. /**
  7097. * Indicates successfully verified one speaker.
  7098. * @member ResultReason.RecognizedSpeaker
  7099. */
  7100. ResultReason[ResultReason["RecognizedSpeaker"] = 15] = "RecognizedSpeaker";
  7101. /**
  7102. * Indicates a voice profile has been reset successfully.
  7103. * @member ResultReason.ResetVoiceProfile
  7104. */
  7105. ResultReason[ResultReason["ResetVoiceProfile"] = 16] = "ResetVoiceProfile";
  7106. /**
  7107. * Indicates a voice profile has been deleted successfully.
  7108. * @member ResultReason.DeletedVoiceProfile
  7109. */
  7110. ResultReason[ResultReason["DeletedVoiceProfile"] = 17] = "DeletedVoiceProfile";
  7111. /**
  7112. * Indicates synthesis voices list has been successfully retrieved.
  7113. * @member ResultReason.VoicesListRetrieved
  7114. */
  7115. ResultReason[ResultReason["VoicesListRetrieved"] = 18] = "VoicesListRetrieved";
  7116. /**
  7117. * Indicates the transcription result contains hypothesis text and its translation(s) for
  7118. * other participants in the conversation.
  7119. * @member ResultReason.TranslatingParticipantSpeech
  7120. */
  7121. ResultReason[ResultReason["TranslatingParticipantSpeech"] = 19] = "TranslatingParticipantSpeech";
  7122. /**
  7123. * Indicates the transcription result contains final text and corresponding translation(s)
  7124. * for other participants in the conversation. Speech Recognition and Translation are now
  7125. * complete for this phrase.
  7126. * @member ResultReason.TranslatedParticipantSpeech
  7127. */
  7128. ResultReason[ResultReason["TranslatedParticipantSpeech"] = 20] = "TranslatedParticipantSpeech";
  7129. /**
  7130. * <summary>
  7131. * Indicates the transcription result contains the instant message and corresponding
  7132. * translation(s).
  7133. * @member ResultReason.TranslatedInstantMessage
  7134. */
  7135. ResultReason[ResultReason["TranslatedInstantMessage"] = 21] = "TranslatedInstantMessage";
  7136. /**
  7137. * Indicates the transcription result contains the instant message for other participants
  7138. * in the conversation and corresponding translation(s).
  7139. * @member ResultReason.TranslatedParticipantInstantMessage
  7140. */
  7141. ResultReason[ResultReason["TranslatedParticipantInstantMessage"] = 22] = "TranslatedParticipantInstantMessage";
  7142. })(ResultReason = exports.ResultReason || (exports.ResultReason = {}));
  7143. /***/ }),
  7144. /* 107 */
  7145. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7146. "use strict";
  7147. // Copyright (c) Microsoft Corporation. All rights reserved.
  7148. // Licensed under the MIT license.
  7149. /* eslint-disable max-classes-per-file */
  7150. Object.defineProperty(exports, "__esModule", ({ value: true }));
  7151. exports.SpeechConfigImpl = exports.SpeechConfig = void 0;
  7152. const Exports_js_1 = __webpack_require__(2);
  7153. const Contracts_js_1 = __webpack_require__(64);
  7154. const Exports_js_2 = __webpack_require__(79);
  7155. /**
  7156. * Speech configuration.
  7157. * @class SpeechConfig
  7158. */
  7159. class SpeechConfig {
  7160. /**
  7161. * Creates and initializes an instance.
  7162. * @constructor
  7163. */
  7164. constructor() {
  7165. return;
  7166. }
  7167. /**
  7168. * Static instance of SpeechConfig returned by passing subscriptionKey and service region.
  7169. * Note: Please use your LanguageUnderstanding subscription key in case you want to use the Intent recognizer.
  7170. * @member SpeechConfig.fromSubscription
  7171. * @function
  7172. * @public
  7173. * @param {string} subscriptionKey - The subscription key.
  7174. * @param {string} region - The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).
  7175. * @returns {SpeechConfig} The speech factory
  7176. */
  7177. static fromSubscription(subscriptionKey, region) {
  7178. Contracts_js_1.Contracts.throwIfNullOrWhitespace(subscriptionKey, "subscriptionKey");
  7179. Contracts_js_1.Contracts.throwIfNullOrWhitespace(region, "region");
  7180. const speechImpl = new SpeechConfigImpl();
  7181. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region, region);
  7182. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_IntentRegion, region);
  7183. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Key, subscriptionKey);
  7184. return speechImpl;
  7185. }
  7186. /**
  7187. * Internal implementation of fromEndpoint() overloads. Accepts either a subscription key or a TokenCredential.
  7188. * @private
  7189. */
  7190. static fromEndpoint(endpoint, auth) {
  7191. Contracts_js_1.Contracts.throwIfNull(endpoint, "endpoint");
  7192. const isValidString = typeof auth === "string" && auth.trim().length > 0;
  7193. const isTokenCredential = typeof auth === "object" && auth !== null && typeof auth.getToken === "function";
  7194. if (auth !== undefined && !isValidString && !isTokenCredential) {
  7195. throw new Error("Invalid 'auth' parameter: must be a non-empty key string or a valid TokenCredential object.");
  7196. }
  7197. const speechImpl = typeof auth === "object"
  7198. ? new SpeechConfigImpl(auth)
  7199. : new SpeechConfigImpl();
  7200. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint, endpoint.href);
  7201. if (typeof auth === "string" && auth.trim().length > 0) {
  7202. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Key, auth);
  7203. }
  7204. return speechImpl;
  7205. }
  7206. /**
  7207. * Creates an instance of the speech config with specified host and subscription key.
  7208. * This method is intended only for users who use a non-default service host. Standard resource path will be assumed.
  7209. * For services with a non-standard resource path or no path at all, use fromEndpoint instead.
  7210. * Note: Query parameters are not allowed in the host URI and must be set by other APIs.
  7211. * Note: To use an authorization token with fromHost, use fromHost(URL),
  7212. * and then set the AuthorizationToken property on the created SpeechConfig instance.
  7213. * Note: Added in version 1.9.0.
  7214. * @member SpeechConfig.fromHost
  7215. * @function
  7216. * @public
  7217. * @param {URL} host - The service endpoint to connect to. Format is "protocol://host:port" where ":port" is optional.
  7218. * @param {string} subscriptionKey - The subscription key. If a subscription key is not specified, an authorization token must be set.
  7219. * @returns {SpeechConfig} A speech factory instance.
  7220. */
  7221. static fromHost(hostName, subscriptionKey) {
  7222. Contracts_js_1.Contracts.throwIfNull(hostName, "hostName");
  7223. const speechImpl = new SpeechConfigImpl();
  7224. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, hostName.protocol + "//" + hostName.hostname + (hostName.port === "" ? "" : ":" + hostName.port));
  7225. // Containers do not yet have /stt/speech/universal/v2 routes.
  7226. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecognitionEndpointVersion, "1");
  7227. if (undefined !== subscriptionKey) {
  7228. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Key, subscriptionKey);
  7229. }
  7230. return speechImpl;
  7231. }
  7232. /**
  7233. * Creates an instance of the speech factory with specified initial authorization token and region.
  7234. * Note: The caller needs to ensure that the authorization token is valid. Before the authorization token
  7235. * expires, the caller needs to refresh it by calling this setter with a new valid token.
  7236. * Note: Please use a token derived from your LanguageUnderstanding subscription key in case you want
  7237. * to use the Intent recognizer. As configuration values are copied when creating a new recognizer,
  7238. * the new token value will not apply to recognizers that have already been created. For recognizers
  7239. * that have been created before, you need to set authorization token of the corresponding recognizer
  7240. * to refresh the token. Otherwise, the recognizers will encounter errors during recognition.
  7241. * @member SpeechConfig.fromAuthorizationToken
  7242. * @function
  7243. * @public
  7244. * @param {string} authorizationToken - The initial authorization token.
  7245. * @param {string} region - The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).
  7246. * @returns {SpeechConfig} A speech factory instance.
  7247. */
  7248. static fromAuthorizationToken(authorizationToken, region) {
  7249. Contracts_js_1.Contracts.throwIfNull(authorizationToken, "authorizationToken");
  7250. Contracts_js_1.Contracts.throwIfNullOrWhitespace(region, "region");
  7251. const speechImpl = new SpeechConfigImpl();
  7252. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region, region);
  7253. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_IntentRegion, region);
  7254. speechImpl.authorizationToken = authorizationToken;
  7255. return speechImpl;
  7256. }
  7257. /**
  7258. * Closes the configuration.
  7259. * @member SpeechConfig.prototype.close
  7260. * @function
  7261. * @public
  7262. */
  7263. // eslint-disable-next-line @typescript-eslint/no-empty-function
  7264. close() { }
  7265. }
  7266. exports.SpeechConfig = SpeechConfig;
  7267. /**
  7268. * @public
  7269. * @class SpeechConfigImpl
  7270. */
  7271. class SpeechConfigImpl extends SpeechConfig {
  7272. constructor(tokenCredential) {
  7273. super();
  7274. this.privProperties = new Exports_js_2.PropertyCollection();
  7275. this.speechRecognitionLanguage = "en-US"; // Should we have a default?
  7276. this.outputFormat = Exports_js_2.OutputFormat.Simple;
  7277. this.privTokenCredential = tokenCredential;
  7278. }
  7279. get properties() {
  7280. return this.privProperties;
  7281. }
  7282. get endPoint() {
  7283. return new URL(this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint));
  7284. }
  7285. get subscriptionKey() {
  7286. return this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Key);
  7287. }
  7288. get region() {
  7289. return this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region);
  7290. }
  7291. get authorizationToken() {
  7292. return this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token);
  7293. }
  7294. set authorizationToken(value) {
  7295. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token, value);
  7296. }
  7297. get speechRecognitionLanguage() {
  7298. return this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage);
  7299. }
  7300. set speechRecognitionLanguage(value) {
  7301. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage, value);
  7302. }
  7303. get autoDetectSourceLanguages() {
  7304. return this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages);
  7305. }
  7306. set autoDetectSourceLanguages(value) {
  7307. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages, value);
  7308. }
  7309. get outputFormat() {
  7310. return Exports_js_2.OutputFormat[this.privProperties.getProperty(Exports_js_1.OutputFormatPropertyName, undefined)];
  7311. }
  7312. set outputFormat(value) {
  7313. this.privProperties.setProperty(Exports_js_1.OutputFormatPropertyName, Exports_js_2.OutputFormat[value]);
  7314. }
  7315. get endpointId() {
  7316. return this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_EndpointId);
  7317. }
  7318. set endpointId(value) {
  7319. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_EndpointId, value);
  7320. }
  7321. get tokenCredential() {
  7322. return this.privTokenCredential;
  7323. }
  7324. setProperty(name, value) {
  7325. Contracts_js_1.Contracts.throwIfNull(value, "value");
  7326. this.privProperties.setProperty(name, value);
  7327. }
  7328. getProperty(name, def) {
  7329. return this.privProperties.getProperty(name, def);
  7330. }
  7331. setProxy(proxyHostName, proxyPort, proxyUserName, proxyPassword) {
  7332. this.setProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_ProxyHostName], proxyHostName);
  7333. this.setProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_ProxyPort], proxyPort);
  7334. this.setProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_ProxyUserName], proxyUserName);
  7335. this.setProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_ProxyPassword], proxyPassword);
  7336. }
  7337. setServiceProperty(name, value) {
  7338. const currentProperties = JSON.parse(this.privProperties.getProperty(Exports_js_1.ServicePropertiesPropertyName, "{}"));
  7339. currentProperties[name] = value;
  7340. this.privProperties.setProperty(Exports_js_1.ServicePropertiesPropertyName, JSON.stringify(currentProperties));
  7341. }
  7342. setProfanity(profanity) {
  7343. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceResponse_ProfanityOption, Exports_js_2.ProfanityOption[profanity]);
  7344. }
  7345. enableAudioLogging() {
  7346. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_EnableAudioLogging, "true");
  7347. }
  7348. requestWordLevelTimestamps() {
  7349. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, "true");
  7350. this.privProperties.setProperty(Exports_js_1.OutputFormatPropertyName, Exports_js_2.OutputFormat[Exports_js_2.OutputFormat.Detailed]);
  7351. }
  7352. enableDictation() {
  7353. this.privProperties.setProperty(Exports_js_1.ForceDictationPropertyName, "true");
  7354. }
  7355. clone() {
  7356. const ret = new SpeechConfigImpl(this.tokenCredential);
  7357. ret.privProperties = this.privProperties.clone();
  7358. return ret;
  7359. }
  7360. get speechSynthesisLanguage() {
  7361. return this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthLanguage);
  7362. }
  7363. set speechSynthesisLanguage(language) {
  7364. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthLanguage, language);
  7365. }
  7366. get speechSynthesisVoiceName() {
  7367. return this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthVoice);
  7368. }
  7369. set speechSynthesisVoiceName(voice) {
  7370. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthVoice, voice);
  7371. }
  7372. get speechSynthesisOutputFormat() {
  7373. return Exports_js_2.SpeechSynthesisOutputFormat[this.privProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthOutputFormat, undefined)];
  7374. }
  7375. set speechSynthesisOutputFormat(format) {
  7376. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthOutputFormat, Exports_js_2.SpeechSynthesisOutputFormat[format]);
  7377. }
  7378. }
  7379. exports.SpeechConfigImpl = SpeechConfigImpl;
  7380. /***/ }),
  7381. /* 108 */
  7382. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7383. "use strict";
  7384. // Copyright (c) Microsoft Corporation. All rights reserved.
  7385. // Licensed under the MIT license.
  7386. Object.defineProperty(exports, "__esModule", ({ value: true }));
  7387. exports.SpeechTranslationConfigImpl = exports.SpeechTranslationConfig = void 0;
  7388. const Exports_js_1 = __webpack_require__(2);
  7389. const Contracts_js_1 = __webpack_require__(64);
  7390. const Exports_js_2 = __webpack_require__(79);
  7391. /**
  7392. * Speech translation configuration.
  7393. * @class SpeechTranslationConfig
  7394. */
  7395. class SpeechTranslationConfig extends Exports_js_2.SpeechConfig {
  7396. /**
  7397. * Creates an instance of recognizer config.
  7398. */
  7399. constructor() {
  7400. super();
  7401. }
  7402. /**
  7403. * Static instance of SpeechTranslationConfig returned by passing a subscription key and service region.
  7404. * @member SpeechTranslationConfig.fromSubscription
  7405. * @function
  7406. * @public
  7407. * @param {string} subscriptionKey - The subscription key.
  7408. * @param {string} region - The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).
  7409. * @returns {SpeechTranslationConfig} The speech translation config.
  7410. */
  7411. static fromSubscription(subscriptionKey, region) {
  7412. Contracts_js_1.Contracts.throwIfNullOrWhitespace(subscriptionKey, "subscriptionKey");
  7413. Contracts_js_1.Contracts.throwIfNullOrWhitespace(region, "region");
  7414. const ret = new SpeechTranslationConfigImpl();
  7415. ret.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Key, subscriptionKey);
  7416. ret.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region, region);
  7417. return ret;
  7418. }
  7419. /**
  7420. * Static instance of SpeechTranslationConfig returned by passing authorization token and service region.
  7421. * Note: The caller needs to ensure that the authorization token is valid. Before the authorization token
  7422. * expires, the caller needs to refresh it by setting the property authorizationToken with a new
  7423. * valid token. Otherwise, all the recognizers created by this SpeechTranslationConfig instance
  7424. * will encounter errors during recognition.
  7425. * As configuration values are copied when creating a new recognizer, the new token value will not apply
  7426. * to recognizers that have already been created.
  7427. * For recognizers that have been created before, you need to set authorization token of the corresponding recognizer
  7428. * to refresh the token. Otherwise, the recognizers will encounter errors during recognition.
  7429. * @member SpeechTranslationConfig.fromAuthorizationToken
  7430. * @function
  7431. * @public
  7432. * @param {string} authorizationToken - The authorization token.
  7433. * @param {string} region - The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).
  7434. * @returns {SpeechTranslationConfig} The speech translation config.
  7435. */
  7436. static fromAuthorizationToken(authorizationToken, region) {
  7437. Contracts_js_1.Contracts.throwIfNullOrWhitespace(authorizationToken, "authorizationToken");
  7438. Contracts_js_1.Contracts.throwIfNullOrWhitespace(region, "region");
  7439. const ret = new SpeechTranslationConfigImpl();
  7440. ret.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token, authorizationToken);
  7441. ret.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region, region);
  7442. return ret;
  7443. }
  7444. /**
  7445. * Creates an instance of the speech config with specified host and subscription key.
  7446. * This method is intended only for users who use a non-default service host. Standard resource path will be assumed.
  7447. * For services with a non-standard resource path or no path at all, use fromEndpoint instead.
  7448. * Note: Query parameters are not allowed in the host URI and must be set by other APIs.
  7449. * Note: To use an authorization token with fromHost, use fromHost(URL),
  7450. * and then set the AuthorizationToken property on the created SpeechConfig instance.
  7451. * Note: Added in version 1.9.0.
  7452. * @member SpeechConfig.fromHost
  7453. * @function
  7454. * @public
  7455. * @param {URL} host - The service endpoint to connect to. Format is "protocol://host:port" where ":port" is optional.
  7456. * @param {string} subscriptionKey - The subscription key. If a subscription key is not specified, an authorization token must be set.
  7457. * @returns {SpeechConfig} A speech factory instance.
  7458. */
  7459. static fromHost(hostName, subscriptionKey) {
  7460. Contracts_js_1.Contracts.throwIfNull(hostName, "hostName");
  7461. const speechImpl = new SpeechTranslationConfigImpl();
  7462. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, hostName.protocol + "//" + hostName.hostname + (hostName.port === "" ? "" : ":" + hostName.port));
  7463. if (undefined !== subscriptionKey) {
  7464. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Key, subscriptionKey);
  7465. }
  7466. return speechImpl;
  7467. }
  7468. /**
  7469. * Internal implementation of fromEndpoint() overloads. Accepts either a subscription key or a TokenCredential.
  7470. * @private
  7471. */
  7472. static fromEndpoint(endpoint, auth) {
  7473. Contracts_js_1.Contracts.throwIfNull(endpoint, "endpoint");
  7474. const isValidString = typeof auth === "string" && auth.trim().length > 0;
  7475. const isTokenCredential = typeof auth === "object" && auth !== null && typeof auth.getToken === "function";
  7476. if (auth !== undefined && !isValidString && !isTokenCredential) {
  7477. throw new Error("Invalid 'auth' parameter: must be a non-empty key string or a valid TokenCredential object.");
  7478. }
  7479. const speechImpl = typeof auth === "object"
  7480. ? new SpeechTranslationConfigImpl(auth)
  7481. : new SpeechTranslationConfigImpl();
  7482. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint, endpoint.href);
  7483. if (typeof auth === "string" && auth.trim().length > 0) {
  7484. speechImpl.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Key, auth);
  7485. }
  7486. return speechImpl;
  7487. }
  7488. }
  7489. exports.SpeechTranslationConfig = SpeechTranslationConfig;
  7490. /**
  7491. * @private
  7492. * @class SpeechTranslationConfigImpl
  7493. */
  7494. class SpeechTranslationConfigImpl extends SpeechTranslationConfig {
  7495. constructor(tokenCredential) {
  7496. super();
  7497. this.privSpeechProperties = new Exports_js_2.PropertyCollection();
  7498. this.outputFormat = Exports_js_2.OutputFormat.Simple;
  7499. this.privTokenCredential = tokenCredential;
  7500. }
  7501. /**
  7502. * Gets/Sets the authorization token.
  7503. * If this is set, subscription key is ignored.
  7504. * User needs to make sure the provided authorization token is valid and not expired.
  7505. * @member SpeechTranslationConfigImpl.prototype.authorizationToken
  7506. * @function
  7507. * @public
  7508. * @param {string} value - The authorization token.
  7509. */
  7510. set authorizationToken(value) {
  7511. Contracts_js_1.Contracts.throwIfNullOrWhitespace(value, "value");
  7512. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token, value);
  7513. }
  7514. /**
  7515. * Sets the speech recognition language.
  7516. * @member SpeechTranslationConfigImpl.prototype.speechRecognitionLanguage
  7517. * @function
  7518. * @public
  7519. * @param {string} value - The authorization token.
  7520. */
  7521. set speechRecognitionLanguage(value) {
  7522. Contracts_js_1.Contracts.throwIfNullOrWhitespace(value, "value");
  7523. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage, value);
  7524. }
  7525. /**
  7526. * Gets the speech recognition language.
  7527. * @member SpeechTranslationConfigImpl.prototype.speechRecognitionLanguage
  7528. * @function
  7529. * @public
  7530. * @return {string} The speechRecognitionLanguage.
  7531. */
  7532. get speechRecognitionLanguage() {
  7533. return this.privSpeechProperties.getProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage]);
  7534. }
  7535. /**
  7536. * @member SpeechTranslationConfigImpl.prototype.subscriptionKey
  7537. * @function
  7538. * @public
  7539. */
  7540. get subscriptionKey() {
  7541. return this.privSpeechProperties.getProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_Key]);
  7542. }
  7543. /**
  7544. * Gets the output format
  7545. * @member SpeechTranslationConfigImpl.prototype.outputFormat
  7546. * @function
  7547. * @public
  7548. */
  7549. get outputFormat() {
  7550. // eslint-disable-next-line
  7551. return Exports_js_2.OutputFormat[this.privSpeechProperties.getProperty(Exports_js_1.OutputFormatPropertyName, undefined)];
  7552. }
  7553. /**
  7554. * Gets/Sets the output format
  7555. * @member SpeechTranslationConfigImpl.prototype.outputFormat
  7556. * @function
  7557. * @public
  7558. */
  7559. set outputFormat(value) {
  7560. this.privSpeechProperties.setProperty(Exports_js_1.OutputFormatPropertyName, Exports_js_2.OutputFormat[value]);
  7561. }
  7562. /**
  7563. * Gets the endpoint id.
  7564. * @member SpeechTranslationConfigImpl.prototype.endpointId
  7565. * @function
  7566. * @public
  7567. */
  7568. get endpointId() {
  7569. return this.privSpeechProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_EndpointId);
  7570. }
  7571. /**
  7572. * Gets/Sets the endpoint id.
  7573. * @member SpeechTranslationConfigImpl.prototype.endpointId
  7574. * @function
  7575. * @public
  7576. */
  7577. set endpointId(value) {
  7578. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_EndpointId, value);
  7579. }
  7580. /**
  7581. * Add a (text) target language to translate into.
  7582. * @member SpeechTranslationConfigImpl.prototype.addTargetLanguage
  7583. * @function
  7584. * @public
  7585. * @param {string} value - The language such as de-DE
  7586. */
  7587. addTargetLanguage(value) {
  7588. Contracts_js_1.Contracts.throwIfNullOrWhitespace(value, "value");
  7589. const languages = this.targetLanguages;
  7590. if (!languages.includes(value)) {
  7591. languages.push(value);
  7592. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationToLanguages, languages.join(","));
  7593. }
  7594. }
  7595. /**
  7596. * Gets the (text) target language to translate into.
  7597. * @member SpeechTranslationConfigImpl.prototype.targetLanguages
  7598. * @function
  7599. * @public
  7600. * @param {string} value - The language such as de-DE
  7601. */
  7602. get targetLanguages() {
  7603. if (this.privSpeechProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationToLanguages, undefined) !== undefined) {
  7604. return this.privSpeechProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationToLanguages).split(",");
  7605. }
  7606. else {
  7607. return [];
  7608. }
  7609. }
  7610. /**
  7611. * Gets the voice name.
  7612. * @member SpeechTranslationConfigImpl.prototype.voiceName
  7613. * @function
  7614. * @public
  7615. */
  7616. get voiceName() {
  7617. return this.getProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_TranslationVoice]);
  7618. }
  7619. /**
  7620. * Gets/Sets the voice of the translated language, enable voice synthesis output.
  7621. * @member SpeechTranslationConfigImpl.prototype.voiceName
  7622. * @function
  7623. * @public
  7624. * @param {string} value - The name of the voice.
  7625. */
  7626. set voiceName(value) {
  7627. Contracts_js_1.Contracts.throwIfNullOrWhitespace(value, "value");
  7628. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationVoice, value);
  7629. }
  7630. /**
  7631. * Provides the region.
  7632. * @member SpeechTranslationConfigImpl.prototype.region
  7633. * @function
  7634. * @public
  7635. * @returns {string} The region.
  7636. */
  7637. get region() {
  7638. return this.privSpeechProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region);
  7639. }
  7640. get tokenCredential() {
  7641. return this.privTokenCredential;
  7642. }
  7643. setProxy(proxyHostName, proxyPort, proxyUserName, proxyPassword) {
  7644. this.setProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_ProxyHostName], proxyHostName);
  7645. this.setProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_ProxyPort], proxyPort);
  7646. this.setProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_ProxyUserName], proxyUserName);
  7647. this.setProperty(Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_ProxyPassword], proxyPassword);
  7648. }
  7649. /**
  7650. * Gets an arbitrary property value.
  7651. * @member SpeechTranslationConfigImpl.prototype.getProperty
  7652. * @function
  7653. * @public
  7654. * @param {string} name - The name of the property.
  7655. * @param {string} def - The default value of the property in case it is not set.
  7656. * @returns {string} The value of the property.
  7657. */
  7658. getProperty(name, def) {
  7659. return this.privSpeechProperties.getProperty(name, def);
  7660. }
  7661. /**
  7662. * Gets/Sets an arbitrary property value.
  7663. * @member SpeechTranslationConfigImpl.prototype.setProperty
  7664. * @function
  7665. * @public
  7666. * @param {string | PropertyId} name - The name of the property to set.
  7667. * @param {string} value - The value of the property.
  7668. */
  7669. setProperty(name, value) {
  7670. this.privSpeechProperties.setProperty(name, value);
  7671. }
  7672. /**
  7673. * Provides access to custom properties.
  7674. * @member SpeechTranslationConfigImpl.prototype.properties
  7675. * @function
  7676. * @public
  7677. * @returns {PropertyCollection} The properties.
  7678. */
  7679. get properties() {
  7680. return this.privSpeechProperties;
  7681. }
  7682. /**
  7683. * Dispose of associated resources.
  7684. * @member SpeechTranslationConfigImpl.prototype.close
  7685. * @function
  7686. * @public
  7687. */
  7688. close() {
  7689. return;
  7690. }
  7691. setServiceProperty(name, value) {
  7692. const currentProperties = JSON.parse(this.privSpeechProperties.getProperty(Exports_js_1.ServicePropertiesPropertyName, "{}"));
  7693. currentProperties[name] = value;
  7694. this.privSpeechProperties.setProperty(Exports_js_1.ServicePropertiesPropertyName, JSON.stringify(currentProperties));
  7695. }
  7696. setProfanity(profanity) {
  7697. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceResponse_ProfanityOption, Exports_js_2.ProfanityOption[profanity]);
  7698. }
  7699. enableAudioLogging() {
  7700. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_EnableAudioLogging, "true");
  7701. }
  7702. requestWordLevelTimestamps() {
  7703. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, "true");
  7704. }
  7705. enableDictation() {
  7706. this.privSpeechProperties.setProperty(Exports_js_1.ForceDictationPropertyName, "true");
  7707. }
  7708. get speechSynthesisLanguage() {
  7709. return this.privSpeechProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthLanguage);
  7710. }
  7711. set speechSynthesisLanguage(language) {
  7712. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthLanguage, language);
  7713. }
  7714. get speechSynthesisVoiceName() {
  7715. return this.privSpeechProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthVoice);
  7716. }
  7717. set speechSynthesisVoiceName(voice) {
  7718. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthVoice, voice);
  7719. }
  7720. get speechSynthesisOutputFormat() {
  7721. // eslint-disable-next-line
  7722. return Exports_js_2.SpeechSynthesisOutputFormat[this.privSpeechProperties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthOutputFormat, undefined)];
  7723. }
  7724. set speechSynthesisOutputFormat(format) {
  7725. this.privSpeechProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SynthOutputFormat, Exports_js_2.SpeechSynthesisOutputFormat[format]);
  7726. }
  7727. }
  7728. exports.SpeechTranslationConfigImpl = SpeechTranslationConfigImpl;
  7729. /***/ }),
  7730. /* 109 */
  7731. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7732. "use strict";
  7733. // Copyright (c) Microsoft Corporation. All rights reserved.
  7734. // Licensed under the MIT license.
  7735. Object.defineProperty(exports, "__esModule", ({ value: true }));
  7736. exports.PropertyCollection = void 0;
  7737. const Exports_js_1 = __webpack_require__(79);
  7738. /**
  7739. * Represents collection of properties and their values.
  7740. * @class PropertyCollection
  7741. */
  7742. class PropertyCollection {
  7743. constructor() {
  7744. this.privKeys = [];
  7745. this.privValues = [];
  7746. }
  7747. /**
  7748. * Returns the property value in type String.
  7749. * Currently only String, int and bool are allowed.
  7750. * If the name is not available, the specified defaultValue is returned.
  7751. * @member PropertyCollection.prototype.getProperty
  7752. * @function
  7753. * @public
  7754. * @param {string} key - The parameter name.
  7755. * @param {string | number | boolean} def - The default value which is returned if the parameter
  7756. * is not available in the collection.
  7757. * @returns {string} value of the parameter.
  7758. */
  7759. getProperty(key, def) {
  7760. let keyToUse;
  7761. if (typeof key === "string") {
  7762. keyToUse = key;
  7763. }
  7764. else {
  7765. keyToUse = Exports_js_1.PropertyId[key];
  7766. }
  7767. for (let n = 0; n < this.privKeys.length; n++) {
  7768. if (this.privKeys[n] === keyToUse) {
  7769. return this.privValues[n];
  7770. }
  7771. }
  7772. if (def === undefined) {
  7773. return undefined;
  7774. }
  7775. return String(def);
  7776. }
  7777. /**
  7778. * Sets the String value of the parameter specified by name.
  7779. * @member PropertyCollection.prototype.setProperty
  7780. * @function
  7781. * @public
  7782. * @param {string} key - The parameter name.
  7783. * @param {string} value - The value of the parameter.
  7784. */
  7785. setProperty(key, value) {
  7786. let keyToUse;
  7787. if (typeof key === "string") {
  7788. keyToUse = key;
  7789. }
  7790. else {
  7791. keyToUse = Exports_js_1.PropertyId[key];
  7792. }
  7793. for (let n = 0; n < this.privKeys.length; n++) {
  7794. if (this.privKeys[n] === keyToUse) {
  7795. this.privValues[n] = value;
  7796. return;
  7797. }
  7798. }
  7799. this.privKeys.push(keyToUse);
  7800. this.privValues.push(value);
  7801. }
  7802. /**
  7803. * Clones the collection.
  7804. * @member PropertyCollection.prototype.clone
  7805. * @function
  7806. * @public
  7807. * @returns {PropertyCollection} A copy of the collection.
  7808. */
  7809. clone() {
  7810. const clonedMap = new PropertyCollection();
  7811. for (let n = 0; n < this.privKeys.length; n++) {
  7812. clonedMap.privKeys.push(this.privKeys[n]);
  7813. clonedMap.privValues.push(this.privValues[n]);
  7814. }
  7815. return clonedMap;
  7816. }
  7817. /**
  7818. * Merges this set of properties into another, no overwrites.
  7819. * @member PropertyCollection.prototype.mergeTo
  7820. * @function
  7821. * @public
  7822. * @param {PropertyCollection} destinationCollection - The collection to merge into.
  7823. */
  7824. mergeTo(destinationCollection) {
  7825. this.privKeys.forEach((key) => {
  7826. if (destinationCollection.getProperty(key, undefined) === undefined) {
  7827. const value = this.getProperty(key);
  7828. destinationCollection.setProperty(key, value);
  7829. }
  7830. });
  7831. }
  7832. /**
  7833. * Get the keys in Property Collection.
  7834. * @member PropertyCollection.prototype.keys
  7835. * @function
  7836. * @public
  7837. * @returns {string []} Keys in the collection.
  7838. */
  7839. get keys() {
  7840. return this.privKeys;
  7841. }
  7842. }
  7843. exports.PropertyCollection = PropertyCollection;
  7844. /***/ }),
  7845. /* 110 */
  7846. /***/ ((__unused_webpack_module, exports) => {
  7847. "use strict";
  7848. // Copyright (c) Microsoft Corporation. All rights reserved.
  7849. // Licensed under the MIT license.
  7850. Object.defineProperty(exports, "__esModule", ({ value: true }));
  7851. exports.PropertyId = void 0;
  7852. /**
  7853. * Defines speech property ids.
  7854. * @class PropertyId
  7855. */
  7856. var PropertyId;
  7857. (function (PropertyId) {
  7858. /**
  7859. * The Cognitive Services Speech Service subscription Key. If you are using an intent recognizer, you need to
  7860. * specify the LUIS endpoint key for your particular LUIS app. Under normal circumstances, you shouldn't
  7861. * have to use this property directly.
  7862. * Instead, use [[SpeechConfig.fromSubscription]].
  7863. * @member PropertyId.SpeechServiceConnection_Key
  7864. */
  7865. PropertyId[PropertyId["SpeechServiceConnection_Key"] = 0] = "SpeechServiceConnection_Key";
  7866. /**
  7867. * The Cognitive Services Speech Service endpoint (url). Under normal circumstances, you shouldn't
  7868. * have to use this property directly.
  7869. * Instead, use [[SpeechConfig.fromEndpoint]].
  7870. * NOTE: This endpoint is not the same as the endpoint used to obtain an access token.
  7871. * @member PropertyId.SpeechServiceConnection_Endpoint
  7872. */
  7873. PropertyId[PropertyId["SpeechServiceConnection_Endpoint"] = 1] = "SpeechServiceConnection_Endpoint";
  7874. /**
  7875. * The Cognitive Services Speech Service region. Under normal circumstances, you shouldn't have to
  7876. * use this property directly.
  7877. * Instead, use [[SpeechConfig.fromSubscription]], [[SpeechConfig.fromEndpoint]], [[SpeechConfig.fromAuthorizationToken]].
  7878. * @member PropertyId.SpeechServiceConnection_Region
  7879. */
  7880. PropertyId[PropertyId["SpeechServiceConnection_Region"] = 2] = "SpeechServiceConnection_Region";
  7881. /**
  7882. * The Cognitive Services Speech Service authorization token (aka access token). Under normal circumstances,
  7883. * you shouldn't have to use this property directly.
  7884. * Instead, use [[SpeechConfig.fromAuthorizationToken]], [[SpeechRecognizer.authorizationToken]],
  7885. * [[IntentRecognizer.authorizationToken]], [[TranslationRecognizer.authorizationToken]], [[SpeakerRecognizer.authorizationToken]].
  7886. * @member PropertyId.SpeechServiceAuthorization_Token
  7887. */
  7888. PropertyId[PropertyId["SpeechServiceAuthorization_Token"] = 3] = "SpeechServiceAuthorization_Token";
  7889. /**
  7890. * The Cognitive Services Speech Service authorization type. Currently unused.
  7891. * @member PropertyId.SpeechServiceAuthorization_Type
  7892. */
  7893. PropertyId[PropertyId["SpeechServiceAuthorization_Type"] = 4] = "SpeechServiceAuthorization_Type";
  7894. /**
  7895. * The Cognitive Services Speech Service endpoint id. Under normal circumstances, you shouldn't
  7896. * have to use this property directly.
  7897. * Instead, use [[SpeechConfig.endpointId]].
  7898. * NOTE: The endpoint id is available in the Speech Portal, listed under Endpoint Details.
  7899. * @member PropertyId.SpeechServiceConnection_EndpointId
  7900. */
  7901. PropertyId[PropertyId["SpeechServiceConnection_EndpointId"] = 5] = "SpeechServiceConnection_EndpointId";
  7902. /**
  7903. * The list of comma separated languages (BCP-47 format) used as target translation languages. Under normal circumstances,
  7904. * you shouldn't have to use this property directly.
  7905. * Instead use [[SpeechTranslationConfig.addTargetLanguage]],
  7906. * [[SpeechTranslationConfig.targetLanguages]], [[TranslationRecognizer.targetLanguages]].
  7907. * @member PropertyId.SpeechServiceConnection_TranslationToLanguages
  7908. */
  7909. PropertyId[PropertyId["SpeechServiceConnection_TranslationToLanguages"] = 6] = "SpeechServiceConnection_TranslationToLanguages";
  7910. /**
  7911. * The name of the Cognitive Service Text to Speech Service Voice. Under normal circumstances, you shouldn't have to use this
  7912. * property directly.
  7913. * Instead, use [[SpeechTranslationConfig.voiceName]].
  7914. * NOTE: Valid voice names can be found <a href="https://aka.ms/csspeech/voicenames">here</a>.
  7915. * @member PropertyId.SpeechServiceConnection_TranslationVoice
  7916. */
  7917. PropertyId[PropertyId["SpeechServiceConnection_TranslationVoice"] = 7] = "SpeechServiceConnection_TranslationVoice";
  7918. /**
  7919. * Translation features.
  7920. * @member PropertyId.SpeechServiceConnection_TranslationFeatures
  7921. */
  7922. PropertyId[PropertyId["SpeechServiceConnection_TranslationFeatures"] = 8] = "SpeechServiceConnection_TranslationFeatures";
  7923. /**
  7924. * The category ID for translation.
  7925. * @member PropertyId.SpeechServiceConnection_TranslationCategoryId
  7926. */
  7927. PropertyId[PropertyId["SpeechServiceConnection_TranslationCategoryId"] = 9] = "SpeechServiceConnection_TranslationCategoryId";
  7928. /**
  7929. * The Language Understanding Service Region. Under normal circumstances, you shouldn't have to use this property directly.
  7930. * Instead, use [[LanguageUnderstandingModel]].
  7931. * @member PropertyId.SpeechServiceConnection_IntentRegion
  7932. */
  7933. PropertyId[PropertyId["SpeechServiceConnection_IntentRegion"] = 10] = "SpeechServiceConnection_IntentRegion";
  7934. /**
  7935. * The host name of the proxy server used to connect to the Cognitive Services Speech Service. Only relevant in Node.js environments.
  7936. * You shouldn't have to use this property directly.
  7937. * Instead use <see cref="SpeechConfig.SetProxy(string,int,string,string)"/>.
  7938. * Added in version 1.4.0.
  7939. */
  7940. PropertyId[PropertyId["SpeechServiceConnection_ProxyHostName"] = 11] = "SpeechServiceConnection_ProxyHostName";
  7941. /**
  7942. * The port of the proxy server used to connect to the Cognitive Services Speech Service. Only relevant in Node.js environments.
  7943. * You shouldn't have to use this property directly.
  7944. * Instead use <see cref="SpeechConfig.SetProxy(string,int,string,string)"/>.
  7945. * Added in version 1.4.0.
  7946. */
  7947. PropertyId[PropertyId["SpeechServiceConnection_ProxyPort"] = 12] = "SpeechServiceConnection_ProxyPort";
  7948. /**
  7949. * The user name of the proxy server used to connect to the Cognitive Services Speech Service. Only relevant in Node.js environments.
  7950. * You shouldn't have to use this property directly.
  7951. * Instead use <see cref="SpeechConfig.SetProxy(string,int,string,string)"/>.
  7952. * Added in version 1.4.0.
  7953. */
  7954. PropertyId[PropertyId["SpeechServiceConnection_ProxyUserName"] = 13] = "SpeechServiceConnection_ProxyUserName";
  7955. /**
  7956. * The password of the proxy server used to connect to the Cognitive Services Speech Service. Only relevant in Node.js environments.
  7957. * You shouldn't have to use this property directly.
  7958. * Instead use <see cref="SpeechConfig.SetProxy(string,int,string,string)"/>.
  7959. * Added in version 1.4.0.
  7960. */
  7961. PropertyId[PropertyId["SpeechServiceConnection_ProxyPassword"] = 14] = "SpeechServiceConnection_ProxyPassword";
  7962. /**
  7963. * The Cognitive Services Speech Service recognition Mode. Can be "INTERACTIVE", "CONVERSATION", "DICTATION".
  7964. * This property is intended to be read-only. The SDK is using it internally.
  7965. * @member PropertyId.SpeechServiceConnection_RecoMode
  7966. */
  7967. PropertyId[PropertyId["SpeechServiceConnection_RecoMode"] = 15] = "SpeechServiceConnection_RecoMode";
  7968. /**
  7969. * The spoken language to be recognized (in BCP-47 format). Under normal circumstances, you shouldn't have to use this property
  7970. * directly.
  7971. * Instead, use [[SpeechConfig.speechRecognitionLanguage]].
  7972. * @member PropertyId.SpeechServiceConnection_RecoLanguage
  7973. */
  7974. PropertyId[PropertyId["SpeechServiceConnection_RecoLanguage"] = 16] = "SpeechServiceConnection_RecoLanguage";
  7975. /**
  7976. * The session id. This id is a universally unique identifier (aka UUID) representing a specific binding of an audio input stream
  7977. * and the underlying speech recognition instance to which it is bound. Under normal circumstances, you shouldn't have to use this
  7978. * property directly.
  7979. * Instead use [[SessionEventArgs.sessionId]].
  7980. * @member PropertyId.Speech_SessionId
  7981. */
  7982. PropertyId[PropertyId["Speech_SessionId"] = 17] = "Speech_SessionId";
  7983. /**
  7984. * The spoken language to be synthesized (e.g. en-US)
  7985. * @member PropertyId.SpeechServiceConnection_SynthLanguage
  7986. */
  7987. PropertyId[PropertyId["SpeechServiceConnection_SynthLanguage"] = 18] = "SpeechServiceConnection_SynthLanguage";
  7988. /**
  7989. * The name of the TTS voice to be used for speech synthesis
  7990. * @member PropertyId.SpeechServiceConnection_SynthVoice
  7991. */
  7992. PropertyId[PropertyId["SpeechServiceConnection_SynthVoice"] = 19] = "SpeechServiceConnection_SynthVoice";
  7993. /**
  7994. * The string to specify TTS output audio format
  7995. * @member PropertyId.SpeechServiceConnection_SynthOutputFormat
  7996. */
  7997. PropertyId[PropertyId["SpeechServiceConnection_SynthOutputFormat"] = 20] = "SpeechServiceConnection_SynthOutputFormat";
  7998. /**
  7999. * The list of comma separated languages used as possible source languages
  8000. * Added in version 1.13.0
  8001. * @member PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages
  8002. */
  8003. PropertyId[PropertyId["SpeechServiceConnection_AutoDetectSourceLanguages"] = 21] = "SpeechServiceConnection_AutoDetectSourceLanguages";
  8004. /**
  8005. * The requested Cognitive Services Speech Service response output format (simple or detailed). Under normal circumstances, you shouldn't have
  8006. * to use this property directly.
  8007. * Instead use [[SpeechConfig.outputFormat]].
  8008. * @member PropertyId.SpeechServiceResponse_RequestDetailedResultTrueFalse
  8009. */
  8010. PropertyId[PropertyId["SpeechServiceResponse_RequestDetailedResultTrueFalse"] = 22] = "SpeechServiceResponse_RequestDetailedResultTrueFalse";
  8011. /**
  8012. * The requested Cognitive Services Speech Service response output profanity level. Currently unused.
  8013. * @member PropertyId.SpeechServiceResponse_RequestProfanityFilterTrueFalse
  8014. */
  8015. PropertyId[PropertyId["SpeechServiceResponse_RequestProfanityFilterTrueFalse"] = 23] = "SpeechServiceResponse_RequestProfanityFilterTrueFalse";
  8016. /**
  8017. * The Cognitive Services Speech Service response output (in JSON format). This property is available on recognition result objects only.
  8018. * @member PropertyId.SpeechServiceResponse_JsonResult
  8019. */
  8020. PropertyId[PropertyId["SpeechServiceResponse_JsonResult"] = 24] = "SpeechServiceResponse_JsonResult";
  8021. /**
  8022. * The Cognitive Services Speech Service error details (in JSON format). Under normal circumstances, you shouldn't have to
  8023. * use this property directly. Instead use [[CancellationDetails.errorDetails]].
  8024. * @member PropertyId.SpeechServiceResponse_JsonErrorDetails
  8025. */
  8026. PropertyId[PropertyId["SpeechServiceResponse_JsonErrorDetails"] = 25] = "SpeechServiceResponse_JsonErrorDetails";
  8027. /**
  8028. * The cancellation reason. Currently unused.
  8029. * @member PropertyId.CancellationDetails_Reason
  8030. */
  8031. PropertyId[PropertyId["CancellationDetails_Reason"] = 26] = "CancellationDetails_Reason";
  8032. /**
  8033. * The cancellation text. Currently unused.
  8034. * @member PropertyId.CancellationDetails_ReasonText
  8035. */
  8036. PropertyId[PropertyId["CancellationDetails_ReasonText"] = 27] = "CancellationDetails_ReasonText";
  8037. /**
  8038. * The Cancellation detailed text. Currently unused.
  8039. * @member PropertyId.CancellationDetails_ReasonDetailedText
  8040. */
  8041. PropertyId[PropertyId["CancellationDetails_ReasonDetailedText"] = 28] = "CancellationDetails_ReasonDetailedText";
  8042. /**
  8043. * The Language Understanding Service response output (in JSON format). Available via [[IntentRecognitionResult]]
  8044. * @member PropertyId.LanguageUnderstandingServiceResponse_JsonResult
  8045. */
  8046. PropertyId[PropertyId["LanguageUnderstandingServiceResponse_JsonResult"] = 29] = "LanguageUnderstandingServiceResponse_JsonResult";
  8047. /**
  8048. * The URL string built from speech configuration.
  8049. * This property is intended to be read-only. The SDK is using it internally.
  8050. * NOTE: Added in version 1.7.0.
  8051. */
  8052. PropertyId[PropertyId["SpeechServiceConnection_Url"] = 30] = "SpeechServiceConnection_Url";
  8053. /**
  8054. * The initial silence timeout value (in milliseconds) used by the service.
  8055. * Added in version 1.7.0
  8056. */
  8057. PropertyId[PropertyId["SpeechServiceConnection_InitialSilenceTimeoutMs"] = 31] = "SpeechServiceConnection_InitialSilenceTimeoutMs";
  8058. /**
  8059. * The end silence timeout value (in milliseconds) used by the service.
  8060. * Added in version 1.7.0
  8061. */
  8062. PropertyId[PropertyId["SpeechServiceConnection_EndSilenceTimeoutMs"] = 32] = "SpeechServiceConnection_EndSilenceTimeoutMs";
  8063. /**
  8064. * A duration of detected silence, measured in milliseconds, after which speech-to-text will determine a spoken
  8065. * phrase has ended and generate a final Recognized result. Configuring this timeout may be helpful in situations
  8066. * where spoken input is significantly faster or slower than usual and default segmentation behavior consistently
  8067. * yields results that are too long or too short. Segmentation timeout values that are inappropriately high or low
  8068. * can negatively affect speech-to-text accuracy; this property should be carefully configured and the resulting
  8069. * behavior should be thoroughly validated as intended.
  8070. *
  8071. * For more information about timeout configuration that includes discussion of default behaviors, please visit
  8072. * https://aka.ms/csspeech/timeouts.
  8073. *
  8074. * Added in version 1.21.0.
  8075. */
  8076. PropertyId[PropertyId["Speech_SegmentationSilenceTimeoutMs"] = 33] = "Speech_SegmentationSilenceTimeoutMs";
  8077. /**
  8078. * SegmentationMaximumTimeMs represents the maximum length of a spoken phrase when using the Time segmentation strategy.
  8079. * As the length of a spoken phrase approaches this value, the @member Speech_SegmentationSilenceTimeoutMs will be reduced until either
  8080. * the phrase silence timeout is reached or the phrase reaches the maximum length.
  8081. *
  8082. * Added in version 1.42.0.
  8083. */
  8084. PropertyId[PropertyId["Speech_SegmentationMaximumTimeMs"] = 34] = "Speech_SegmentationMaximumTimeMs";
  8085. /**
  8086. * SegmentationStrategy defines the strategy used to determine when a spoken phrase has ended and a final Recognized result should be generated.
  8087. * Allowed values are "Default", "Time", and "Semantic".
  8088. *
  8089. * Valid values:
  8090. * - "Default": Uses the default strategy and settings as determined by the Speech Service. Suitable for most situations.
  8091. * - "Time": Uses a time-based strategy where the amount of silence between speech determines when to generate a final result.
  8092. * - "Semantic": Uses an AI model to determine the end of a spoken phrase based on the phrase's content.
  8093. *
  8094. * Additional Notes:
  8095. * - When using the Time strategy, @member Speech_SegmentationSilenceTimeoutMs can be adjusted to modify the required silence duration for ending a phrase,
  8096. * and @member Speech_SegmentationMaximumTimeMs can be adjusted to set the maximum length of a spoken phrase.
  8097. * - The Semantic strategy does not have any adjustable properties.
  8098. *
  8099. * Added in version 1.42.0.
  8100. */
  8101. PropertyId[PropertyId["Speech_SegmentationStrategy"] = 35] = "Speech_SegmentationStrategy";
  8102. /**
  8103. * A boolean value specifying whether audio logging is enabled in the service or not.
  8104. * Audio and content logs are stored either in Microsoft-owned storage, or in your own storage account linked
  8105. * to your Cognitive Services subscription (Bring Your Own Storage (BYOS) enabled Speech resource).
  8106. * The logs will be removed after 30 days.
  8107. * Added in version 1.7.0
  8108. */
  8109. PropertyId[PropertyId["SpeechServiceConnection_EnableAudioLogging"] = 36] = "SpeechServiceConnection_EnableAudioLogging";
  8110. /**
  8111. * The speech service connection language identifier mode.
  8112. * Can be "AtStart" (the default), or "Continuous". See Language
  8113. * Identification document https://aka.ms/speech/lid?pivots=programming-language-javascript
  8114. * for more details.
  8115. * Added in 1.25.0
  8116. **/
  8117. PropertyId[PropertyId["SpeechServiceConnection_LanguageIdMode"] = 37] = "SpeechServiceConnection_LanguageIdMode";
  8118. /**
  8119. * A string value representing the desired endpoint version to target for Speech Recognition.
  8120. * Added in version 1.21.0
  8121. */
  8122. PropertyId[PropertyId["SpeechServiceConnection_RecognitionEndpointVersion"] = 38] = "SpeechServiceConnection_RecognitionEndpointVersion";
  8123. /**
  8124. /**
  8125. * A string value the current speaker recognition scenario/mode (TextIndependentIdentification, etc.).
  8126. * Added in version 1.23.0
  8127. */
  8128. PropertyId[PropertyId["SpeechServiceConnection_SpeakerIdMode"] = 39] = "SpeechServiceConnection_SpeakerIdMode";
  8129. /**
  8130. * The requested Cognitive Services Speech Service response output profanity setting.
  8131. * Allowed values are "masked", "removed", and "raw".
  8132. * Added in version 1.7.0.
  8133. */
  8134. PropertyId[PropertyId["SpeechServiceResponse_ProfanityOption"] = 40] = "SpeechServiceResponse_ProfanityOption";
  8135. /**
  8136. * A string value specifying which post processing option should be used by service.
  8137. * Allowed values are "TrueText".
  8138. * Added in version 1.7.0
  8139. */
  8140. PropertyId[PropertyId["SpeechServiceResponse_PostProcessingOption"] = 41] = "SpeechServiceResponse_PostProcessingOption";
  8141. /**
  8142. * A boolean value specifying whether to include word-level timestamps in the response result.
  8143. * Added in version 1.7.0
  8144. */
  8145. PropertyId[PropertyId["SpeechServiceResponse_RequestWordLevelTimestamps"] = 42] = "SpeechServiceResponse_RequestWordLevelTimestamps";
  8146. /**
  8147. * The number of times a word has to be in partial results to be returned.
  8148. * Added in version 1.7.0
  8149. */
  8150. PropertyId[PropertyId["SpeechServiceResponse_StablePartialResultThreshold"] = 43] = "SpeechServiceResponse_StablePartialResultThreshold";
  8151. /**
  8152. * A string value specifying the output format option in the response result. Internal use only.
  8153. * Added in version 1.7.0.
  8154. */
  8155. PropertyId[PropertyId["SpeechServiceResponse_OutputFormatOption"] = 44] = "SpeechServiceResponse_OutputFormatOption";
  8156. /**
  8157. * A boolean value to request for stabilizing translation partial results by omitting words in the end.
  8158. * Added in version 1.7.0.
  8159. */
  8160. PropertyId[PropertyId["SpeechServiceResponse_TranslationRequestStablePartialResult"] = 45] = "SpeechServiceResponse_TranslationRequestStablePartialResult";
  8161. /**
  8162. * A boolean value specifying whether to request WordBoundary events.
  8163. * @member PropertyId.SpeechServiceResponse_RequestWordBoundary
  8164. * Added in version 1.21.0.
  8165. */
  8166. PropertyId[PropertyId["SpeechServiceResponse_RequestWordBoundary"] = 46] = "SpeechServiceResponse_RequestWordBoundary";
  8167. /**
  8168. * A boolean value specifying whether to request punctuation boundary in WordBoundary Events. Default is true.
  8169. * @member PropertyId.SpeechServiceResponse_RequestPunctuationBoundary
  8170. * Added in version 1.21.0.
  8171. */
  8172. PropertyId[PropertyId["SpeechServiceResponse_RequestPunctuationBoundary"] = 47] = "SpeechServiceResponse_RequestPunctuationBoundary";
  8173. /**
  8174. * A boolean value specifying whether to request sentence boundary in WordBoundary Events. Default is false.
  8175. * @member PropertyId.SpeechServiceResponse_RequestSentenceBoundary
  8176. * Added in version 1.21.0.
  8177. */
  8178. PropertyId[PropertyId["SpeechServiceResponse_RequestSentenceBoundary"] = 48] = "SpeechServiceResponse_RequestSentenceBoundary";
  8179. /**
  8180. * Determines if intermediate results contain speaker identification.
  8181. * Allowed values are "true" or "false". If set to "true", the intermediate results will contain speaker identification.
  8182. * The default value if unset or set to an invalid value is "false".
  8183. * This is currently only supported for scenarios using the ConversationTranscriber".
  8184. * @member PropertyId.SpeechServiceResponse_DiarizeIntermediateResults
  8185. * Adding in version 1.41.
  8186. */
  8187. PropertyId[PropertyId["SpeechServiceResponse_DiarizeIntermediateResults"] = 49] = "SpeechServiceResponse_DiarizeIntermediateResults";
  8188. /**
  8189. * Identifier used to connect to the backend service.
  8190. * @member PropertyId.Conversation_ApplicationId
  8191. */
  8192. PropertyId[PropertyId["Conversation_ApplicationId"] = 50] = "Conversation_ApplicationId";
  8193. /**
  8194. * Type of dialog backend to connect to.
  8195. * @member PropertyId.Conversation_DialogType
  8196. */
  8197. PropertyId[PropertyId["Conversation_DialogType"] = 51] = "Conversation_DialogType";
  8198. /**
  8199. * Silence timeout for listening
  8200. * @member PropertyId.Conversation_Initial_Silence_Timeout
  8201. */
  8202. PropertyId[PropertyId["Conversation_Initial_Silence_Timeout"] = 52] = "Conversation_Initial_Silence_Timeout";
  8203. /**
  8204. * From Id to add to speech recognition activities.
  8205. * @member PropertyId.Conversation_From_Id
  8206. */
  8207. PropertyId[PropertyId["Conversation_From_Id"] = 53] = "Conversation_From_Id";
  8208. /**
  8209. * ConversationId for the session.
  8210. * @member PropertyId.Conversation_Conversation_Id
  8211. */
  8212. PropertyId[PropertyId["Conversation_Conversation_Id"] = 54] = "Conversation_Conversation_Id";
  8213. /**
  8214. * Comma separated list of custom voice deployment ids.
  8215. * @member PropertyId.Conversation_Custom_Voice_Deployment_Ids
  8216. */
  8217. PropertyId[PropertyId["Conversation_Custom_Voice_Deployment_Ids"] = 55] = "Conversation_Custom_Voice_Deployment_Ids";
  8218. /**
  8219. * Speech activity template, stamp properties from the template on the activity generated by the service for speech.
  8220. * @member PropertyId.Conversation_Speech_Activity_Template
  8221. * Added in version 1.10.0.
  8222. */
  8223. PropertyId[PropertyId["Conversation_Speech_Activity_Template"] = 56] = "Conversation_Speech_Activity_Template";
  8224. /**
  8225. * Enables or disables the receipt of turn status messages as obtained on the turnStatusReceived event.
  8226. * @member PropertyId.Conversation_Request_Bot_Status_Messages
  8227. * Added in version 1.15.0.
  8228. */
  8229. PropertyId[PropertyId["Conversation_Request_Bot_Status_Messages"] = 57] = "Conversation_Request_Bot_Status_Messages";
  8230. /**
  8231. * Specifies the connection ID to be provided in the Agent configuration message, e.g. a Direct Line token for
  8232. * channel authentication.
  8233. * Added in version 1.15.1.
  8234. */
  8235. PropertyId[PropertyId["Conversation_Agent_Connection_Id"] = 58] = "Conversation_Agent_Connection_Id";
  8236. /**
  8237. * The Cognitive Services Speech Service host (url). Under normal circumstances, you shouldn't have to use this property directly.
  8238. * Instead, use [[SpeechConfig.fromHost]].
  8239. */
  8240. PropertyId[PropertyId["SpeechServiceConnection_Host"] = 59] = "SpeechServiceConnection_Host";
  8241. /**
  8242. * Set the host for service calls to the Conversation Translator REST management and websocket calls.
  8243. */
  8244. PropertyId[PropertyId["ConversationTranslator_Host"] = 60] = "ConversationTranslator_Host";
  8245. /**
  8246. * Optionally set the the host's display name.
  8247. * Used when joining a conversation.
  8248. */
  8249. PropertyId[PropertyId["ConversationTranslator_Name"] = 61] = "ConversationTranslator_Name";
  8250. /**
  8251. * Optionally set a value for the X-CorrelationId request header.
  8252. * Used for troubleshooting errors in the server logs. It should be a valid guid.
  8253. */
  8254. PropertyId[PropertyId["ConversationTranslator_CorrelationId"] = 62] = "ConversationTranslator_CorrelationId";
  8255. /**
  8256. * Set the conversation token to be sent to the speech service. This enables the
  8257. * service to service call from the speech service to the Conversation Translator service for relaying
  8258. * recognitions. For internal use.
  8259. */
  8260. PropertyId[PropertyId["ConversationTranslator_Token"] = 63] = "ConversationTranslator_Token";
  8261. /**
  8262. * The reference text of the audio for pronunciation evaluation.
  8263. * For this and the following pronunciation assessment parameters, see
  8264. * https://docs.microsoft.com/azure/cognitive-services/speech-service/rest-speech-to-text#pronunciation-assessment-parameters for details.
  8265. * Under normal circumstances, you shouldn't have to use this property directly.
  8266. * Added in version 1.15.0
  8267. */
  8268. PropertyId[PropertyId["PronunciationAssessment_ReferenceText"] = 64] = "PronunciationAssessment_ReferenceText";
  8269. /**
  8270. * The point system for pronunciation score calibration (FivePoint or HundredMark).
  8271. * Under normal circumstances, you shouldn't have to use this property directly.
  8272. * Added in version 1.15.0
  8273. */
  8274. PropertyId[PropertyId["PronunciationAssessment_GradingSystem"] = 65] = "PronunciationAssessment_GradingSystem";
  8275. /**
  8276. * The pronunciation evaluation granularity (Phoneme, Word, or FullText).
  8277. * Under normal circumstances, you shouldn't have to use this property directly.
  8278. * Added in version 1.15.0
  8279. */
  8280. PropertyId[PropertyId["PronunciationAssessment_Granularity"] = 66] = "PronunciationAssessment_Granularity";
  8281. /**
  8282. * Defines if enable miscue calculation.
  8283. * With this enabled, the pronounced words will be compared to the reference text,
  8284. * and will be marked with omission/insertion based on the comparison. The default setting is False.
  8285. * Under normal circumstances, you shouldn't have to use this property directly.
  8286. * Added in version 1.15.0
  8287. */
  8288. PropertyId[PropertyId["PronunciationAssessment_EnableMiscue"] = 67] = "PronunciationAssessment_EnableMiscue";
  8289. /**
  8290. * The json string of pronunciation assessment parameters
  8291. * Under normal circumstances, you shouldn't have to use this property directly.
  8292. * Added in version 1.15.0
  8293. */
  8294. PropertyId[PropertyId["PronunciationAssessment_Json"] = 68] = "PronunciationAssessment_Json";
  8295. /**
  8296. * Pronunciation assessment parameters.
  8297. * This property is intended to be read-only. The SDK is using it internally.
  8298. * Added in version 1.15.0
  8299. */
  8300. PropertyId[PropertyId["PronunciationAssessment_Params"] = 69] = "PronunciationAssessment_Params";
  8301. /**
  8302. * Version of Speaker Recognition API to use.
  8303. * Added in version 1.18.0
  8304. */
  8305. PropertyId[PropertyId["SpeakerRecognition_Api_Version"] = 70] = "SpeakerRecognition_Api_Version";
  8306. /**
  8307. * Specifies whether to allow load of data URL for web worker
  8308. * Allowed values are "off" and "on". Default is "on".
  8309. * Added in version 1.32.0
  8310. */
  8311. PropertyId[PropertyId["WebWorkerLoadType"] = 71] = "WebWorkerLoadType";
  8312. /**
  8313. * Talking avatar service WebRTC session description protocol.
  8314. * This property is intended to be read-only. The SDK is using it internally.
  8315. * Added in version 1.33.0
  8316. */
  8317. PropertyId[PropertyId["TalkingAvatarService_WebRTC_SDP"] = 72] = "TalkingAvatarService_WebRTC_SDP";
  8318. })(PropertyId = exports.PropertyId || (exports.PropertyId = {}));
  8319. /***/ }),
  8320. /* 111 */
  8321. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8322. "use strict";
  8323. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8324. exports.Recognizer = void 0;
  8325. const Exports_js_1 = __webpack_require__(2);
  8326. const Exports_js_2 = __webpack_require__(4);
  8327. const Contracts_js_1 = __webpack_require__(64);
  8328. const Exports_js_3 = __webpack_require__(79);
  8329. /**
  8330. * Defines the base class Recognizer which mainly contains common event handlers.
  8331. * @class Recognizer
  8332. */
  8333. class Recognizer {
  8334. /**
  8335. * Creates and initializes an instance of a Recognizer
  8336. * @constructor
  8337. * @param {AudioConfig} audioInput - An optional audio input stream associated with the recognizer
  8338. * @param {PropertyCollection} properties - A set of properties to set on the recognizer
  8339. * @param {IConnectionFactory} connectionFactory - The factory class used to create a custom IConnection for the recognizer
  8340. */
  8341. constructor(audioConfig, properties, connectionFactory, tokenCredential) {
  8342. this.audioConfig = (audioConfig !== undefined) ? audioConfig : Exports_js_3.AudioConfig.fromDefaultMicrophoneInput();
  8343. this.privDisposed = false;
  8344. this.privProperties = properties.clone();
  8345. this.privConnectionFactory = connectionFactory;
  8346. this.tokenCredential = tokenCredential;
  8347. this.implCommonRecognizerSetup();
  8348. }
  8349. /**
  8350. * Dispose of associated resources.
  8351. * @member Recognizer.prototype.close
  8352. * @function
  8353. * @public
  8354. */
  8355. close(cb, errorCb) {
  8356. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);
  8357. (0, Exports_js_2.marshalPromiseToCallbacks)(this.dispose(true), cb, errorCb);
  8358. }
  8359. /**
  8360. * @Internal
  8361. * Internal data member to support fromRecognizer* pattern methods on other classes.
  8362. * Do not use externally, object returned will change without warning or notice.
  8363. */
  8364. get internalData() {
  8365. return this.privReco;
  8366. }
  8367. /**
  8368. * This method performs cleanup of resources.
  8369. * The Boolean parameter disposing indicates whether the method is called
  8370. * from Dispose (if disposing is true) or from the finalizer (if disposing is false).
  8371. * Derived classes should override this method to dispose resource if needed.
  8372. * @member Recognizer.prototype.dispose
  8373. * @function
  8374. * @public
  8375. * @param {boolean} disposing - Flag to request disposal.
  8376. */
  8377. async dispose(disposing) {
  8378. if (this.privDisposed) {
  8379. return;
  8380. }
  8381. this.privDisposed = true;
  8382. if (disposing) {
  8383. if (this.privReco) {
  8384. await this.privReco.audioSource.turnOff();
  8385. await this.privReco.dispose();
  8386. }
  8387. }
  8388. }
  8389. /**
  8390. * This method returns the current state of the telemetry setting.
  8391. * @member Recognizer.prototype.telemetryEnabled
  8392. * @function
  8393. * @public
  8394. * @returns true if the telemetry is enabled, false otherwise.
  8395. */
  8396. static get telemetryEnabled() {
  8397. return Exports_js_1.ServiceRecognizerBase.telemetryDataEnabled;
  8398. }
  8399. /**
  8400. * This method globally enables or disables telemetry.
  8401. * @member Recognizer.prototype.enableTelemetry
  8402. * @function
  8403. * @public
  8404. * @param enabled - Global setting for telemetry collection.
  8405. * If set to true, telemetry information like microphone errors,
  8406. * recognition errors are collected and sent to Microsoft.
  8407. * If set to false, no telemetry is sent to Microsoft.
  8408. */
  8409. static enableTelemetry(enabled) {
  8410. Exports_js_1.ServiceRecognizerBase.telemetryDataEnabled = enabled;
  8411. }
  8412. // Does the generic recognizer setup that is common across all recognizer types.
  8413. implCommonRecognizerSetup() {
  8414. let osPlatform = (typeof window !== "undefined") ? "Browser" : "Node";
  8415. let osName = "unknown";
  8416. let osVersion = "unknown";
  8417. if (typeof navigator !== "undefined") {
  8418. osPlatform = osPlatform + "/" + navigator.platform;
  8419. osName = navigator.userAgent;
  8420. osVersion = navigator.appVersion;
  8421. }
  8422. const recognizerConfig = this.createRecognizerConfig(new Exports_js_1.SpeechServiceConfig(new Exports_js_1.Context(new Exports_js_1.OS(osPlatform, osName, osVersion))));
  8423. this.privReco = this.createServiceRecognizer(Recognizer.getAuth(this.privProperties, this.tokenCredential), this.privConnectionFactory, this.audioConfig, recognizerConfig);
  8424. }
  8425. async recognizeOnceAsyncImpl(recognitionMode) {
  8426. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);
  8427. const ret = new Exports_js_2.Deferred();
  8428. await this.implRecognizerStop();
  8429. await this.privReco.recognize(recognitionMode, ret.resolve, ret.reject);
  8430. const result = await ret.promise;
  8431. await this.implRecognizerStop();
  8432. return result;
  8433. }
  8434. async startContinuousRecognitionAsyncImpl(recognitionMode) {
  8435. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);
  8436. await this.implRecognizerStop();
  8437. await this.privReco.recognize(recognitionMode, undefined, undefined);
  8438. }
  8439. async stopContinuousRecognitionAsyncImpl() {
  8440. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);
  8441. await this.implRecognizerStop();
  8442. }
  8443. async implRecognizerStop() {
  8444. if (this.privReco) {
  8445. await this.privReco.stopRecognizing();
  8446. }
  8447. return;
  8448. }
  8449. static getAuth(properties, tokenCredential) {
  8450. const subscriptionKey = properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Key, undefined);
  8451. if (subscriptionKey && subscriptionKey !== "") {
  8452. return new Exports_js_1.CognitiveSubscriptionKeyAuthentication(subscriptionKey);
  8453. }
  8454. if (tokenCredential) {
  8455. return new Exports_js_1.CognitiveTokenAuthentication(async () => {
  8456. try {
  8457. const tokenResponse = await tokenCredential.getToken("https://cognitiveservices.azure.com/.default");
  8458. return tokenResponse?.token ?? "";
  8459. }
  8460. catch (err) {
  8461. throw err;
  8462. }
  8463. }, async () => {
  8464. try {
  8465. const tokenResponse = await tokenCredential.getToken("https://cognitiveservices.azure.com/.default");
  8466. return tokenResponse?.token ?? "";
  8467. }
  8468. catch (err) {
  8469. throw err;
  8470. }
  8471. });
  8472. }
  8473. return new Exports_js_1.CognitiveTokenAuthentication(() => {
  8474. const authorizationToken = properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, undefined);
  8475. return Promise.resolve(authorizationToken);
  8476. }, () => {
  8477. const authorizationToken = properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, undefined);
  8478. return Promise.resolve(authorizationToken);
  8479. });
  8480. }
  8481. }
  8482. exports.Recognizer = Recognizer;
  8483. /***/ }),
  8484. /* 112 */
  8485. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8486. "use strict";
  8487. // Copyright (c) Microsoft Corporation. All rights reserved.
  8488. // Licensed under the MIT license.
  8489. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8490. exports.SpeechRecognizer = void 0;
  8491. const Exports_js_1 = __webpack_require__(2);
  8492. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  8493. const Exports_js_2 = __webpack_require__(4);
  8494. const Contracts_js_1 = __webpack_require__(64);
  8495. const Exports_js_3 = __webpack_require__(79);
  8496. /**
  8497. * Performs speech recognition from microphone, file, or other audio input streams, and gets transcribed text as result.
  8498. * @class SpeechRecognizer
  8499. */
  8500. class SpeechRecognizer extends Exports_js_3.Recognizer {
  8501. /**
  8502. * SpeechRecognizer constructor.
  8503. * @constructor
  8504. * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer
  8505. * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer
  8506. */
  8507. constructor(speechConfig, audioConfig) {
  8508. const speechConfigImpl = speechConfig;
  8509. Contracts_js_1.Contracts.throwIfNull(speechConfigImpl, "speechConfig");
  8510. Contracts_js_1.Contracts.throwIfNullOrWhitespace(speechConfigImpl.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage), Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage]);
  8511. super(audioConfig, speechConfigImpl.properties, new Exports_js_1.SpeechConnectionFactory(), speechConfig.tokenCredential);
  8512. this.privDisposedRecognizer = false;
  8513. }
  8514. /**
  8515. * SpeechRecognizer constructor.
  8516. * @constructor
  8517. * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer
  8518. * @param {AutoDetectSourceLanguageConfig} autoDetectSourceLanguageConfig - An source language detection configuration associated with the recognizer
  8519. * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer
  8520. */
  8521. static FromConfig(speechConfig, autoDetectSourceLanguageConfig, audioConfig) {
  8522. const speechConfigImpl = speechConfig;
  8523. autoDetectSourceLanguageConfig.properties.mergeTo(speechConfigImpl.properties);
  8524. const recognizer = new SpeechRecognizer(speechConfig, audioConfig);
  8525. return recognizer;
  8526. }
  8527. /**
  8528. * Gets the endpoint id of a customized speech model that is used for speech recognition.
  8529. * @member SpeechRecognizer.prototype.endpointId
  8530. * @function
  8531. * @public
  8532. * @returns {string} the endpoint id of a customized speech model that is used for speech recognition.
  8533. */
  8534. get endpointId() {
  8535. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  8536. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_EndpointId, "00000000-0000-0000-0000-000000000000");
  8537. }
  8538. /**
  8539. * Gets the authorization token used to communicate with the service.
  8540. * @member SpeechRecognizer.prototype.authorizationToken
  8541. * @function
  8542. * @public
  8543. * @returns {string} Authorization token.
  8544. */
  8545. get authorizationToken() {
  8546. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token);
  8547. }
  8548. /**
  8549. * Gets/Sets the authorization token used to communicate with the service.
  8550. * @member SpeechRecognizer.prototype.authorizationToken
  8551. * @function
  8552. * @public
  8553. * @param {string} token - Authorization token.
  8554. */
  8555. set authorizationToken(token) {
  8556. Contracts_js_1.Contracts.throwIfNullOrWhitespace(token, "token");
  8557. this.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, token);
  8558. }
  8559. /**
  8560. * Gets the spoken language of recognition.
  8561. * @member SpeechRecognizer.prototype.speechRecognitionLanguage
  8562. * @function
  8563. * @public
  8564. * @returns {string} The spoken language of recognition.
  8565. */
  8566. get speechRecognitionLanguage() {
  8567. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  8568. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage);
  8569. }
  8570. /**
  8571. * Gets the output format of recognition.
  8572. * @member SpeechRecognizer.prototype.outputFormat
  8573. * @function
  8574. * @public
  8575. * @returns {OutputFormat} The output format of recognition.
  8576. */
  8577. get outputFormat() {
  8578. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  8579. if (this.properties.getProperty(Exports_js_1.OutputFormatPropertyName, Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Simple]) === Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Simple]) {
  8580. return Exports_js_3.OutputFormat.Simple;
  8581. }
  8582. else {
  8583. return Exports_js_3.OutputFormat.Detailed;
  8584. }
  8585. }
  8586. /**
  8587. * The collection of properties and their values defined for this SpeechRecognizer.
  8588. * @member SpeechRecognizer.prototype.properties
  8589. * @function
  8590. * @public
  8591. * @returns {PropertyCollection} The collection of properties and their values defined for this SpeechRecognizer.
  8592. */
  8593. get properties() {
  8594. return this.privProperties;
  8595. }
  8596. /**
  8597. * Starts speech recognition, and stops after the first utterance is recognized.
  8598. * The task returns the recognition text as result.
  8599. * Note: RecognizeOnceAsync() returns when the first utterance has been recognized,
  8600. * so it is suitable only for single shot recognition
  8601. * like command or query. For long-running recognition, use StartContinuousRecognitionAsync() instead.
  8602. * @member SpeechRecognizer.prototype.recognizeOnceAsync
  8603. * @function
  8604. * @public
  8605. * @param cb - Callback that received the SpeechRecognitionResult.
  8606. * @param err - Callback invoked in case of an error.
  8607. */
  8608. recognizeOnceAsync(cb, err) {
  8609. (0, Exports_js_2.marshalPromiseToCallbacks)(this.recognizeOnceAsyncImpl(PhraseDetectionContext_js_1.RecognitionMode.Interactive), cb, err);
  8610. }
  8611. /**
  8612. * Starts speech recognition, until stopContinuousRecognitionAsync() is called.
  8613. * User must subscribe to events to receive recognition results.
  8614. * @member SpeechRecognizer.prototype.startContinuousRecognitionAsync
  8615. * @function
  8616. * @public
  8617. * @param cb - Callback invoked once the recognition has started.
  8618. * @param err - Callback invoked in case of an error.
  8619. */
  8620. startContinuousRecognitionAsync(cb, err) {
  8621. (0, Exports_js_2.marshalPromiseToCallbacks)(this.startContinuousRecognitionAsyncImpl(PhraseDetectionContext_js_1.RecognitionMode.Conversation), cb, err);
  8622. }
  8623. /**
  8624. * Stops continuous speech recognition.
  8625. * @member SpeechRecognizer.prototype.stopContinuousRecognitionAsync
  8626. * @function
  8627. * @public
  8628. * @param cb - Callback invoked once the recognition has stopped.
  8629. * @param err - Callback invoked in case of an error.
  8630. */
  8631. stopContinuousRecognitionAsync(cb, err) {
  8632. (0, Exports_js_2.marshalPromiseToCallbacks)(this.stopContinuousRecognitionAsyncImpl(), cb, err);
  8633. }
  8634. /**
  8635. * Starts speech recognition with keyword spotting, until
  8636. * stopKeywordRecognitionAsync() is called.
  8637. * User must subscribe to events to receive recognition results.
  8638. * Note: Key word spotting functionality is only available on the
  8639. * Speech Devices SDK. This functionality is currently not included in the SDK itself.
  8640. * @member SpeechRecognizer.prototype.startKeywordRecognitionAsync
  8641. * @function
  8642. * @public
  8643. * @param {KeywordRecognitionModel} model The keyword recognition model that
  8644. * specifies the keyword to be recognized.
  8645. * @param cb - Callback invoked once the recognition has started.
  8646. * @param err - Callback invoked in case of an error.
  8647. */
  8648. startKeywordRecognitionAsync(model, cb, err) {
  8649. Contracts_js_1.Contracts.throwIfNull(model, "model");
  8650. if (!!err) {
  8651. err("Not yet implemented.");
  8652. }
  8653. }
  8654. /**
  8655. * Stops continuous speech recognition.
  8656. * Note: Key word spotting functionality is only available on the
  8657. * Speech Devices SDK. This functionality is currently not included in the SDK itself.
  8658. * @member SpeechRecognizer.prototype.stopKeywordRecognitionAsync
  8659. * @function
  8660. * @public
  8661. * @param cb - Callback invoked once the recognition has stopped.
  8662. * @param err - Callback invoked in case of an error.
  8663. */
  8664. stopKeywordRecognitionAsync(cb) {
  8665. if (!!cb) {
  8666. cb();
  8667. }
  8668. }
  8669. /**
  8670. * closes all external resources held by an instance of this class.
  8671. * @member SpeechRecognizer.prototype.close
  8672. * @function
  8673. * @public
  8674. */
  8675. close(cb, errorCb) {
  8676. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  8677. (0, Exports_js_2.marshalPromiseToCallbacks)(this.dispose(true), cb, errorCb);
  8678. }
  8679. /**
  8680. * Disposes any resources held by the object.
  8681. * @member SpeechRecognizer.prototype.dispose
  8682. * @function
  8683. * @public
  8684. * @param {boolean} disposing - true if disposing the object.
  8685. */
  8686. async dispose(disposing) {
  8687. if (this.privDisposedRecognizer) {
  8688. return;
  8689. }
  8690. if (disposing) {
  8691. this.privDisposedRecognizer = true;
  8692. await this.implRecognizerStop();
  8693. }
  8694. await super.dispose(disposing);
  8695. }
  8696. createRecognizerConfig(speechConfig) {
  8697. return new Exports_js_1.RecognizerConfig(speechConfig, this.privProperties);
  8698. }
  8699. createServiceRecognizer(authentication, connectionFactory, audioConfig, recognizerConfig) {
  8700. const configImpl = audioConfig;
  8701. return new Exports_js_1.SpeechServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);
  8702. }
  8703. }
  8704. exports.SpeechRecognizer = SpeechRecognizer;
  8705. /***/ }),
  8706. /* 113 */
  8707. /***/ ((__unused_webpack_module, exports) => {
  8708. "use strict";
  8709. //
  8710. // Copyright (c) Microsoft. All rights reserved.
  8711. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  8712. //
  8713. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8714. exports.RecognitionMode = void 0;
  8715. /**
  8716. * The Recognition modes
  8717. */
  8718. var RecognitionMode;
  8719. (function (RecognitionMode) {
  8720. RecognitionMode["Interactive"] = "Interactive";
  8721. RecognitionMode["Dictation"] = "Dictation";
  8722. RecognitionMode["Conversation"] = "Conversation";
  8723. RecognitionMode["None"] = "None";
  8724. })(RecognitionMode = exports.RecognitionMode || (exports.RecognitionMode = {}));
  8725. /***/ }),
  8726. /* 114 */
  8727. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8728. "use strict";
  8729. // Copyright (c) Microsoft Corporation. All rights reserved.
  8730. // Licensed under the MIT license.
  8731. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8732. exports.IntentRecognizer = void 0;
  8733. const Exports_js_1 = __webpack_require__(2);
  8734. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  8735. const Exports_js_2 = __webpack_require__(4);
  8736. const Contracts_js_1 = __webpack_require__(64);
  8737. const Exports_js_3 = __webpack_require__(79);
  8738. /**
  8739. * Intent recognizer.
  8740. * @class
  8741. */
  8742. class IntentRecognizer extends Exports_js_3.Recognizer {
  8743. /**
  8744. * Initializes an instance of the IntentRecognizer.
  8745. * @constructor
  8746. * @param {SpeechConfig} speechConfig - The set of configuration properties.
  8747. * @param {AudioConfig} audioConfig - An optional audio input config associated with the recognizer
  8748. */
  8749. constructor(speechConfig, audioConfig) {
  8750. Contracts_js_1.Contracts.throwIfNullOrUndefined(speechConfig, "speechConfig");
  8751. const configImpl = speechConfig;
  8752. Contracts_js_1.Contracts.throwIfNullOrUndefined(configImpl, "speechConfig");
  8753. super(audioConfig, configImpl.properties, new Exports_js_1.IntentConnectionFactory());
  8754. this.privAddedIntents = [];
  8755. this.privAddedLmIntents = {};
  8756. this.privDisposedIntentRecognizer = false;
  8757. this.privProperties = configImpl.properties;
  8758. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage), Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage]);
  8759. }
  8760. /**
  8761. * Gets the spoken language of recognition.
  8762. * @member IntentRecognizer.prototype.speechRecognitionLanguage
  8763. * @function
  8764. * @public
  8765. * @returns {string} the spoken language of recognition.
  8766. */
  8767. get speechRecognitionLanguage() {
  8768. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedIntentRecognizer);
  8769. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage);
  8770. }
  8771. /**
  8772. * Gets the authorization token used to communicate with the service.
  8773. * @member IntentRecognizer.prototype.authorizationToken
  8774. * @function
  8775. * @public
  8776. * @returns {string} Authorization token.
  8777. */
  8778. get authorizationToken() {
  8779. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token);
  8780. }
  8781. /**
  8782. * Gets/Sets the authorization token used to communicate with the service.
  8783. * Note: Please use a token derived from your LanguageUnderstanding subscription key for the Intent recognizer.
  8784. * @member IntentRecognizer.prototype.authorizationToken
  8785. * @function
  8786. * @public
  8787. * @param {string} value - Authorization token.
  8788. */
  8789. set authorizationToken(value) {
  8790. this.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, value);
  8791. }
  8792. /**
  8793. * The collection of properties and their values defined for this IntentRecognizer.
  8794. * @member IntentRecognizer.prototype.properties
  8795. * @function
  8796. * @public
  8797. * @returns {PropertyCollection} The collection of properties and their
  8798. * values defined for this IntentRecognizer.
  8799. */
  8800. get properties() {
  8801. return this.privProperties;
  8802. }
  8803. /**
  8804. * Starts intent recognition, and stops after the first utterance is recognized.
  8805. * The task returns the recognition text and intent as result.
  8806. * Note: RecognizeOnceAsync() returns when the first utterance has been recognized,
  8807. * so it is suitable only for single shot recognition like command or query.
  8808. * For long-running recognition, use StartContinuousRecognitionAsync() instead.
  8809. * @member IntentRecognizer.prototype.recognizeOnceAsync
  8810. * @function
  8811. * @public
  8812. * @param cb - Callback that received the recognition has finished with an IntentRecognitionResult.
  8813. * @param err - Callback invoked in case of an error.
  8814. */
  8815. recognizeOnceAsync(cb, err) {
  8816. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedIntentRecognizer);
  8817. if (Object.keys(this.privAddedLmIntents).length !== 0 || undefined !== this.privUmbrellaIntent) {
  8818. const context = this.buildSpeechContext();
  8819. this.privReco.speechContext.getContext().intent = context.Intent;
  8820. this.privReco.dynamicGrammar.addReferenceGrammar(context.ReferenceGrammars);
  8821. const intentReco = this.privReco;
  8822. intentReco.setIntents(this.privAddedLmIntents, this.privUmbrellaIntent);
  8823. }
  8824. (0, Exports_js_2.marshalPromiseToCallbacks)(this.recognizeOnceAsyncImpl(PhraseDetectionContext_js_1.RecognitionMode.Interactive), cb, err);
  8825. }
  8826. /**
  8827. * Starts speech recognition, until stopContinuousRecognitionAsync() is called.
  8828. * User must subscribe to events to receive recognition results.
  8829. * @member IntentRecognizer.prototype.startContinuousRecognitionAsync
  8830. * @function
  8831. * @public
  8832. * @param cb - Callback invoked once the recognition has started.
  8833. * @param err - Callback invoked in case of an error.
  8834. */
  8835. startContinuousRecognitionAsync(cb, err) {
  8836. if (Object.keys(this.privAddedLmIntents).length !== 0 || undefined !== this.privUmbrellaIntent) {
  8837. const context = this.buildSpeechContext();
  8838. this.privReco.speechContext.getContext().intent = context.Intent;
  8839. this.privReco.dynamicGrammar.addReferenceGrammar(context.ReferenceGrammars);
  8840. const intentReco = this.privReco;
  8841. intentReco.setIntents(this.privAddedLmIntents, this.privUmbrellaIntent);
  8842. }
  8843. (0, Exports_js_2.marshalPromiseToCallbacks)(this.startContinuousRecognitionAsyncImpl(PhraseDetectionContext_js_1.RecognitionMode.Conversation), cb, err);
  8844. }
  8845. /**
  8846. * Stops continuous intent recognition.
  8847. * @member IntentRecognizer.prototype.stopContinuousRecognitionAsync
  8848. * @function
  8849. * @public
  8850. * @param cb - Callback invoked once the recognition has stopped.
  8851. * @param err - Callback invoked in case of an error.
  8852. */
  8853. stopContinuousRecognitionAsync(cb, err) {
  8854. (0, Exports_js_2.marshalPromiseToCallbacks)(this.stopContinuousRecognitionAsyncImpl(), cb, err);
  8855. }
  8856. /**
  8857. * Starts speech recognition with keyword spotting, until stopKeywordRecognitionAsync() is called.
  8858. * User must subscribe to events to receive recognition results.
  8859. * Note: Key word spotting functionality is only available on the Speech Devices SDK.
  8860. * This functionality is currently not included in the SDK itself.
  8861. * @member IntentRecognizer.prototype.startKeywordRecognitionAsync
  8862. * @function
  8863. * @public
  8864. * @param {KeywordRecognitionModel} model - The keyword recognition model that specifies the keyword to be recognized.
  8865. * @param cb - Callback invoked once the recognition has started.
  8866. * @param err - Callback invoked in case of an error.
  8867. */
  8868. startKeywordRecognitionAsync(model, cb, err) {
  8869. Contracts_js_1.Contracts.throwIfNull(model, "model");
  8870. if (!!err) {
  8871. err("Not yet implemented.");
  8872. }
  8873. }
  8874. /**
  8875. * Stops continuous speech recognition.
  8876. * Note: Key word spotting functionality is only available on the Speech Devices SDK.
  8877. * This functionality is currently not included in the SDK itself.
  8878. * @member IntentRecognizer.prototype.stopKeywordRecognitionAsync
  8879. * @function
  8880. * @public
  8881. * @param cb - Callback invoked once the recognition has stopped.
  8882. * @param err - Callback invoked in case of an error.
  8883. */
  8884. stopKeywordRecognitionAsync(cb, err) {
  8885. if (!!cb) {
  8886. try {
  8887. cb();
  8888. }
  8889. catch (e) {
  8890. if (!!err) {
  8891. err(e);
  8892. }
  8893. }
  8894. }
  8895. }
  8896. /**
  8897. * Adds a phrase that should be recognized as intent.
  8898. * @member IntentRecognizer.prototype.addIntent
  8899. * @function
  8900. * @public
  8901. * @param {string} intentId - A String that represents the identifier of the intent to be recognized.
  8902. * @param {string} phrase - A String that specifies the phrase representing the intent.
  8903. */
  8904. addIntent(simplePhrase, intentId) {
  8905. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedIntentRecognizer);
  8906. Contracts_js_1.Contracts.throwIfNullOrWhitespace(intentId, "intentId");
  8907. Contracts_js_1.Contracts.throwIfNullOrWhitespace(simplePhrase, "simplePhrase");
  8908. this.privAddedIntents.push([intentId, simplePhrase]);
  8909. }
  8910. /**
  8911. * Adds an intent from Language Understanding service for recognition.
  8912. * @member IntentRecognizer.prototype.addIntentWithLanguageModel
  8913. * @function
  8914. * @public
  8915. * @param {string} intentId - A String that represents the identifier of the intent
  8916. * to be recognized. Ignored if intentName is empty.
  8917. * @param {string} model - The intent model from Language Understanding service.
  8918. * @param {string} intentName - The intent name defined in the intent model. If it
  8919. * is empty, all intent names defined in the model will be added.
  8920. */
  8921. addIntentWithLanguageModel(intentId, model, intentName) {
  8922. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedIntentRecognizer);
  8923. Contracts_js_1.Contracts.throwIfNullOrWhitespace(intentId, "intentId");
  8924. Contracts_js_1.Contracts.throwIfNull(model, "model");
  8925. const modelImpl = model;
  8926. Contracts_js_1.Contracts.throwIfNullOrWhitespace(modelImpl.appId, "model.appId");
  8927. this.privAddedLmIntents[intentId] = new Exports_js_1.AddedLmIntent(modelImpl, intentName);
  8928. }
  8929. /**
  8930. * @summary Adds all intents from the specified Language Understanding Model.
  8931. * @member IntentRecognizer.prototype.addAllIntents
  8932. * @function
  8933. * @public
  8934. * @function
  8935. * @public
  8936. * @param {LanguageUnderstandingModel} model - The language understanding model containing the intents.
  8937. * @param {string} intentId - A custom id String to be returned in the IntentRecognitionResult's getIntentId() method.
  8938. */
  8939. addAllIntents(model, intentId) {
  8940. Contracts_js_1.Contracts.throwIfNull(model, "model");
  8941. const modelImpl = model;
  8942. Contracts_js_1.Contracts.throwIfNullOrWhitespace(modelImpl.appId, "model.appId");
  8943. this.privUmbrellaIntent = new Exports_js_1.AddedLmIntent(modelImpl, intentId);
  8944. }
  8945. /**
  8946. * closes all external resources held by an instance of this class.
  8947. * @member IntentRecognizer.prototype.close
  8948. * @function
  8949. * @public
  8950. */
  8951. close(cb, errorCb) {
  8952. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedIntentRecognizer);
  8953. (0, Exports_js_2.marshalPromiseToCallbacks)(this.dispose(true), cb, errorCb);
  8954. }
  8955. createRecognizerConfig(speechConfig) {
  8956. return new Exports_js_1.RecognizerConfig(speechConfig, this.privProperties);
  8957. }
  8958. createServiceRecognizer(authentication, connectionFactory, audioConfig, recognizerConfig) {
  8959. const audioImpl = audioConfig;
  8960. return new Exports_js_1.IntentServiceRecognizer(authentication, connectionFactory, audioImpl, recognizerConfig, this);
  8961. }
  8962. async dispose(disposing) {
  8963. if (this.privDisposedIntentRecognizer) {
  8964. return;
  8965. }
  8966. if (disposing) {
  8967. this.privDisposedIntentRecognizer = true;
  8968. await super.dispose(disposing);
  8969. }
  8970. }
  8971. buildSpeechContext() {
  8972. let appId;
  8973. let region;
  8974. let subscriptionKey;
  8975. const refGrammers = [];
  8976. if (undefined !== this.privUmbrellaIntent) {
  8977. appId = this.privUmbrellaIntent.modelImpl.appId;
  8978. region = this.privUmbrellaIntent.modelImpl.region;
  8979. subscriptionKey = this.privUmbrellaIntent.modelImpl.subscriptionKey;
  8980. }
  8981. // Build the reference grammer array.
  8982. for (const intentId of Object.keys(this.privAddedLmIntents)) {
  8983. const addedLmIntent = this.privAddedLmIntents[intentId];
  8984. // validate all the same model, region, and key...
  8985. if (appId === undefined) {
  8986. appId = addedLmIntent.modelImpl.appId;
  8987. }
  8988. else {
  8989. if (appId !== addedLmIntent.modelImpl.appId) {
  8990. throw new Error("Intents must all be from the same LUIS model");
  8991. }
  8992. }
  8993. if (region === undefined) {
  8994. region = addedLmIntent.modelImpl.region;
  8995. }
  8996. else {
  8997. if (region !== addedLmIntent.modelImpl.region) {
  8998. throw new Error("Intents must all be from the same LUIS model in a single region");
  8999. }
  9000. }
  9001. if (subscriptionKey === undefined) {
  9002. subscriptionKey = addedLmIntent.modelImpl.subscriptionKey;
  9003. }
  9004. else {
  9005. if (subscriptionKey !== addedLmIntent.modelImpl.subscriptionKey) {
  9006. throw new Error("Intents must all use the same subscription key");
  9007. }
  9008. }
  9009. const grammer = "luis/" + appId + "-PRODUCTION#" + intentId;
  9010. refGrammers.push(grammer);
  9011. }
  9012. return {
  9013. Intent: {
  9014. id: appId,
  9015. key: (subscriptionKey === undefined) ? this.privProperties.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_Key]) : subscriptionKey,
  9016. provider: "LUIS",
  9017. },
  9018. ReferenceGrammars: (undefined === this.privUmbrellaIntent) ? refGrammers : ["luis/" + appId + "-PRODUCTION"],
  9019. };
  9020. }
  9021. }
  9022. exports.IntentRecognizer = IntentRecognizer;
  9023. /***/ }),
  9024. /* 115 */
  9025. /***/ ((__unused_webpack_module, exports) => {
  9026. "use strict";
  9027. // Copyright (c) Microsoft Corporation. All rights reserved.
  9028. // Licensed under the MIT license.
  9029. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9030. exports.VoiceProfileType = void 0;
  9031. /**
  9032. * Output format
  9033. * @class VoiceProfileType
  9034. */
  9035. var VoiceProfileType;
  9036. (function (VoiceProfileType) {
  9037. /**
  9038. * Text independent speaker identification
  9039. * @member VoiceProfileType.TextIndependentIdentification
  9040. */
  9041. VoiceProfileType[VoiceProfileType["TextIndependentIdentification"] = 0] = "TextIndependentIdentification";
  9042. /**
  9043. * Text dependent speaker verification
  9044. * @member VoiceProfileType.TextDependentVerification
  9045. */
  9046. VoiceProfileType[VoiceProfileType["TextDependentVerification"] = 1] = "TextDependentVerification";
  9047. /**
  9048. * Text independent speaker verification
  9049. * @member VoiceProfileType.TextIndependentVerification
  9050. */
  9051. VoiceProfileType[VoiceProfileType["TextIndependentVerification"] = 2] = "TextIndependentVerification";
  9052. })(VoiceProfileType = exports.VoiceProfileType || (exports.VoiceProfileType = {}));
  9053. /***/ }),
  9054. /* 116 */
  9055. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9056. "use strict";
  9057. // Copyright (c) Microsoft Corporation. All rights reserved.
  9058. // Licensed under the MIT license.
  9059. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9060. exports.TranslationRecognizer = void 0;
  9061. const Exports_js_1 = __webpack_require__(2);
  9062. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  9063. const Exports_js_2 = __webpack_require__(4);
  9064. const Connection_js_1 = __webpack_require__(117);
  9065. const Contracts_js_1 = __webpack_require__(64);
  9066. const Exports_js_3 = __webpack_require__(79);
  9067. /**
  9068. * Translation recognizer
  9069. * @class TranslationRecognizer
  9070. */
  9071. class TranslationRecognizer extends Exports_js_3.Recognizer {
  9072. /**
  9073. * Initializes an instance of the TranslationRecognizer.
  9074. * @constructor
  9075. * @param {SpeechTranslationConfig} speechConfig - Set of properties to configure this recognizer.
  9076. * @param {AudioConfig} audioConfig - An optional audio config associated with the recognizer
  9077. * @param {IConnectionFactory} connectionFactory - An optional connection factory to use to generate the endpoint URIs, headers to set, etc...
  9078. */
  9079. constructor(speechConfig, audioConfig, connectionFactory) {
  9080. const configImpl = speechConfig;
  9081. Contracts_js_1.Contracts.throwIfNull(configImpl, "speechConfig");
  9082. super(audioConfig, configImpl.properties, connectionFactory || new Exports_js_1.TranslationConnectionFactory(), speechConfig.tokenCredential);
  9083. this.privDisposedTranslationRecognizer = false;
  9084. if (this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationVoice, undefined) !== undefined) {
  9085. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationVoice), Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_TranslationVoice]);
  9086. }
  9087. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages), Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages]);
  9088. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage), Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage]);
  9089. }
  9090. /**
  9091. * TranslationRecognizer constructor.
  9092. * @constructor
  9093. * @param {SpeechTranslationConfig} speechTranslationConfig - an set of initial properties for this recognizer
  9094. * @param {AutoDetectSourceLanguageConfig} autoDetectSourceLanguageConfig - An source language detection configuration associated with the recognizer
  9095. * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer
  9096. */
  9097. static FromConfig(speechTranslationConfig, autoDetectSourceLanguageConfig, audioConfig) {
  9098. const speechTranslationConfigImpl = speechTranslationConfig;
  9099. autoDetectSourceLanguageConfig.properties.mergeTo(speechTranslationConfigImpl.properties);
  9100. if (autoDetectSourceLanguageConfig.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages, undefined) === Exports_js_1.AutoDetectSourceLanguagesOpenRangeOptionName) {
  9101. speechTranslationConfigImpl.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage, "en-US");
  9102. }
  9103. return new TranslationRecognizer(speechTranslationConfig, audioConfig);
  9104. }
  9105. /**
  9106. * Gets the language name that was set when the recognizer was created.
  9107. * @member TranslationRecognizer.prototype.speechRecognitionLanguage
  9108. * @function
  9109. * @public
  9110. * @returns {string} Gets the language name that was set when the recognizer was created.
  9111. */
  9112. get speechRecognitionLanguage() {
  9113. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);
  9114. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage);
  9115. }
  9116. /**
  9117. * Gets target languages for translation that were set when the recognizer was created.
  9118. * The language is specified in BCP-47 format. The translation will provide translated text for each of language.
  9119. * @member TranslationRecognizer.prototype.targetLanguages
  9120. * @function
  9121. * @public
  9122. * @returns {string[]} Gets target languages for translation that were set when the recognizer was created.
  9123. */
  9124. get targetLanguages() {
  9125. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);
  9126. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages).split(",");
  9127. }
  9128. /**
  9129. * Gets the name of output voice.
  9130. * @member TranslationRecognizer.prototype.voiceName
  9131. * @function
  9132. * @public
  9133. * @returns {string} the name of output voice.
  9134. */
  9135. get voiceName() {
  9136. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);
  9137. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationVoice, undefined);
  9138. }
  9139. /**
  9140. * The collection of properties and their values defined for this TranslationRecognizer.
  9141. * @member TranslationRecognizer.prototype.properties
  9142. * @function
  9143. * @public
  9144. * @returns {PropertyCollection} The collection of properties and their values defined for this TranslationRecognizer.
  9145. */
  9146. get properties() {
  9147. return this.privProperties;
  9148. }
  9149. /**
  9150. * Gets the authorization token used to communicate with the service.
  9151. * @member TranslationRecognizer.prototype.authorizationToken
  9152. * @function
  9153. * @public
  9154. * @returns {string} Authorization token.
  9155. */
  9156. get authorizationToken() {
  9157. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token);
  9158. }
  9159. /**
  9160. * Gets/Sets the authorization token used to communicate with the service.
  9161. * @member TranslationRecognizer.prototype.authorizationToken
  9162. * @function
  9163. * @public
  9164. * @param {string} value - Authorization token.
  9165. */
  9166. set authorizationToken(value) {
  9167. this.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, value);
  9168. }
  9169. /**
  9170. * Starts recognition and translation, and stops after the first utterance is recognized.
  9171. * The task returns the translation text as result.
  9172. * Note: recognizeOnceAsync returns when the first utterance has been recognized, so it is suitable only
  9173. * for single shot recognition like command or query. For long-running recognition,
  9174. * use startContinuousRecognitionAsync() instead.
  9175. * @member TranslationRecognizer.prototype.recognizeOnceAsync
  9176. * @function
  9177. * @public
  9178. * @param cb - Callback that received the result when the translation has completed.
  9179. * @param err - Callback invoked in case of an error.
  9180. */
  9181. recognizeOnceAsync(cb, err) {
  9182. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);
  9183. (0, Exports_js_2.marshalPromiseToCallbacks)(this.recognizeOnceAsyncImpl(PhraseDetectionContext_js_1.RecognitionMode.Interactive), cb, err);
  9184. }
  9185. /**
  9186. * Starts recognition and translation, until stopContinuousRecognitionAsync() is called.
  9187. * User must subscribe to events to receive translation results.
  9188. * @member TranslationRecognizer.prototype.startContinuousRecognitionAsync
  9189. * @function
  9190. * @public
  9191. * @param cb - Callback that received the translation has started.
  9192. * @param err - Callback invoked in case of an error.
  9193. */
  9194. startContinuousRecognitionAsync(cb, err) {
  9195. (0, Exports_js_2.marshalPromiseToCallbacks)(this.startContinuousRecognitionAsyncImpl(PhraseDetectionContext_js_1.RecognitionMode.Conversation), cb, err);
  9196. }
  9197. /**
  9198. * Stops continuous recognition and translation.
  9199. * @member TranslationRecognizer.prototype.stopContinuousRecognitionAsync
  9200. * @function
  9201. * @public
  9202. * @param cb - Callback that received the translation has stopped.
  9203. * @param err - Callback invoked in case of an error.
  9204. */
  9205. stopContinuousRecognitionAsync(cb, err) {
  9206. (0, Exports_js_2.marshalPromiseToCallbacks)(this.stopContinuousRecognitionAsyncImpl(), cb, err);
  9207. }
  9208. /**
  9209. * dynamically remove a language from list of target language
  9210. * (can be used while recognition is ongoing)
  9211. * @member TranslationRecognizer.prototype.removeTargetLanguage
  9212. * @function
  9213. * @param lang - language to be removed
  9214. * @public
  9215. */
  9216. removeTargetLanguage(lang) {
  9217. Contracts_js_1.Contracts.throwIfNullOrUndefined(lang, "language to be removed");
  9218. if (this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages, undefined) !== undefined) {
  9219. const languages = this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages).split(",");
  9220. const index = languages.indexOf(lang);
  9221. if (index > -1) {
  9222. languages.splice(index, 1);
  9223. this.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages, languages.join(","));
  9224. this.updateLanguages(languages);
  9225. }
  9226. }
  9227. }
  9228. /**
  9229. * dynamically add a language to list of target language
  9230. * (can be used while recognition is ongoing)
  9231. * @member TranslationRecognizer.prototype.addTargetLanguage
  9232. * @function
  9233. * @param lang - language to be added
  9234. * @public
  9235. */
  9236. addTargetLanguage(lang) {
  9237. Contracts_js_1.Contracts.throwIfNullOrUndefined(lang, "language to be added");
  9238. let languages = [];
  9239. if (this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages, undefined) !== undefined) {
  9240. languages = this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages).split(",");
  9241. if (!languages.includes(lang)) {
  9242. languages.push(lang);
  9243. this.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages, languages.join(","));
  9244. }
  9245. }
  9246. else {
  9247. this.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages, lang);
  9248. languages = [lang];
  9249. }
  9250. this.updateLanguages(languages);
  9251. }
  9252. /**
  9253. * closes all external resources held by an instance of this class.
  9254. * @member TranslationRecognizer.prototype.close
  9255. * @function
  9256. * @public
  9257. */
  9258. close(cb, errorCb) {
  9259. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);
  9260. (0, Exports_js_2.marshalPromiseToCallbacks)(this.dispose(true), cb, errorCb);
  9261. }
  9262. /**
  9263. * handles ConnectionEstablishedEvent for conversation translation scenarios.
  9264. * @member TranslationRecognizer.prototype.onConnection
  9265. * @function
  9266. * @public
  9267. */
  9268. // eslint-disable-next-line @typescript-eslint/no-empty-function
  9269. onConnection() { }
  9270. async dispose(disposing) {
  9271. if (this.privDisposedTranslationRecognizer) {
  9272. return;
  9273. }
  9274. this.privDisposedTranslationRecognizer = true;
  9275. if (disposing) {
  9276. await this.implRecognizerStop();
  9277. await super.dispose(disposing);
  9278. }
  9279. }
  9280. createRecognizerConfig(speechConfig) {
  9281. return new Exports_js_1.RecognizerConfig(speechConfig, this.privProperties);
  9282. }
  9283. createServiceRecognizer(authentication, connectionFactory, audioConfig, recognizerConfig) {
  9284. const configImpl = audioConfig;
  9285. return new Exports_js_1.TranslationServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);
  9286. }
  9287. updateLanguages(languages) {
  9288. const conn = Connection_js_1.Connection.fromRecognizer(this);
  9289. if (!!conn) {
  9290. conn.setMessageProperty("speech.context", "translationcontext", { to: languages });
  9291. conn.sendMessageAsync("event", JSON.stringify({
  9292. id: "translation",
  9293. name: "updateLanguage",
  9294. to: languages
  9295. }));
  9296. }
  9297. }
  9298. }
  9299. exports.TranslationRecognizer = TranslationRecognizer;
  9300. /***/ }),
  9301. /* 117 */
  9302. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9303. "use strict";
  9304. //
  9305. // Copyright (c) Microsoft. All rights reserved.
  9306. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  9307. //
  9308. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9309. exports.Connection = void 0;
  9310. const Exports_js_1 = __webpack_require__(2);
  9311. const Exports_js_2 = __webpack_require__(4);
  9312. const ConnectionMessage_js_1 = __webpack_require__(118);
  9313. const Contracts_js_1 = __webpack_require__(64);
  9314. const Exports_js_3 = __webpack_require__(79);
  9315. /**
  9316. * Connection is a proxy class for managing connection to the speech service of the specified Recognizer.
  9317. * By default, a Recognizer autonomously manages connection to service when needed.
  9318. * The Connection class provides additional methods for users to explicitly open or close a connection and
  9319. * to subscribe to connection status changes.
  9320. * The use of Connection is optional, and mainly for scenarios where fine tuning of application
  9321. * behavior based on connection status is needed. Users can optionally call Open() to manually set up a connection
  9322. * in advance before starting recognition on the Recognizer associated with this Connection.
  9323. * If the Recognizer needs to connect or disconnect to service, it will
  9324. * setup or shutdown the connection independently. In this case the Connection will be notified by change of connection
  9325. * status via Connected/Disconnected events.
  9326. * Added in version 1.2.1.
  9327. */
  9328. class Connection {
  9329. /**
  9330. * Gets the Connection instance from the specified recognizer.
  9331. * @param recognizer The recognizer associated with the connection.
  9332. * @return The Connection instance of the recognizer.
  9333. */
  9334. static fromRecognizer(recognizer) {
  9335. const recoBase = recognizer.internalData;
  9336. const ret = new Connection();
  9337. ret.privInternalData = recoBase;
  9338. ret.setupEvents();
  9339. return ret;
  9340. }
  9341. /**
  9342. * Gets the Connection instance from the specified synthesizer.
  9343. * @param synthesizer The synthesizer associated with the connection.
  9344. * @return The Connection instance of the synthesizer.
  9345. */
  9346. static fromSynthesizer(synthesizer) {
  9347. const synthBase = synthesizer.internalData;
  9348. const ret = new Connection();
  9349. ret.privInternalData = synthBase;
  9350. ret.setupEvents();
  9351. return ret;
  9352. }
  9353. /**
  9354. * Starts to set up connection to the service.
  9355. * Users can optionally call openConnection() to manually set up a connection in advance before starting recognition on the
  9356. * Recognizer associated with this Connection. After starting recognition, calling Open() will have no effect
  9357. *
  9358. * Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to
  9359. * be notified when the connection is established.
  9360. */
  9361. openConnection(cb, err) {
  9362. (0, Exports_js_2.marshalPromiseToCallbacks)(this.privInternalData.connect(), cb, err);
  9363. }
  9364. /**
  9365. * Closes the connection the service.
  9366. * Users can optionally call closeConnection() to manually shutdown the connection of the associated Recognizer.
  9367. *
  9368. * If closeConnection() is called during recognition, recognition will fail and cancel with an error.
  9369. */
  9370. closeConnection(cb, err) {
  9371. if (this.privInternalData instanceof Exports_js_1.SynthesisAdapterBase) {
  9372. throw new Error("Disconnecting a synthesizer's connection is currently not supported");
  9373. }
  9374. else {
  9375. (0, Exports_js_2.marshalPromiseToCallbacks)(this.privInternalData.disconnect(), cb, err);
  9376. }
  9377. }
  9378. /**
  9379. * Appends a parameter in a message to service.
  9380. * Added in version 1.12.1.
  9381. * @param path The path of the network message.
  9382. * @param propertyName Name of the property
  9383. * @param propertyValue Value of the property. This is a json string.
  9384. */
  9385. setMessageProperty(path, propertyName, propertyValue) {
  9386. Contracts_js_1.Contracts.throwIfNullOrWhitespace(propertyName, "propertyName");
  9387. if (this.privInternalData instanceof Exports_js_1.ServiceRecognizerBase) {
  9388. if (path.toLowerCase() !== "speech.context") {
  9389. throw new Error("Only speech.context message property sets are currently supported for recognizer");
  9390. }
  9391. else {
  9392. const context = this.privInternalData.speechContext.getContext();
  9393. context[propertyName] = propertyValue;
  9394. }
  9395. }
  9396. else if (this.privInternalData instanceof Exports_js_1.SynthesisAdapterBase) {
  9397. if (path.toLowerCase() !== "synthesis.context") {
  9398. throw new Error("Only synthesis.context message property sets are currently supported for synthesizer");
  9399. }
  9400. else {
  9401. this.privInternalData.synthesisContext.setSection(propertyName, propertyValue);
  9402. }
  9403. }
  9404. }
  9405. /**
  9406. * Sends a message to the speech service.
  9407. * Added in version 1.13.0.
  9408. * @param path The WebSocket path of the message
  9409. * @param payload The payload of the message. This is a json string or a ArrayBuffer.
  9410. * @param success A callback to indicate success.
  9411. * @param error A callback to indicate an error.
  9412. */
  9413. sendMessageAsync(path, payload, success, error) {
  9414. (0, Exports_js_2.marshalPromiseToCallbacks)(this.privInternalData.sendNetworkMessage(path, payload), success, error);
  9415. }
  9416. /**
  9417. * Dispose of associated resources.
  9418. */
  9419. close() {
  9420. /* eslint-disable no-empty */
  9421. }
  9422. setupEvents() {
  9423. this.privEventListener = this.privInternalData.connectionEvents.attach((connectionEvent) => {
  9424. if (connectionEvent.name === "ConnectionEstablishedEvent") {
  9425. if (!!this.connected) {
  9426. this.connected(new Exports_js_3.ConnectionEventArgs(connectionEvent.connectionId));
  9427. }
  9428. }
  9429. else if (connectionEvent.name === "ConnectionClosedEvent") {
  9430. if (!!this.disconnected) {
  9431. this.disconnected(new Exports_js_3.ConnectionEventArgs(connectionEvent.connectionId));
  9432. }
  9433. }
  9434. else if (connectionEvent.name === "ConnectionMessageSentEvent") {
  9435. if (!!this.messageSent) {
  9436. this.messageSent(new Exports_js_3.ConnectionMessageEventArgs(new ConnectionMessage_js_1.ConnectionMessageImpl(connectionEvent.message)));
  9437. }
  9438. }
  9439. else if (connectionEvent.name === "ConnectionMessageReceivedEvent") {
  9440. if (!!this.messageReceived) {
  9441. this.messageReceived(new Exports_js_3.ConnectionMessageEventArgs(new ConnectionMessage_js_1.ConnectionMessageImpl(connectionEvent.message)));
  9442. }
  9443. }
  9444. });
  9445. this.privServiceEventListener = this.privInternalData.serviceEvents.attach((e) => {
  9446. if (!!this.receivedServiceMessage) {
  9447. this.receivedServiceMessage(new Exports_js_3.ServiceEventArgs(e.jsonString, e.name));
  9448. }
  9449. });
  9450. }
  9451. }
  9452. exports.Connection = Connection;
  9453. /***/ }),
  9454. /* 118 */
  9455. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9456. "use strict";
  9457. //
  9458. // Copyright (c) Microsoft. All rights reserved.
  9459. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  9460. //
  9461. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9462. exports.ConnectionMessageImpl = exports.ConnectionMessage = void 0;
  9463. // eslint-disable-next-line max-classes-per-file
  9464. const HeaderNames_js_1 = __webpack_require__(54);
  9465. const Exports_js_1 = __webpack_require__(4);
  9466. const PropertyCollection_js_1 = __webpack_require__(109);
  9467. const PropertyId_js_1 = __webpack_require__(110);
  9468. /**
  9469. * ConnectionMessage represents implementation specific messages sent to and received from
  9470. * the speech service. These messages are provided for debugging purposes and should not
  9471. * be used for production use cases with the Azure Cognitive Services Speech Service.
  9472. * Messages sent to and received from the Speech Service are subject to change without
  9473. * notice. This includes message contents, headers, payloads, ordering, etc.
  9474. * Added in version 1.11.0.
  9475. */
  9476. class ConnectionMessage {
  9477. }
  9478. exports.ConnectionMessage = ConnectionMessage;
  9479. class ConnectionMessageImpl {
  9480. constructor(message) {
  9481. this.privConnectionMessage = message;
  9482. this.privProperties = new PropertyCollection_js_1.PropertyCollection();
  9483. if (!!this.privConnectionMessage.headers[HeaderNames_js_1.HeaderNames.ConnectionId]) {
  9484. this.privProperties.setProperty(PropertyId_js_1.PropertyId.Speech_SessionId, this.privConnectionMessage.headers[HeaderNames_js_1.HeaderNames.ConnectionId]);
  9485. }
  9486. Object.keys(this.privConnectionMessage.headers).forEach((header) => {
  9487. this.privProperties.setProperty(header, this.privConnectionMessage.headers[header]);
  9488. });
  9489. }
  9490. /**
  9491. * The message path.
  9492. */
  9493. get path() {
  9494. return this.privConnectionMessage.headers[Object.keys(this.privConnectionMessage.headers).find((key) => key.toLowerCase() === "path".toLowerCase())];
  9495. }
  9496. /**
  9497. * Checks to see if the ConnectionMessage is a text message.
  9498. * See also IsBinaryMessage().
  9499. */
  9500. get isTextMessage() {
  9501. return this.privConnectionMessage.messageType === Exports_js_1.MessageType.Text;
  9502. }
  9503. /**
  9504. * Checks to see if the ConnectionMessage is a binary message.
  9505. * See also GetBinaryMessage().
  9506. */
  9507. get isBinaryMessage() {
  9508. return this.privConnectionMessage.messageType === Exports_js_1.MessageType.Binary;
  9509. }
  9510. /**
  9511. * Gets the text message payload. Typically the text message content-type is
  9512. * application/json. To determine other content-types use
  9513. * Properties.GetProperty("Content-Type").
  9514. */
  9515. get TextMessage() {
  9516. return this.privConnectionMessage.textBody;
  9517. }
  9518. /**
  9519. * Gets the binary message payload.
  9520. */
  9521. get binaryMessage() {
  9522. return this.privConnectionMessage.binaryBody;
  9523. }
  9524. /**
  9525. * A collection of properties and their values defined for this <see cref="ConnectionMessage"/>.
  9526. * Message headers can be accessed via this collection (e.g. "Content-Type").
  9527. */
  9528. get properties() {
  9529. return this.privProperties;
  9530. }
  9531. /**
  9532. * Returns a string that represents the connection message.
  9533. */
  9534. toString() {
  9535. return "";
  9536. }
  9537. }
  9538. exports.ConnectionMessageImpl = ConnectionMessageImpl;
  9539. /***/ }),
  9540. /* 119 */
  9541. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9542. "use strict";
  9543. // Copyright (c) Microsoft Corporation. All rights reserved.
  9544. // Licensed under the MIT license.
  9545. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9546. exports.Translations = void 0;
  9547. const Exports_js_1 = __webpack_require__(79);
  9548. /**
  9549. * Represents collection of parameters and their values.
  9550. * @class Translations
  9551. */
  9552. class Translations {
  9553. constructor() {
  9554. // Use an PropertyCollection internally, just wrapping it to hide the | enum syntax it has.
  9555. this.privMap = new Exports_js_1.PropertyCollection();
  9556. }
  9557. /**
  9558. * Get the languages in the object in a String array.
  9559. * @member Translations.prototype.languages
  9560. * @function
  9561. * @public
  9562. * @returns {string[]} languages in translations object.
  9563. */
  9564. get languages() {
  9565. return this.privMap.keys;
  9566. }
  9567. /**
  9568. * Returns the parameter value in type String. The parameter must have the same type as String.
  9569. * Currently only String, int and bool are allowed.
  9570. * If the name is not available, the specified defaultValue is returned.
  9571. * @member Translations.prototype.get
  9572. * @function
  9573. * @public
  9574. * @param {string} key - The parameter name.
  9575. * @param {string} def - The default value which is returned if the parameter is not available in the collection.
  9576. * @returns {string} value of the parameter.
  9577. */
  9578. get(key, def) {
  9579. return this.privMap.getProperty(key, def);
  9580. }
  9581. /**
  9582. * Sets the String value of the parameter specified by name.
  9583. * @member Translations.prototype.set
  9584. * @function
  9585. * @public
  9586. * @param {string} key - The parameter name.
  9587. * @param {string} value - The value of the parameter.
  9588. */
  9589. set(key, value) {
  9590. this.privMap.setProperty(key, value);
  9591. }
  9592. }
  9593. exports.Translations = Translations;
  9594. /***/ }),
  9595. /* 120 */
  9596. /***/ ((__unused_webpack_module, exports) => {
  9597. "use strict";
  9598. // Copyright (c) Microsoft Corporation. All rights reserved.
  9599. // Licensed under the MIT license.
  9600. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9601. exports.NoMatchReason = void 0;
  9602. /**
  9603. * Defines the possible reasons a recognition result might not be recognized.
  9604. * @class NoMatchReason
  9605. */
  9606. var NoMatchReason;
  9607. (function (NoMatchReason) {
  9608. /**
  9609. * Indicates that speech was detected, but not recognized.
  9610. * @member NoMatchReason.NotRecognized
  9611. */
  9612. NoMatchReason[NoMatchReason["NotRecognized"] = 0] = "NotRecognized";
  9613. /**
  9614. * Indicates that the start of the audio stream contained only silence,
  9615. * and the service timed out waiting for speech.
  9616. * @member NoMatchReason.InitialSilenceTimeout
  9617. */
  9618. NoMatchReason[NoMatchReason["InitialSilenceTimeout"] = 1] = "InitialSilenceTimeout";
  9619. /**
  9620. * Indicates that the start of the audio stream contained only noise,
  9621. * and the service timed out waiting for speech.
  9622. * @member NoMatchReason.InitialBabbleTimeout
  9623. */
  9624. NoMatchReason[NoMatchReason["InitialBabbleTimeout"] = 2] = "InitialBabbleTimeout";
  9625. })(NoMatchReason = exports.NoMatchReason || (exports.NoMatchReason = {}));
  9626. /***/ }),
  9627. /* 121 */
  9628. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9629. "use strict";
  9630. // Copyright (c) Microsoft Corporation. All rights reserved.
  9631. // Licensed under the MIT license.
  9632. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9633. exports.NoMatchDetails = void 0;
  9634. const Exports_js_1 = __webpack_require__(2);
  9635. const Exports_js_2 = __webpack_require__(79);
  9636. /**
  9637. * Contains detailed information for NoMatch recognition results.
  9638. * @class NoMatchDetails
  9639. */
  9640. class NoMatchDetails {
  9641. /**
  9642. * Creates and initializes an instance of this class.
  9643. * @constructor
  9644. * @param {NoMatchReason} reason - The no-match reason.
  9645. */
  9646. constructor(reason) {
  9647. this.privReason = reason;
  9648. }
  9649. /**
  9650. * Creates an instance of NoMatchDetails object for the NoMatch SpeechRecognitionResults.
  9651. * @member NoMatchDetails.fromResult
  9652. * @function
  9653. * @public
  9654. * @param {SpeechRecognitionResult | IntentRecognitionResult | TranslationRecognitionResult}
  9655. * result - The recognition result that was not recognized.
  9656. * @returns {NoMatchDetails} The no match details object being created.
  9657. */
  9658. static fromResult(result) {
  9659. const simpleSpeech = Exports_js_1.SimpleSpeechPhrase.fromJSON(result.json, 0); // Offset fixups are already done.
  9660. let reason = Exports_js_2.NoMatchReason.NotRecognized;
  9661. switch (simpleSpeech.RecognitionStatus) {
  9662. case Exports_js_1.RecognitionStatus.BabbleTimeout:
  9663. reason = Exports_js_2.NoMatchReason.InitialBabbleTimeout;
  9664. break;
  9665. case Exports_js_1.RecognitionStatus.InitialSilenceTimeout:
  9666. reason = Exports_js_2.NoMatchReason.InitialSilenceTimeout;
  9667. break;
  9668. default:
  9669. reason = Exports_js_2.NoMatchReason.NotRecognized;
  9670. break;
  9671. }
  9672. return new NoMatchDetails(reason);
  9673. }
  9674. /**
  9675. * The reason the recognition was canceled.
  9676. * @member NoMatchDetails.prototype.reason
  9677. * @function
  9678. * @public
  9679. * @returns {NoMatchReason} Specifies the reason canceled.
  9680. */
  9681. get reason() {
  9682. return this.privReason;
  9683. }
  9684. }
  9685. exports.NoMatchDetails = NoMatchDetails;
  9686. /***/ }),
  9687. /* 122 */
  9688. /***/ ((__unused_webpack_module, exports) => {
  9689. "use strict";
  9690. // Copyright (c) Microsoft Corporation. All rights reserved.
  9691. // Licensed under the MIT license.
  9692. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9693. exports.TranslationRecognitionCanceledEventArgs = void 0;
  9694. /**
  9695. * Define payload of speech recognition canceled result events.
  9696. * @class TranslationRecognitionCanceledEventArgs
  9697. */
  9698. class TranslationRecognitionCanceledEventArgs {
  9699. /**
  9700. * Creates and initializes an instance of this class.
  9701. * @constructor
  9702. * @param {string} sessionid - The session id.
  9703. * @param {CancellationReason} cancellationReason - The cancellation reason.
  9704. * @param {string} errorDetails - Error details, if provided.
  9705. * @param {TranslationRecognitionResult} result - The result.
  9706. */
  9707. constructor(sessionid, cancellationReason, errorDetails, errorCode, result) {
  9708. this.privCancelReason = cancellationReason;
  9709. this.privErrorDetails = errorDetails;
  9710. this.privResult = result;
  9711. this.privSessionId = sessionid;
  9712. this.privErrorCode = errorCode;
  9713. }
  9714. /**
  9715. * Specifies the recognition result.
  9716. * @member TranslationRecognitionCanceledEventArgs.prototype.result
  9717. * @function
  9718. * @public
  9719. * @returns {TranslationRecognitionResult} the recognition result.
  9720. */
  9721. get result() {
  9722. return this.privResult;
  9723. }
  9724. /**
  9725. * Specifies the session identifier.
  9726. * @member TranslationRecognitionCanceledEventArgs.prototype.sessionId
  9727. * @function
  9728. * @public
  9729. * @returns {string} the session identifier.
  9730. */
  9731. get sessionId() {
  9732. return this.privSessionId;
  9733. }
  9734. /**
  9735. * The reason the recognition was canceled.
  9736. * @member TranslationRecognitionCanceledEventArgs.prototype.reason
  9737. * @function
  9738. * @public
  9739. * @returns {CancellationReason} Specifies the reason canceled.
  9740. */
  9741. get reason() {
  9742. return this.privCancelReason;
  9743. }
  9744. /**
  9745. * The error code in case of an unsuccessful recognition.
  9746. * Added in version 1.1.0.
  9747. * @return An error code that represents the error reason.
  9748. */
  9749. get errorCode() {
  9750. return this.privErrorCode;
  9751. }
  9752. /**
  9753. * In case of an unsuccessful recognition, provides details of the occurred error.
  9754. * @member TranslationRecognitionCanceledEventArgs.prototype.errorDetails
  9755. * @function
  9756. * @public
  9757. * @returns {string} A String that represents the error details.
  9758. */
  9759. get errorDetails() {
  9760. return this.privErrorDetails;
  9761. }
  9762. }
  9763. exports.TranslationRecognitionCanceledEventArgs = TranslationRecognitionCanceledEventArgs;
  9764. /***/ }),
  9765. /* 123 */
  9766. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9767. "use strict";
  9768. // Copyright (c) Microsoft Corporation. All rights reserved.
  9769. // Licensed under the MIT license.
  9770. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9771. exports.IntentRecognitionCanceledEventArgs = void 0;
  9772. const Exports_js_1 = __webpack_require__(79);
  9773. /**
  9774. * Define payload of intent recognition canceled result events.
  9775. * @class IntentRecognitionCanceledEventArgs
  9776. */
  9777. class IntentRecognitionCanceledEventArgs extends Exports_js_1.IntentRecognitionEventArgs {
  9778. /**
  9779. * Creates and initializes an instance of this class.
  9780. * @constructor
  9781. * @param {CancellationReason} result - The result of the intent recognition.
  9782. * @param {string} offset - The offset.
  9783. * @param {IntentRecognitionResult} sessionId - The session id.
  9784. */
  9785. constructor(reason, errorDetails, errorCode, result, offset, sessionId) {
  9786. super(result, offset, sessionId);
  9787. this.privReason = reason;
  9788. this.privErrorDetails = errorDetails;
  9789. this.privErrorCode = errorCode;
  9790. }
  9791. /**
  9792. * The reason the recognition was canceled.
  9793. * @member IntentRecognitionCanceledEventArgs.prototype.reason
  9794. * @function
  9795. * @public
  9796. * @returns {CancellationReason} Specifies the reason canceled.
  9797. */
  9798. get reason() {
  9799. return this.privReason;
  9800. }
  9801. /**
  9802. * The error code in case of an unsuccessful recognition.
  9803. * Added in version 1.1.0.
  9804. * @return An error code that represents the error reason.
  9805. */
  9806. get errorCode() {
  9807. return this.privErrorCode;
  9808. }
  9809. /**
  9810. * In case of an unsuccessful recognition, provides details of the occurred error.
  9811. * @member IntentRecognitionCanceledEventArgs.prototype.errorDetails
  9812. * @function
  9813. * @public
  9814. * @returns {string} A String that represents the error details.
  9815. */
  9816. get errorDetails() {
  9817. return this.privErrorDetails;
  9818. }
  9819. }
  9820. exports.IntentRecognitionCanceledEventArgs = IntentRecognitionCanceledEventArgs;
  9821. /***/ }),
  9822. /* 124 */
  9823. /***/ ((__unused_webpack_module, exports) => {
  9824. "use strict";
  9825. // Copyright (c) Microsoft Corporation. All rights reserved.
  9826. // Licensed under the MIT license.
  9827. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9828. exports.CancellationDetailsBase = void 0;
  9829. /**
  9830. * Contains detailed information about why a result was canceled.
  9831. * @class CancellationDetailsBase
  9832. */
  9833. class CancellationDetailsBase {
  9834. /**
  9835. * Creates and initializes an instance of this class.
  9836. * @constructor
  9837. * @param {CancellationReason} reason - The cancellation reason.
  9838. * @param {string} errorDetails - The error details, if provided.
  9839. */
  9840. constructor(reason, errorDetails, errorCode) {
  9841. this.privReason = reason;
  9842. this.privErrorDetails = errorDetails;
  9843. this.privErrorCode = errorCode;
  9844. }
  9845. /**
  9846. * The reason the recognition was canceled.
  9847. * @member CancellationDetailsBase.prototype.reason
  9848. * @function
  9849. * @public
  9850. * @returns {CancellationReason} Specifies the reason canceled.
  9851. */
  9852. get reason() {
  9853. return this.privReason;
  9854. }
  9855. /**
  9856. * In case of an unsuccessful recognition, provides details of the occurred error.
  9857. * @member CancellationDetailsBase.prototype.errorDetails
  9858. * @function
  9859. * @public
  9860. * @returns {string} A String that represents the error details.
  9861. */
  9862. get errorDetails() {
  9863. return this.privErrorDetails;
  9864. }
  9865. /**
  9866. * The error code in case of an unsuccessful recognition.
  9867. * Added in version 1.1.0.
  9868. * @return An error code that represents the error reason.
  9869. */
  9870. get ErrorCode() {
  9871. return this.privErrorCode;
  9872. }
  9873. }
  9874. exports.CancellationDetailsBase = CancellationDetailsBase;
  9875. /***/ }),
  9876. /* 125 */
  9877. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9878. "use strict";
  9879. // Copyright (c) Microsoft Corporation. All rights reserved.
  9880. // Licensed under the MIT license.
  9881. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9882. exports.CancellationDetails = void 0;
  9883. const Exports_js_1 = __webpack_require__(2);
  9884. const CancellationDetailsBase_js_1 = __webpack_require__(124);
  9885. const Exports_js_2 = __webpack_require__(79);
  9886. /**
  9887. * Contains detailed information about why a result was canceled.
  9888. * @class CancellationDetails
  9889. */
  9890. class CancellationDetails extends CancellationDetailsBase_js_1.CancellationDetailsBase {
  9891. constructor(reason, errorDetails, errorCode) {
  9892. super(reason, errorDetails, errorCode);
  9893. }
  9894. /**
  9895. * Creates an instance of CancellationDetails object for the canceled RecognitionResult.
  9896. * @member CancellationDetails.fromResult
  9897. * @function
  9898. * @public
  9899. * @param {RecognitionResult | SpeechSynthesisResult} result - The result that was canceled.
  9900. * @returns {CancellationDetails} The cancellation details object being created.
  9901. */
  9902. static fromResult(result) {
  9903. let reason = Exports_js_2.CancellationReason.Error;
  9904. let errorCode = Exports_js_2.CancellationErrorCode.NoError;
  9905. if (result instanceof Exports_js_2.RecognitionResult && !!result.json) {
  9906. const simpleSpeech = Exports_js_1.SimpleSpeechPhrase.fromJSON(result.json, 0); // Offset fixups are already done.
  9907. reason = Exports_js_1.EnumTranslation.implTranslateCancelResult(simpleSpeech.RecognitionStatus);
  9908. }
  9909. if (!!result.properties) {
  9910. errorCode = Exports_js_2.CancellationErrorCode[result.properties.getProperty(Exports_js_1.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[Exports_js_2.CancellationErrorCode.NoError])];
  9911. }
  9912. return new CancellationDetails(reason, result.errorDetails || Exports_js_1.EnumTranslation.implTranslateErrorDetails(errorCode), errorCode);
  9913. }
  9914. }
  9915. exports.CancellationDetails = CancellationDetails;
  9916. /***/ }),
  9917. /* 126 */
  9918. /***/ ((__unused_webpack_module, exports) => {
  9919. "use strict";
  9920. // Copyright (c) Microsoft Corporation. All rights reserved.
  9921. // Licensed under the MIT license.
  9922. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9923. exports.CancellationErrorCode = void 0;
  9924. /**
  9925. * Defines error code in case that CancellationReason is Error.
  9926. * Added in version 1.1.0.
  9927. */
  9928. var CancellationErrorCode;
  9929. (function (CancellationErrorCode) {
  9930. /**
  9931. * Indicates that no error occurred during speech recognition.
  9932. */
  9933. CancellationErrorCode[CancellationErrorCode["NoError"] = 0] = "NoError";
  9934. /**
  9935. * Indicates an authentication error.
  9936. */
  9937. CancellationErrorCode[CancellationErrorCode["AuthenticationFailure"] = 1] = "AuthenticationFailure";
  9938. /**
  9939. * Indicates that one or more recognition parameters are invalid.
  9940. */
  9941. CancellationErrorCode[CancellationErrorCode["BadRequestParameters"] = 2] = "BadRequestParameters";
  9942. /**
  9943. * Indicates that the number of parallel requests exceeded the number of allowed
  9944. * concurrent transcriptions for the subscription.
  9945. */
  9946. CancellationErrorCode[CancellationErrorCode["TooManyRequests"] = 3] = "TooManyRequests";
  9947. /**
  9948. * Indicates a connection error.
  9949. */
  9950. CancellationErrorCode[CancellationErrorCode["ConnectionFailure"] = 4] = "ConnectionFailure";
  9951. /**
  9952. * Indicates a time-out error when waiting for response from service.
  9953. */
  9954. CancellationErrorCode[CancellationErrorCode["ServiceTimeout"] = 5] = "ServiceTimeout";
  9955. /**
  9956. * Indicates that an error is returned by the service.
  9957. */
  9958. CancellationErrorCode[CancellationErrorCode["ServiceError"] = 6] = "ServiceError";
  9959. /**
  9960. * Indicates an unexpected runtime error.
  9961. */
  9962. CancellationErrorCode[CancellationErrorCode["RuntimeError"] = 7] = "RuntimeError";
  9963. /**
  9964. * Indicates an quota overrun on existing key.
  9965. */
  9966. CancellationErrorCode[CancellationErrorCode["Forbidden"] = 8] = "Forbidden";
  9967. })(CancellationErrorCode = exports.CancellationErrorCode || (exports.CancellationErrorCode = {}));
  9968. /***/ }),
  9969. /* 127 */
  9970. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9971. "use strict";
  9972. //
  9973. // Copyright (c) Microsoft. All rights reserved.
  9974. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  9975. //
  9976. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9977. exports.ConnectionEventArgs = void 0;
  9978. const Exports_js_1 = __webpack_require__(79);
  9979. /**
  9980. * Defines payload for connection events like Connected/Disconnected.
  9981. * Added in version 1.2.0
  9982. */
  9983. class ConnectionEventArgs extends Exports_js_1.SessionEventArgs {
  9984. }
  9985. exports.ConnectionEventArgs = ConnectionEventArgs;
  9986. /***/ }),
  9987. /* 128 */
  9988. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9989. "use strict";
  9990. //
  9991. // Copyright (c) Microsoft. All rights reserved.
  9992. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  9993. //
  9994. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9995. exports.ServiceEventArgs = void 0;
  9996. const Exports_js_1 = __webpack_require__(79);
  9997. /**
  9998. * Defines payload for any Service message event
  9999. * Added in version 1.9.0
  10000. */
  10001. class ServiceEventArgs extends Exports_js_1.SessionEventArgs {
  10002. /**
  10003. * Creates and initializes an instance of this class.
  10004. * @constructor
  10005. * @param {string} json - json payload of the USP message.
  10006. */
  10007. constructor(json, name, sessionId) {
  10008. super(sessionId);
  10009. this.privJsonResult = json;
  10010. this.privEventName = name;
  10011. }
  10012. get jsonString() {
  10013. return this.privJsonResult;
  10014. }
  10015. get eventName() {
  10016. return this.privEventName;
  10017. }
  10018. }
  10019. exports.ServiceEventArgs = ServiceEventArgs;
  10020. /***/ }),
  10021. /* 129 */
  10022. /***/ ((__unused_webpack_module, exports) => {
  10023. "use strict";
  10024. // Copyright (c) Microsoft Corporation. All rights reserved.
  10025. // Licensed under the MIT license.
  10026. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10027. exports.PhraseListGrammar = void 0;
  10028. /**
  10029. * Allows additions of new phrases to improve speech recognition.
  10030. *
  10031. * Phrases added to the recognizer are effective at the start of the next recognition, or the next time the SpeechSDK must reconnect
  10032. * to the speech service.
  10033. */
  10034. class PhraseListGrammar {
  10035. constructor(recogBase) {
  10036. this.privGrammerBuilder = recogBase.dynamicGrammar;
  10037. }
  10038. /**
  10039. * Creates a PhraseListGrammar from a given speech recognizer. Will accept any recognizer that derives from @class Recognizer.
  10040. * @param recognizer The recognizer to add phrase lists to.
  10041. */
  10042. static fromRecognizer(recognizer) {
  10043. const recoBase = recognizer.internalData;
  10044. return new PhraseListGrammar(recoBase);
  10045. }
  10046. /**
  10047. * Adds a single phrase to the current recognizer.
  10048. * @param phrase Phrase to add.
  10049. */
  10050. addPhrase(phrase) {
  10051. this.privGrammerBuilder.addPhrase(phrase);
  10052. }
  10053. /**
  10054. * Adds multiple phrases to the current recognizer.
  10055. * @param phrases Array of phrases to add.
  10056. */
  10057. addPhrases(phrases) {
  10058. this.privGrammerBuilder.addPhrase(phrases);
  10059. }
  10060. /**
  10061. * Clears all phrases added to the current recognizer.
  10062. */
  10063. clear() {
  10064. this.privGrammerBuilder.clearPhrases();
  10065. }
  10066. }
  10067. exports.PhraseListGrammar = PhraseListGrammar;
  10068. /***/ }),
  10069. /* 130 */
  10070. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10071. "use strict";
  10072. // Copyright (c) Microsoft Corporation. All rights reserved.
  10073. // Licensed under the MIT license.
  10074. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10075. exports.DialogServiceConfigImpl = exports.DialogServiceConfig = void 0;
  10076. /* eslint-disable max-classes-per-file */
  10077. const Contracts_js_1 = __webpack_require__(64);
  10078. const Exports_js_1 = __webpack_require__(79);
  10079. /**
  10080. * Class that defines base configurations for dialog service connector
  10081. * @class DialogServiceConfig
  10082. */
  10083. class DialogServiceConfig {
  10084. /**
  10085. * Creates an instance of DialogService config.
  10086. * @constructor
  10087. */
  10088. constructor() {
  10089. return;
  10090. }
  10091. /**
  10092. * Sets the corresponding backend application identifier.
  10093. * @member DialogServiceConfig.prototype.Conversation_ApplicationId
  10094. * @function
  10095. * @public
  10096. * @param {string} value - The application identifier to set.
  10097. */
  10098. // eslint-disable-next-line @typescript-eslint/no-empty-function
  10099. set applicationId(value) { }
  10100. static get DialogTypes() {
  10101. return {
  10102. BotFramework: "bot_framework",
  10103. CustomCommands: "custom_commands"
  10104. };
  10105. }
  10106. }
  10107. exports.DialogServiceConfig = DialogServiceConfig;
  10108. /**
  10109. * Dialog Service configuration.
  10110. * @class DialogServiceConfigImpl
  10111. */
  10112. class DialogServiceConfigImpl extends DialogServiceConfig {
  10113. /**
  10114. * Creates an instance of dialogService config.
  10115. */
  10116. constructor() {
  10117. super();
  10118. this.privSpeechConfig = new Exports_js_1.SpeechConfigImpl();
  10119. }
  10120. /**
  10121. * Provides access to custom properties.
  10122. * @member DialogServiceConfigImpl.prototype.properties
  10123. * @function
  10124. * @public
  10125. * @returns {PropertyCollection} The properties.
  10126. */
  10127. get properties() {
  10128. return this.privSpeechConfig.properties;
  10129. }
  10130. /**
  10131. * Gets the speech recognition language.
  10132. * @member DialogServiceConfigImpl.prototype.speechRecognitionLanguage
  10133. * @function
  10134. * @public
  10135. */
  10136. get speechRecognitionLanguage() {
  10137. return this.privSpeechConfig.speechRecognitionLanguage;
  10138. }
  10139. /**
  10140. * Sets the speech recognition language.
  10141. * @member DialogServiceConfigImpl.prototype.speechRecognitionLanguage
  10142. * @function
  10143. * @public
  10144. * @param {string} value - The language to set.
  10145. */
  10146. set speechRecognitionLanguage(value) {
  10147. Contracts_js_1.Contracts.throwIfNullOrWhitespace(value, "value");
  10148. this.privSpeechConfig.speechRecognitionLanguage = value;
  10149. }
  10150. get outputFormat() {
  10151. return this.privSpeechConfig.outputFormat;
  10152. }
  10153. set outputFormat(value) {
  10154. this.privSpeechConfig.outputFormat = value;
  10155. }
  10156. /**
  10157. * Sets a named property as value
  10158. * @member DialogServiceConfigImpl.prototype.setProperty
  10159. * @function
  10160. * @public
  10161. * @param {PropertyId | string} name - The property to set.
  10162. * @param {string} value - The value.
  10163. */
  10164. setProperty(name, value) {
  10165. this.privSpeechConfig.setProperty(name, value);
  10166. }
  10167. /**
  10168. * Sets a named property as value
  10169. * @member DialogServiceConfigImpl.prototype.getProperty
  10170. * @function
  10171. * @public
  10172. * @param {PropertyId | string} name - The property to get.
  10173. * @param {string} def - The default value to return in case the property is not known.
  10174. * @returns {string} The current value, or provided default, of the given property.
  10175. */
  10176. getProperty(name, def) {
  10177. void def;
  10178. return this.privSpeechConfig.getProperty(name);
  10179. }
  10180. /**
  10181. * Sets the proxy configuration.
  10182. * Only relevant in Node.js environments.
  10183. * Added in version 1.4.0.
  10184. * @param proxyHostName The host name of the proxy server, without the protocol scheme (http://)
  10185. * @param proxyPort The port number of the proxy server.
  10186. * @param proxyUserName The user name of the proxy server.
  10187. * @param proxyPassword The password of the proxy server.
  10188. */
  10189. setProxy(proxyHostName, proxyPort, proxyUserName, proxyPassword) {
  10190. this.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_ProxyHostName, proxyHostName);
  10191. this.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_ProxyPort, `${proxyPort}`);
  10192. if (proxyUserName) {
  10193. this.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_ProxyUserName, proxyUserName);
  10194. }
  10195. if (proxyPassword) {
  10196. this.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_ProxyPassword, proxyPassword);
  10197. }
  10198. }
  10199. setServiceProperty(name, value, channel) {
  10200. void channel;
  10201. this.privSpeechConfig.setServiceProperty(name, value);
  10202. }
  10203. /**
  10204. * Dispose of associated resources.
  10205. * @member DialogServiceConfigImpl.prototype.close
  10206. * @function
  10207. * @public
  10208. */
  10209. close() {
  10210. return;
  10211. }
  10212. }
  10213. exports.DialogServiceConfigImpl = DialogServiceConfigImpl;
  10214. /***/ }),
  10215. /* 131 */
  10216. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10217. "use strict";
  10218. // Copyright (c) Microsoft Corporation. All rights reserved.
  10219. // Licensed under the MIT license.
  10220. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10221. exports.BotFrameworkConfig = void 0;
  10222. const Contracts_js_1 = __webpack_require__(64);
  10223. const DialogServiceConfig_js_1 = __webpack_require__(130);
  10224. const Exports_js_1 = __webpack_require__(79);
  10225. /**
  10226. * Class that defines configurations for the dialog service connector object for using a Bot Framework backend.
  10227. * @class BotFrameworkConfig
  10228. */
  10229. class BotFrameworkConfig extends DialogServiceConfig_js_1.DialogServiceConfigImpl {
  10230. /**
  10231. * Creates an instance of BotFrameworkConfig.
  10232. */
  10233. constructor() {
  10234. super();
  10235. }
  10236. /**
  10237. * Creates a bot framework configuration instance with the provided subscription information.
  10238. * @member BotFrameworkConfig.fromSubscription
  10239. * @function
  10240. * @public
  10241. * @param subscription Subscription key associated with the bot
  10242. * @param region The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).
  10243. * @param botId Optional. Identifier for using a specific bot within an Azure resource group. Equivalent to the
  10244. * resource name.
  10245. * @returns {BotFrameworkConfig} A new bot framework configuration instance.
  10246. */
  10247. static fromSubscription(subscription, region, botId) {
  10248. Contracts_js_1.Contracts.throwIfNullOrWhitespace(subscription, "subscription");
  10249. Contracts_js_1.Contracts.throwIfNullOrWhitespace(region, "region");
  10250. const botFrameworkConfig = new DialogServiceConfig_js_1.DialogServiceConfigImpl();
  10251. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.Conversation_DialogType, DialogServiceConfig_js_1.DialogServiceConfig.DialogTypes.BotFramework);
  10252. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Key, subscription);
  10253. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Region, region);
  10254. if (botId) {
  10255. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.Conversation_ApplicationId, botId);
  10256. }
  10257. return botFrameworkConfig;
  10258. }
  10259. /**
  10260. * Creates a bot framework configuration instance for the specified authorization token and region.
  10261. * Note: The caller must ensure that an authorization token is valid. Before an authorization token expires, the
  10262. * caller must refresh it by setting the authorizationToken property on the corresponding
  10263. * DialogServiceConnector instance created with this config. The contents of configuration objects are copied
  10264. * when connectors are created, so setting authorizationToken on a DialogServiceConnector will not update the
  10265. * original configuration's authorization token. Create a new configuration instance or set the
  10266. * SpeechServiceAuthorization_Token property to update an existing instance if it will be used to create
  10267. * further DialogServiceConnectors.
  10268. * @member BotFrameworkConfig.fromAuthorizationToken
  10269. * @function
  10270. * @public
  10271. * @param authorizationToken The authorization token associated with the bot
  10272. * @param region The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).
  10273. * @param botId Optional. Identifier for using a specific bot within an Azure resource group. Equivalent to the
  10274. * resource name.
  10275. * @returns {BotFrameworkConfig} A new bot framework configuration instance.
  10276. */
  10277. static fromAuthorizationToken(authorizationToken, region, botId) {
  10278. Contracts_js_1.Contracts.throwIfNullOrWhitespace(authorizationToken, "authorizationToken");
  10279. Contracts_js_1.Contracts.throwIfNullOrWhitespace(region, "region");
  10280. const botFrameworkConfig = new DialogServiceConfig_js_1.DialogServiceConfigImpl();
  10281. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.Conversation_DialogType, DialogServiceConfig_js_1.DialogServiceConfig.DialogTypes.BotFramework);
  10282. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceAuthorization_Token, authorizationToken);
  10283. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Region, region);
  10284. if (botId) {
  10285. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.Conversation_ApplicationId, botId);
  10286. }
  10287. return botFrameworkConfig;
  10288. }
  10289. /**
  10290. * Creates an instance of a BotFrameworkConfig.
  10291. * This method is intended only for users who use a non-default service host. The standard resource path will be
  10292. * assumed. For services with a non-standard resource path or no path at all, use fromEndpoint instead.
  10293. * Note: Query parameters are not allowed in the host URI and must be set by other APIs.
  10294. * Note: To use an authorization token with fromHost, use fromHost(URL) and then set the AuthorizationToken
  10295. * property on the created BotFrameworkConfig instance.
  10296. * Note: Added in version 1.15.0.
  10297. * @member BotFrameworkConfig.fromHost
  10298. * @function
  10299. * @public
  10300. * @param {URL | string} host - If a URL is provided, the fully-qualified host with protocol (e.g.
  10301. * wss://your.host.com:1234) will be used. If a string is provided, it will be embedded in
  10302. * wss://{host}.convai.speech.azure.us.
  10303. * @param {string} subscriptionKey - The subscription key. If a subscription key is not specified, an authorization
  10304. * token must be set.
  10305. * @param botId Optional. Identifier for using a specific bot within an Azure resource group. Equivalent to the
  10306. * resource name.
  10307. * @returns {BotFrameworkConfig} A new bot framework configuration instance.
  10308. */
  10309. static fromHost(host, subscriptionKey, botId) {
  10310. void botId;
  10311. Contracts_js_1.Contracts.throwIfNullOrUndefined(host, "host");
  10312. const resolvedHost = host instanceof URL ? host : new URL(`wss://${host}.convai.speech.azure.us`);
  10313. Contracts_js_1.Contracts.throwIfNullOrUndefined(resolvedHost, "resolvedHost");
  10314. const botFrameworkConfig = new DialogServiceConfig_js_1.DialogServiceConfigImpl();
  10315. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.Conversation_DialogType, DialogServiceConfig_js_1.DialogServiceConfig.DialogTypes.BotFramework);
  10316. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Host, resolvedHost.toString());
  10317. if (undefined !== subscriptionKey) {
  10318. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Key, subscriptionKey);
  10319. }
  10320. return botFrameworkConfig;
  10321. }
  10322. /**
  10323. * Creates an instance of a BotFrameworkConfig.
  10324. * This method is intended only for users who use a non-standard service endpoint or parameters.
  10325. * Note: The query parameters specified in the endpoint URL are not changed, even if they are set by any other APIs.
  10326. * Note: To use authorization token with fromEndpoint, pass an empty string to the subscriptionKey in the
  10327. * fromEndpoint method, and then set authorizationToken="token" on the created BotFrameworkConfig instance to
  10328. * use the authorization token.
  10329. * Note: Added in version 1.15.0.
  10330. * @member BotFrameworkConfig.fromEndpoint
  10331. * @function
  10332. * @public
  10333. * @param {URL} endpoint - The service endpoint to connect to.
  10334. * @param {string} subscriptionKey - The subscription key. If a subscription key is not specified, an authorization
  10335. * token must be set.
  10336. * @returns {BotFrameworkConfig} - A new bot framework configuration instance using the provided endpoint.
  10337. */
  10338. static fromEndpoint(endpoint, subscriptionKey) {
  10339. Contracts_js_1.Contracts.throwIfNull(endpoint, "endpoint");
  10340. const botFrameworkConfig = new DialogServiceConfig_js_1.DialogServiceConfigImpl();
  10341. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.Conversation_DialogType, DialogServiceConfig_js_1.DialogServiceConfig.DialogTypes.BotFramework);
  10342. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Endpoint, endpoint.toString());
  10343. if (undefined !== subscriptionKey) {
  10344. botFrameworkConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Key, subscriptionKey);
  10345. }
  10346. return botFrameworkConfig;
  10347. }
  10348. }
  10349. exports.BotFrameworkConfig = BotFrameworkConfig;
  10350. /***/ }),
  10351. /* 132 */
  10352. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10353. "use strict";
  10354. // Copyright (c) Microsoft Corporation. All rights reserved.
  10355. // Licensed under the MIT license.
  10356. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10357. exports.CustomCommandsConfig = void 0;
  10358. const Contracts_js_1 = __webpack_require__(64);
  10359. const DialogServiceConfig_js_1 = __webpack_require__(130);
  10360. const Exports_js_1 = __webpack_require__(79);
  10361. /**
  10362. * Class that defines configurations for the dialog service connector object for using a CustomCommands backend.
  10363. * @class CustomCommandsConfig
  10364. */
  10365. class CustomCommandsConfig extends DialogServiceConfig_js_1.DialogServiceConfigImpl {
  10366. /**
  10367. * Creates an instance of CustomCommandsConfig.
  10368. */
  10369. constructor() {
  10370. super();
  10371. }
  10372. /**
  10373. * Creates an instance of the bot framework config with the specified subscription and region.
  10374. * @member CustomCommandsConfig.fromSubscription
  10375. * @function
  10376. * @public
  10377. * @param applicationId Speech Commands application id.
  10378. * @param subscription Subscription key associated with the bot
  10379. * @param region The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).
  10380. * @returns {CustomCommandsConfig} A new bot framework config.
  10381. */
  10382. static fromSubscription(applicationId, subscription, region) {
  10383. Contracts_js_1.Contracts.throwIfNullOrWhitespace(applicationId, "applicationId");
  10384. Contracts_js_1.Contracts.throwIfNullOrWhitespace(subscription, "subscription");
  10385. Contracts_js_1.Contracts.throwIfNullOrWhitespace(region, "region");
  10386. const customCommandsConfig = new DialogServiceConfig_js_1.DialogServiceConfigImpl();
  10387. customCommandsConfig.setProperty(Exports_js_1.PropertyId.Conversation_DialogType, DialogServiceConfig_js_1.DialogServiceConfig.DialogTypes.CustomCommands);
  10388. customCommandsConfig.setProperty(Exports_js_1.PropertyId.Conversation_ApplicationId, applicationId);
  10389. customCommandsConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Key, subscription);
  10390. customCommandsConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Region, region);
  10391. return customCommandsConfig;
  10392. }
  10393. /**
  10394. * Creates an instance of the bot framework config with the specified Speech Commands application id, authorization token and region.
  10395. * Note: The caller needs to ensure that the authorization token is valid. Before the authorization token
  10396. * expires, the caller needs to refresh it by calling this setter with a new valid token.
  10397. * As configuration values are copied when creating a new recognizer, the new token value will not apply to recognizers that have already been created.
  10398. * For recognizers that have been created before, you need to set authorization token of the corresponding recognizer
  10399. * to refresh the token. Otherwise, the recognizers will encounter errors during recognition.
  10400. * @member CustomCommandsConfig.fromAuthorizationToken
  10401. * @function
  10402. * @public
  10403. * @param applicationId Speech Commands application id.
  10404. * @param authorizationToken The authorization token associated with the application.
  10405. * @param region The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).
  10406. * @returns {CustomCommandsConfig} A new speech commands config.
  10407. */
  10408. static fromAuthorizationToken(applicationId, authorizationToken, region) {
  10409. Contracts_js_1.Contracts.throwIfNullOrWhitespace(applicationId, "applicationId");
  10410. Contracts_js_1.Contracts.throwIfNullOrWhitespace(authorizationToken, "authorizationToken");
  10411. Contracts_js_1.Contracts.throwIfNullOrWhitespace(region, "region");
  10412. const customCommandsConfig = new DialogServiceConfig_js_1.DialogServiceConfigImpl();
  10413. customCommandsConfig.setProperty(Exports_js_1.PropertyId.Conversation_DialogType, DialogServiceConfig_js_1.DialogServiceConfig.DialogTypes.CustomCommands);
  10414. customCommandsConfig.setProperty(Exports_js_1.PropertyId.Conversation_ApplicationId, applicationId);
  10415. customCommandsConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceAuthorization_Token, authorizationToken);
  10416. customCommandsConfig.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_Region, region);
  10417. return customCommandsConfig;
  10418. }
  10419. /**
  10420. * Sets the corresponding backend application identifier.
  10421. * @member CustomCommandsConfig.prototype.Conversation_ApplicationId
  10422. * @function
  10423. * @public
  10424. * @param {string} value - The application identifier to set.
  10425. */
  10426. set applicationId(value) {
  10427. Contracts_js_1.Contracts.throwIfNullOrWhitespace(value, "value");
  10428. this.setProperty(Exports_js_1.PropertyId.Conversation_ApplicationId, value);
  10429. }
  10430. /**
  10431. * Gets the corresponding backend application identifier.
  10432. * @member CustomCommandsConfig.prototype.Conversation_ApplicationId
  10433. * @function
  10434. * @public
  10435. * @param {string} value - The application identifier to get.
  10436. */
  10437. get applicationId() {
  10438. return this.getProperty(Exports_js_1.PropertyId.Conversation_ApplicationId);
  10439. }
  10440. }
  10441. exports.CustomCommandsConfig = CustomCommandsConfig;
  10442. /***/ }),
  10443. /* 133 */
  10444. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10445. "use strict";
  10446. // Copyright (c) Microsoft Corporation. All rights reserved.
  10447. // Licensed under the MIT license.
  10448. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10449. exports.DialogServiceConnector = void 0;
  10450. const DialogConnectorFactory_js_1 = __webpack_require__(134);
  10451. const Exports_js_1 = __webpack_require__(2);
  10452. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  10453. const Exports_js_2 = __webpack_require__(4);
  10454. const Contracts_js_1 = __webpack_require__(64);
  10455. const Exports_js_3 = __webpack_require__(79);
  10456. const PropertyId_js_1 = __webpack_require__(110);
  10457. /**
  10458. * Dialog Service Connector
  10459. * @class DialogServiceConnector
  10460. */
  10461. class DialogServiceConnector extends Exports_js_3.Recognizer {
  10462. /**
  10463. * Initializes an instance of the DialogServiceConnector.
  10464. * @constructor
  10465. * @param {DialogServiceConfig} dialogConfig - Set of properties to configure this recognizer.
  10466. * @param {AudioConfig} audioConfig - An optional audio config associated with the recognizer
  10467. */
  10468. constructor(dialogConfig, audioConfig) {
  10469. const dialogServiceConfigImpl = dialogConfig;
  10470. Contracts_js_1.Contracts.throwIfNull(dialogConfig, "dialogConfig");
  10471. super(audioConfig, dialogServiceConfigImpl.properties, new DialogConnectorFactory_js_1.DialogConnectionFactory());
  10472. this.isTurnComplete = true;
  10473. this.privIsDisposed = false;
  10474. this.privProperties = dialogServiceConfigImpl.properties.clone();
  10475. const agentConfig = this.buildAgentConfig();
  10476. this.privReco.agentConfig.set(agentConfig);
  10477. }
  10478. /**
  10479. * Starts a connection to the service.
  10480. * Users can optionally call connect() to manually set up a connection in advance, before starting interactions.
  10481. *
  10482. * Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to
  10483. * be notified when the connection is established.
  10484. * @member DialogServiceConnector.prototype.connect
  10485. * @function
  10486. * @public
  10487. */
  10488. connect(cb, err) {
  10489. (0, Exports_js_2.marshalPromiseToCallbacks)(this.privReco.connect(), cb, err);
  10490. }
  10491. /**
  10492. * Closes the connection the service.
  10493. * Users can optionally call disconnect() to manually shutdown the connection of the associated DialogServiceConnector.
  10494. *
  10495. * If disconnect() is called during a recognition, recognition will fail and cancel with an error.
  10496. */
  10497. disconnect(cb, err) {
  10498. (0, Exports_js_2.marshalPromiseToCallbacks)(this.privReco.disconnect(), cb, err);
  10499. }
  10500. /**
  10501. * Gets the authorization token used to communicate with the service.
  10502. * @member DialogServiceConnector.prototype.authorizationToken
  10503. * @function
  10504. * @public
  10505. * @returns {string} Authorization token.
  10506. */
  10507. get authorizationToken() {
  10508. return this.properties.getProperty(PropertyId_js_1.PropertyId.SpeechServiceAuthorization_Token);
  10509. }
  10510. /**
  10511. * Sets the authorization token used to communicate with the service.
  10512. * @member DialogServiceConnector.prototype.authorizationToken
  10513. * @function
  10514. * @public
  10515. * @param {string} token - Authorization token.
  10516. */
  10517. set authorizationToken(token) {
  10518. Contracts_js_1.Contracts.throwIfNullOrWhitespace(token, "token");
  10519. this.properties.setProperty(PropertyId_js_1.PropertyId.SpeechServiceAuthorization_Token, token);
  10520. }
  10521. /**
  10522. * The collection of properties and their values defined for this DialogServiceConnector.
  10523. * @member DialogServiceConnector.prototype.properties
  10524. * @function
  10525. * @public
  10526. * @returns {PropertyCollection} The collection of properties and their values defined for this DialogServiceConnector.
  10527. */
  10528. get properties() {
  10529. return this.privProperties;
  10530. }
  10531. /** Gets the template for the activity generated by service from speech.
  10532. * Properties from the template will be stamped on the generated activity.
  10533. * It can be empty
  10534. */
  10535. get speechActivityTemplate() {
  10536. return this.properties.getProperty(PropertyId_js_1.PropertyId.Conversation_Speech_Activity_Template);
  10537. }
  10538. /** Sets the template for the activity generated by service from speech.
  10539. * Properties from the template will be stamped on the generated activity.
  10540. * It can be null or empty.
  10541. * Note: it has to be a valid Json object.
  10542. */
  10543. set speechActivityTemplate(speechActivityTemplate) {
  10544. this.properties.setProperty(PropertyId_js_1.PropertyId.Conversation_Speech_Activity_Template, speechActivityTemplate);
  10545. }
  10546. /**
  10547. * Starts recognition and stops after the first utterance is recognized.
  10548. * @member DialogServiceConnector.prototype.listenOnceAsync
  10549. * @function
  10550. * @public
  10551. * @param cb - Callback that received the result when the reco has completed.
  10552. * @param err - Callback invoked in case of an error.
  10553. */
  10554. listenOnceAsync(cb, err) {
  10555. if (this.isTurnComplete) {
  10556. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  10557. const callbackHolder = async () => {
  10558. await this.privReco.connect();
  10559. await this.implRecognizerStop();
  10560. this.isTurnComplete = false;
  10561. const ret = new Exports_js_2.Deferred();
  10562. await this.privReco.recognize(PhraseDetectionContext_js_1.RecognitionMode.Conversation, ret.resolve, ret.reject);
  10563. const e = await ret.promise;
  10564. await this.implRecognizerStop();
  10565. return e;
  10566. };
  10567. const retPromise = callbackHolder();
  10568. retPromise.catch(() => {
  10569. // Destroy the recognizer.
  10570. // We've done all we can here.
  10571. // eslint-disable-next-line @typescript-eslint/no-empty-function
  10572. this.dispose(true).catch(() => { });
  10573. });
  10574. (0, Exports_js_2.marshalPromiseToCallbacks)(retPromise.finally(() => {
  10575. this.isTurnComplete = true;
  10576. }), cb, err);
  10577. }
  10578. }
  10579. sendActivityAsync(activity, cb, errCb) {
  10580. (0, Exports_js_2.marshalPromiseToCallbacks)(this.privReco.sendMessage(activity), cb, errCb);
  10581. }
  10582. /**
  10583. * closes all external resources held by an instance of this class.
  10584. * @member DialogServiceConnector.prototype.close
  10585. * @function
  10586. * @public
  10587. */
  10588. close(cb, err) {
  10589. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  10590. (0, Exports_js_2.marshalPromiseToCallbacks)(this.dispose(true), cb, err);
  10591. }
  10592. async dispose(disposing) {
  10593. if (this.privIsDisposed) {
  10594. return;
  10595. }
  10596. if (disposing) {
  10597. this.privIsDisposed = true;
  10598. await this.implRecognizerStop();
  10599. await super.dispose(disposing);
  10600. }
  10601. }
  10602. createRecognizerConfig(speechConfig) {
  10603. return new Exports_js_1.RecognizerConfig(speechConfig, this.privProperties);
  10604. }
  10605. createServiceRecognizer(authentication, connectionFactory, audioConfig, recognizerConfig) {
  10606. const audioSource = audioConfig;
  10607. return new Exports_js_1.DialogServiceAdapter(authentication, connectionFactory, audioSource, recognizerConfig, this);
  10608. }
  10609. buildAgentConfig() {
  10610. const communicationType = this.properties.getProperty("Conversation_Communication_Type", "Default");
  10611. return {
  10612. botInfo: {
  10613. commType: communicationType,
  10614. commandsCulture: undefined,
  10615. connectionId: this.properties.getProperty(PropertyId_js_1.PropertyId.Conversation_Agent_Connection_Id),
  10616. conversationId: this.properties.getProperty(PropertyId_js_1.PropertyId.Conversation_Conversation_Id, undefined),
  10617. fromId: this.properties.getProperty(PropertyId_js_1.PropertyId.Conversation_From_Id, undefined),
  10618. ttsAudioFormat: this.properties.getProperty(PropertyId_js_1.PropertyId.SpeechServiceConnection_SynthOutputFormat, undefined)
  10619. },
  10620. version: 0.2
  10621. };
  10622. }
  10623. }
  10624. exports.DialogServiceConnector = DialogServiceConnector;
  10625. /***/ }),
  10626. /* 134 */
  10627. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10628. "use strict";
  10629. // Copyright (c) Microsoft Corporation. All rights reserved.
  10630. // Licensed under the MIT license.
  10631. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10632. exports.DialogConnectionFactory = void 0;
  10633. /* eslint-disable max-classes-per-file */
  10634. const Exports_js_1 = __webpack_require__(60);
  10635. const Exports_js_2 = __webpack_require__(2);
  10636. const Exports_js_3 = __webpack_require__(79);
  10637. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  10638. const Exports_js_4 = __webpack_require__(2);
  10639. const HeaderNames_js_1 = __webpack_require__(54);
  10640. const QueryParameterNames_js_1 = __webpack_require__(136);
  10641. class DialogConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {
  10642. create(config, authInfo, connectionId) {
  10643. const applicationId = config.parameters.getProperty(Exports_js_3.PropertyId.Conversation_ApplicationId, "");
  10644. const dialogType = config.parameters.getProperty(Exports_js_3.PropertyId.Conversation_DialogType);
  10645. const region = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Region);
  10646. const language = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage, "en-US");
  10647. const requestTurnStatus = config.parameters.getProperty(Exports_js_3.PropertyId.Conversation_Request_Bot_Status_Messages, "true");
  10648. const queryParams = {};
  10649. queryParams[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;
  10650. queryParams[QueryParameterNames_js_1.QueryParameterNames.Format] = config.parameters.getProperty(Exports_js_2.OutputFormatPropertyName, Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Simple]).toLowerCase();
  10651. queryParams[QueryParameterNames_js_1.QueryParameterNames.Language] = language;
  10652. queryParams[QueryParameterNames_js_1.QueryParameterNames.RequestBotStatusMessages] = requestTurnStatus;
  10653. if (applicationId) {
  10654. queryParams[QueryParameterNames_js_1.QueryParameterNames.BotId] = applicationId;
  10655. if (dialogType === Exports_js_3.DialogServiceConfig.DialogTypes.CustomCommands) {
  10656. queryParams[HeaderNames_js_1.HeaderNames.CustomCommandsAppId] = applicationId;
  10657. }
  10658. }
  10659. const resourceInfix = dialogType === Exports_js_3.DialogServiceConfig.DialogTypes.CustomCommands ? "commands/"
  10660. : "";
  10661. const version = dialogType === Exports_js_3.DialogServiceConfig.DialogTypes.CustomCommands ? "v1"
  10662. : dialogType === Exports_js_3.DialogServiceConfig.DialogTypes.BotFramework ? "v3"
  10663. : "v0";
  10664. const headers = {};
  10665. if (authInfo.token != null && authInfo.token !== "") {
  10666. headers[authInfo.headerName] = authInfo.token;
  10667. }
  10668. // The URL used for connection is chosen in a priority order of specification:
  10669. // 1. If a custom endpoint is provided, that URL is used verbatim.
  10670. // 2. If a custom host is provided (e.g. "wss://my.custom.endpoint.com:1123"), a URL is constructed from it.
  10671. // 3. If no custom connection details are provided, a URL is constructed from default values.
  10672. let endpoint = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Endpoint, "");
  10673. if (!endpoint) {
  10674. const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);
  10675. const host = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Host, `wss://${region}.${DialogConnectionFactory.BaseUrl}${hostSuffix}`);
  10676. const standardizedHost = host.endsWith("/") ? host : host + "/";
  10677. endpoint = `${standardizedHost}${resourceInfix}${DialogConnectionFactory.ApiKey}/${version}`;
  10678. }
  10679. this.setCommonUrlParams(config, queryParams, endpoint);
  10680. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "false") === "true";
  10681. return Promise.resolve(new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_4.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId));
  10682. }
  10683. }
  10684. exports.DialogConnectionFactory = DialogConnectionFactory;
  10685. DialogConnectionFactory.ApiKey = "api";
  10686. DialogConnectionFactory.BaseUrl = "convai.speech";
  10687. /***/ }),
  10688. /* 135 */
  10689. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10690. "use strict";
  10691. // Copyright (c) Microsoft Corporation. All rights reserved.
  10692. // Licensed under the MIT license.
  10693. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10694. exports.ConnectionFactoryBase = void 0;
  10695. const Exports_js_1 = __webpack_require__(2);
  10696. const Exports_js_2 = __webpack_require__(4);
  10697. const Exports_js_3 = __webpack_require__(79);
  10698. const QueryParameterNames_js_1 = __webpack_require__(136);
  10699. class ConnectionFactoryBase {
  10700. static getHostSuffix(region) {
  10701. if (!!region) {
  10702. if (region.toLowerCase().startsWith("china")) {
  10703. return ".azure.cn";
  10704. }
  10705. if (region.toLowerCase().startsWith("usgov")) {
  10706. return ".azure.us";
  10707. }
  10708. }
  10709. return ".microsoft.com";
  10710. }
  10711. setCommonUrlParams(config, queryParams, endpoint) {
  10712. const propertyIdToParameterMap = new Map([
  10713. [Exports_js_3.PropertyId.Speech_SegmentationSilenceTimeoutMs, QueryParameterNames_js_1.QueryParameterNames.SegmentationSilenceTimeoutMs],
  10714. [Exports_js_3.PropertyId.SpeechServiceConnection_EnableAudioLogging, QueryParameterNames_js_1.QueryParameterNames.EnableAudioLogging],
  10715. [Exports_js_3.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, QueryParameterNames_js_1.QueryParameterNames.EndSilenceTimeoutMs],
  10716. [Exports_js_3.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, QueryParameterNames_js_1.QueryParameterNames.InitialSilenceTimeoutMs],
  10717. [Exports_js_3.PropertyId.SpeechServiceResponse_PostProcessingOption, QueryParameterNames_js_1.QueryParameterNames.Postprocessing],
  10718. [Exports_js_3.PropertyId.SpeechServiceResponse_ProfanityOption, QueryParameterNames_js_1.QueryParameterNames.Profanity],
  10719. [Exports_js_3.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, QueryParameterNames_js_1.QueryParameterNames.EnableWordLevelTimestamps],
  10720. [Exports_js_3.PropertyId.SpeechServiceResponse_StablePartialResultThreshold, QueryParameterNames_js_1.QueryParameterNames.StableIntermediateThreshold],
  10721. ]);
  10722. propertyIdToParameterMap.forEach((parameterName, propertyId) => {
  10723. this.setUrlParameter(propertyId, parameterName, config, queryParams, endpoint);
  10724. });
  10725. const serviceProperties = JSON.parse(config.parameters.getProperty(Exports_js_1.ServicePropertiesPropertyName, "{}"));
  10726. Object.keys(serviceProperties).forEach((value) => {
  10727. queryParams[value] = serviceProperties[value];
  10728. });
  10729. }
  10730. setUrlParameter(propId, parameterName, config, queryParams, endpoint) {
  10731. const value = config.parameters.getProperty(propId, undefined);
  10732. // FIXME: The .search() check will incorrectly match parameter name anywhere in the string
  10733. // including e.g. the path portion, or even as a substring of other query parameters
  10734. if (value && (!endpoint || endpoint.search(parameterName) === -1)) {
  10735. queryParams[parameterName] = value.toLocaleLowerCase();
  10736. }
  10737. }
  10738. static async getRedirectUrlFromEndpoint(endpoint) {
  10739. let redirectUrlString;
  10740. if (typeof window !== "undefined" && typeof window.fetch !== "undefined") {
  10741. // make a rest call to the endpoint to get the redirect url
  10742. const redirectUrl = new URL(endpoint);
  10743. redirectUrl.protocol = "https:";
  10744. redirectUrl.port = "443";
  10745. const params = redirectUrl.searchParams;
  10746. params.append("GenerateRedirectResponse", "true");
  10747. const redirectedUrlString = redirectUrl.toString();
  10748. Exports_js_2.Events.instance.onEvent(new Exports_js_2.ConnectionRedirectEvent("", redirectedUrlString, undefined, "ConnectionFactoryBase: redirectUrl request"));
  10749. const redirectResponse = await fetch(redirectedUrlString);
  10750. if (redirectResponse.status !== 200) {
  10751. return endpoint;
  10752. }
  10753. // Fix: properly read the response text
  10754. redirectUrlString = await redirectResponse.text();
  10755. }
  10756. else {
  10757. redirectUrlString = endpoint;
  10758. }
  10759. Exports_js_2.Events.instance.onEvent(new Exports_js_2.ConnectionRedirectEvent("", redirectUrlString, endpoint, "ConnectionFactoryBase: redirectUrlString"));
  10760. try {
  10761. // Validate the URL before returning
  10762. return new URL(redirectUrlString.trim()).toString();
  10763. }
  10764. catch (error) {
  10765. return endpoint; // Return original endpoint if the redirect URL is invalid
  10766. }
  10767. }
  10768. }
  10769. exports.ConnectionFactoryBase = ConnectionFactoryBase;
  10770. /***/ }),
  10771. /* 136 */
  10772. /***/ ((__unused_webpack_module, exports) => {
  10773. "use strict";
  10774. // Copyright (c) Microsoft Corporation. All rights reserved.
  10775. // Licensed under the MIT license.
  10776. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10777. exports.QueryParameterNames = void 0;
  10778. class QueryParameterNames {
  10779. }
  10780. exports.QueryParameterNames = QueryParameterNames;
  10781. QueryParameterNames.BotId = "botid";
  10782. QueryParameterNames.CustomSpeechDeploymentId = "cid";
  10783. QueryParameterNames.CustomVoiceDeploymentId = "deploymentId";
  10784. QueryParameterNames.EnableAudioLogging = "storeAudio";
  10785. QueryParameterNames.EnableLanguageId = "lidEnabled";
  10786. QueryParameterNames.EnableWordLevelTimestamps = "wordLevelTimestamps";
  10787. QueryParameterNames.EndSilenceTimeoutMs = "endSilenceTimeoutMs";
  10788. QueryParameterNames.SegmentationSilenceTimeoutMs = "segmentationSilenceTimeoutMs";
  10789. QueryParameterNames.SegmentationMaximumTimeMs = "segmentationMaximumTimeMs";
  10790. QueryParameterNames.SegmentationStrategy = "segmentationStrategy";
  10791. QueryParameterNames.Format = "format";
  10792. QueryParameterNames.InitialSilenceTimeoutMs = "initialSilenceTimeoutMs";
  10793. QueryParameterNames.Language = "language";
  10794. QueryParameterNames.Profanity = "profanity";
  10795. QueryParameterNames.RequestBotStatusMessages = "enableBotMessageStatus";
  10796. QueryParameterNames.StableIntermediateThreshold = "stableIntermediateThreshold";
  10797. QueryParameterNames.StableTranslation = "stableTranslation";
  10798. QueryParameterNames.TestHooks = "testhooks";
  10799. QueryParameterNames.Postprocessing = "postprocessing";
  10800. QueryParameterNames.CtsMeetingId = "meetingId";
  10801. QueryParameterNames.CtsDeviceId = "deviceId";
  10802. QueryParameterNames.CtsIsParticipant = "isParticipant";
  10803. QueryParameterNames.EnableAvatar = "enableTalkingAvatar";
  10804. /***/ }),
  10805. /* 137 */
  10806. /***/ ((__unused_webpack_module, exports) => {
  10807. "use strict";
  10808. // Copyright (c) Microsoft Corporation. All rights reserved.
  10809. // Licensed under the MIT license.
  10810. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10811. exports.ActivityReceivedEventArgs = void 0;
  10812. /**
  10813. * Defines contents of received message/events.
  10814. * @class ActivityReceivedEventArgs
  10815. */
  10816. class ActivityReceivedEventArgs {
  10817. /**
  10818. * Creates and initializes an instance of this class.
  10819. * @constructor
  10820. * @param {any} activity - The activity..
  10821. */
  10822. constructor(activity, audioStream) {
  10823. this.privActivity = activity;
  10824. this.privAudioStream = audioStream;
  10825. }
  10826. /**
  10827. * Gets the received activity
  10828. * @member ActivityReceivedEventArgs.prototype.activity
  10829. * @function
  10830. * @public
  10831. * @returns {any} the received activity.
  10832. */
  10833. get activity() {
  10834. return this.privActivity;
  10835. }
  10836. get audioStream() {
  10837. return this.privAudioStream;
  10838. }
  10839. }
  10840. exports.ActivityReceivedEventArgs = ActivityReceivedEventArgs;
  10841. /***/ }),
  10842. /* 138 */
  10843. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10844. "use strict";
  10845. // Copyright (c) Microsoft Corporation. All rights reserved.
  10846. // Licensed under the MIT license.
  10847. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10848. exports.TurnStatusReceivedEventArgs = void 0;
  10849. const TurnStatusPayload_js_1 = __webpack_require__(139);
  10850. /**
  10851. * Defines contents of received message/events.
  10852. * @class TurnStatusReceivedEventArgs
  10853. */
  10854. class TurnStatusReceivedEventArgs {
  10855. /**
  10856. * Creates and initializes an instance of this class.
  10857. * @constructor
  10858. * @param {string} turnStatus - The JSON-encoded turn status message.
  10859. */
  10860. constructor(turnStatus) {
  10861. this.privTurnStatus = TurnStatusPayload_js_1.TurnStatusResponsePayload.fromJSON(turnStatus);
  10862. }
  10863. /**
  10864. * Gets the interaction identifier associated with this turn status event.
  10865. * @member TurnStatusReceivedEventArgs.prototype.interactionId
  10866. * @function
  10867. * @public
  10868. * @returns {any} the received interaction id.
  10869. */
  10870. get interactionId() {
  10871. return this.privTurnStatus.interactionId;
  10872. }
  10873. /**
  10874. * Gets the conversation identifier associated with this turn status event.
  10875. * @member TurnStatusReceivedEventArgs.prototype.conversationId
  10876. * @function
  10877. * @public
  10878. * @returns {any} the received conversation id.
  10879. */
  10880. get conversationId() {
  10881. return this.privTurnStatus.conversationId;
  10882. }
  10883. /**
  10884. * Gets the received turn status code.
  10885. * @member TurnStatusReceivedEventArgs.prototype.statusCode
  10886. * @function
  10887. * @public
  10888. * @returns {number} the received turn status.
  10889. */
  10890. get statusCode() {
  10891. return this.privTurnStatus.statusCode; // eslint-disable-line @typescript-eslint/no-unsafe-return
  10892. }
  10893. }
  10894. exports.TurnStatusReceivedEventArgs = TurnStatusReceivedEventArgs;
  10895. /***/ }),
  10896. /* 139 */
  10897. /***/ ((__unused_webpack_module, exports) => {
  10898. "use strict";
  10899. // Copyright (c) Microsoft Corporation. All rights reserved.
  10900. // Licensed under the MIT license.
  10901. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10902. exports.TurnStatusResponsePayload = void 0;
  10903. class TurnStatusResponsePayload {
  10904. constructor(json) {
  10905. this.privMessageStatusResponse = JSON.parse(json);
  10906. }
  10907. static fromJSON(json) {
  10908. return new TurnStatusResponsePayload(json);
  10909. }
  10910. get interactionId() {
  10911. return this.privMessageStatusResponse.interactionId;
  10912. }
  10913. get conversationId() {
  10914. return this.privMessageStatusResponse.conversationId;
  10915. }
  10916. get statusCode() {
  10917. // Payloads may contain a limited set of textual representations or a numeric status
  10918. // code. The textual values are here converted into numeric ones.
  10919. switch (this.privMessageStatusResponse.statusCode) {
  10920. case "Success":
  10921. return 200;
  10922. case "Failed":
  10923. return 400;
  10924. case "TimedOut":
  10925. return 429;
  10926. default:
  10927. // eslint-disable-next-line @typescript-eslint/no-unsafe-return
  10928. return this.privMessageStatusResponse.statusCode;
  10929. }
  10930. }
  10931. }
  10932. exports.TurnStatusResponsePayload = TurnStatusResponsePayload;
  10933. /***/ }),
  10934. /* 140 */
  10935. /***/ ((__unused_webpack_module, exports) => {
  10936. "use strict";
  10937. // Copyright (c) Microsoft Corporation.
  10938. // Licensed under the MIT license.
  10939. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10940. exports.ServicePropertyChannel = void 0;
  10941. /**
  10942. * Defines channels used to pass property settings to service.
  10943. * Added in version 1.7.0.
  10944. */
  10945. var ServicePropertyChannel;
  10946. (function (ServicePropertyChannel) {
  10947. /**
  10948. * Uses URI query parameter to pass property settings to service.
  10949. */
  10950. ServicePropertyChannel[ServicePropertyChannel["UriQueryParameter"] = 0] = "UriQueryParameter";
  10951. })(ServicePropertyChannel = exports.ServicePropertyChannel || (exports.ServicePropertyChannel = {}));
  10952. /***/ }),
  10953. /* 141 */
  10954. /***/ ((__unused_webpack_module, exports) => {
  10955. "use strict";
  10956. // Copyright (c) Microsoft Corporation.
  10957. // Licensed under the MIT license.
  10958. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10959. exports.ProfanityOption = void 0;
  10960. /**
  10961. * Profanity option.
  10962. * Added in version 1.7.0.
  10963. */
  10964. var ProfanityOption;
  10965. (function (ProfanityOption) {
  10966. ProfanityOption[ProfanityOption["Masked"] = 0] = "Masked";
  10967. ProfanityOption[ProfanityOption["Removed"] = 1] = "Removed";
  10968. ProfanityOption[ProfanityOption["Raw"] = 2] = "Raw";
  10969. })(ProfanityOption = exports.ProfanityOption || (exports.ProfanityOption = {}));
  10970. /***/ }),
  10971. /* 142 */
  10972. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10973. "use strict";
  10974. // Copyright (c) Microsoft Corporation. All rights reserved.
  10975. // Licensed under the MIT license.
  10976. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10977. exports.BaseAudioPlayer = void 0;
  10978. const Error_js_1 = __webpack_require__(26);
  10979. const Exports_js_1 = __webpack_require__(79);
  10980. const AudioStreamFormat_js_1 = __webpack_require__(67);
  10981. /**
  10982. * Base audio player class
  10983. * TODO: Plays only PCM for now.
  10984. * @class
  10985. */
  10986. class BaseAudioPlayer {
  10987. /**
  10988. * Creates and initializes an instance of this class.
  10989. * @constructor
  10990. * @param {AudioStreamFormat} audioFormat audio stream format recognized by the player.
  10991. */
  10992. constructor(audioFormat) {
  10993. this.audioContext = null;
  10994. this.gainNode = null;
  10995. this.autoUpdateBufferTimer = 0;
  10996. if (audioFormat === undefined) {
  10997. audioFormat = Exports_js_1.AudioStreamFormat.getDefaultInputFormat();
  10998. }
  10999. this.init(audioFormat);
  11000. }
  11001. /**
  11002. * play Audio sample
  11003. * @param newAudioData audio data to be played.
  11004. */
  11005. playAudioSample(newAudioData, cb, err) {
  11006. try {
  11007. this.ensureInitializedContext();
  11008. const audioData = this.formatAudioData(newAudioData);
  11009. const newSamplesData = new Float32Array(this.samples.length + audioData.length);
  11010. newSamplesData.set(this.samples, 0);
  11011. newSamplesData.set(audioData, this.samples.length);
  11012. this.samples = newSamplesData;
  11013. if (!!cb) {
  11014. cb();
  11015. }
  11016. }
  11017. catch (e) {
  11018. if (!!err) {
  11019. err(e);
  11020. }
  11021. }
  11022. }
  11023. /**
  11024. * stops audio and clears the buffers
  11025. */
  11026. stopAudio(cb, err) {
  11027. if (this.audioContext !== null) {
  11028. this.samples = new Float32Array();
  11029. // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  11030. clearInterval(this.autoUpdateBufferTimer);
  11031. this.audioContext.close().then(() => {
  11032. if (!!cb) {
  11033. cb();
  11034. }
  11035. }, (error) => {
  11036. if (!!err) {
  11037. err(error);
  11038. }
  11039. });
  11040. this.audioContext = null;
  11041. }
  11042. }
  11043. init(audioFormat) {
  11044. this.audioFormat = audioFormat;
  11045. this.samples = new Float32Array();
  11046. }
  11047. ensureInitializedContext() {
  11048. if (this.audioContext === null) {
  11049. this.createAudioContext();
  11050. const timerPeriod = 200;
  11051. this.autoUpdateBufferTimer = setInterval(() => {
  11052. this.updateAudioBuffer();
  11053. }, timerPeriod);
  11054. }
  11055. }
  11056. createAudioContext() {
  11057. // new ((window as any).AudioContext || (window as any).webkitAudioContext)();
  11058. this.audioContext = AudioStreamFormat_js_1.AudioStreamFormatImpl.getAudioContext();
  11059. // TODO: Various examples shows this gain node, it does not seem to be needed unless we plan
  11060. // to control the volume, not likely
  11061. this.gainNode = this.audioContext.createGain();
  11062. this.gainNode.gain.value = 1;
  11063. this.gainNode.connect(this.audioContext.destination);
  11064. this.startTime = this.audioContext.currentTime;
  11065. }
  11066. formatAudioData(audioData) {
  11067. switch (this.audioFormat.bitsPerSample) {
  11068. case 8:
  11069. return this.formatArrayBuffer(new Int8Array(audioData), 128);
  11070. case 16:
  11071. return this.formatArrayBuffer(new Int16Array(audioData), 32768);
  11072. case 32:
  11073. return this.formatArrayBuffer(new Int32Array(audioData), 2147483648);
  11074. default:
  11075. throw new Error_js_1.InvalidOperationError("Only WAVE_FORMAT_PCM (8/16/32 bps) format supported at this time");
  11076. }
  11077. }
  11078. formatArrayBuffer(audioData, maxValue) {
  11079. const float32Data = new Float32Array(audioData.length);
  11080. for (let i = 0; i < audioData.length; i++) {
  11081. float32Data[i] = audioData[i] / maxValue;
  11082. }
  11083. return float32Data;
  11084. }
  11085. updateAudioBuffer() {
  11086. if (this.samples.length === 0) {
  11087. return;
  11088. }
  11089. const channelCount = this.audioFormat.channels;
  11090. const bufferSource = this.audioContext.createBufferSource();
  11091. const frameCount = this.samples.length / channelCount;
  11092. const audioBuffer = this.audioContext.createBuffer(channelCount, frameCount, this.audioFormat.samplesPerSec);
  11093. // TODO: Should we do the conversion in the pushAudioSample instead?
  11094. for (let channel = 0; channel < channelCount; channel++) {
  11095. // Fill in individual channel data
  11096. let channelOffset = channel;
  11097. const audioData = audioBuffer.getChannelData(channel);
  11098. for (let i = 0; i < this.samples.length; i++, channelOffset += channelCount) {
  11099. audioData[i] = this.samples[channelOffset];
  11100. }
  11101. }
  11102. if (this.startTime < this.audioContext.currentTime) {
  11103. this.startTime = this.audioContext.currentTime;
  11104. }
  11105. bufferSource.buffer = audioBuffer;
  11106. bufferSource.connect(this.gainNode);
  11107. bufferSource.start(this.startTime);
  11108. // Make sure we play the next sample after the current one.
  11109. this.startTime += audioBuffer.duration;
  11110. // Clear the samples for the next pushed data.
  11111. this.samples = new Float32Array();
  11112. }
  11113. async playAudio(audioData) {
  11114. if (this.audioContext === null) {
  11115. this.createAudioContext();
  11116. }
  11117. const source = this.audioContext.createBufferSource();
  11118. const destination = this.audioContext.destination;
  11119. await this.audioContext.decodeAudioData(audioData, (newBuffer) => {
  11120. source.buffer = newBuffer;
  11121. source.connect(destination);
  11122. source.start(0);
  11123. });
  11124. }
  11125. }
  11126. exports.BaseAudioPlayer = BaseAudioPlayer;
  11127. /***/ }),
  11128. /* 143 */
  11129. /***/ ((__unused_webpack_module, exports) => {
  11130. "use strict";
  11131. //
  11132. // Copyright (c) Microsoft. All rights reserved.
  11133. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  11134. //
  11135. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11136. exports.ConnectionMessageEventArgs = void 0;
  11137. class ConnectionMessageEventArgs {
  11138. constructor(message) {
  11139. this.privConnectionMessage = message;
  11140. }
  11141. /**
  11142. * Gets the <see cref="ConnectionMessage"/> associated with this <see cref="ConnectionMessageEventArgs"/>.
  11143. */
  11144. get message() {
  11145. return this.privConnectionMessage;
  11146. }
  11147. /**
  11148. * Returns a string that represents the connection message event.
  11149. */
  11150. toString() {
  11151. return "Message: " + this.privConnectionMessage.toString();
  11152. }
  11153. }
  11154. exports.ConnectionMessageEventArgs = ConnectionMessageEventArgs;
  11155. /***/ }),
  11156. /* 144 */
  11157. /***/ ((__unused_webpack_module, exports) => {
  11158. "use strict";
  11159. // Copyright (c) Microsoft Corporation. All rights reserved.
  11160. // Licensed under the MIT license.
  11161. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11162. exports.VoiceProfile = void 0;
  11163. /**
  11164. * Defines Voice Profile class for Speaker Recognition
  11165. * @class VoiceProfile
  11166. */
  11167. class VoiceProfile {
  11168. /**
  11169. * Creates and initializes an instance of this class.
  11170. * @constructor
  11171. * @param {string} profileId - profileId of this Voice Profile.
  11172. * @param {VoiceProfileType} profileType - profileType of this Voice Profile.
  11173. */
  11174. constructor(profileId, profileType) {
  11175. this.privId = profileId;
  11176. this.privProfileType = profileType;
  11177. }
  11178. /**
  11179. * profileId of this Voice Profile instance
  11180. * @member VoiceProfile.prototype.profileId
  11181. * @function
  11182. * @public
  11183. * @returns {string} profileId of this Voice Profile instance.
  11184. */
  11185. get profileId() {
  11186. return this.privId;
  11187. }
  11188. /**
  11189. * profileType of this Voice Profile instance
  11190. * @member VoiceProfile.prototype.profileType
  11191. * @function
  11192. * @public
  11193. * @returns {VoiceProfileType} profile type of this Voice Profile instance.
  11194. */
  11195. get profileType() {
  11196. return this.privProfileType;
  11197. }
  11198. }
  11199. exports.VoiceProfile = VoiceProfile;
  11200. /***/ }),
  11201. /* 145 */
  11202. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11203. "use strict";
  11204. // Copyright (c) Microsoft Corporation. All rights reserved.
  11205. // Licensed under the MIT license.
  11206. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11207. exports.VoiceProfileEnrollmentCancellationDetails = exports.VoiceProfileEnrollmentResult = void 0;
  11208. /* eslint-disable max-classes-per-file */
  11209. const Exports_js_1 = __webpack_require__(2);
  11210. const Exports_js_2 = __webpack_require__(79);
  11211. /**
  11212. * Output format
  11213. * @class VoiceProfileEnrollmentResult
  11214. */
  11215. class VoiceProfileEnrollmentResult {
  11216. constructor(reason, json, statusText) {
  11217. this.privReason = reason;
  11218. this.privProperties = new Exports_js_2.PropertyCollection();
  11219. if (this.privReason !== Exports_js_2.ResultReason.Canceled) {
  11220. if (!!json) {
  11221. this.privDetails = JSON.parse(json);
  11222. if (this.privDetails.enrollmentStatus.toLowerCase() === "enrolling") {
  11223. this.privReason = Exports_js_2.ResultReason.EnrollingVoiceProfile;
  11224. }
  11225. }
  11226. }
  11227. else {
  11228. this.privErrorDetails = statusText;
  11229. this.privProperties.setProperty(Exports_js_1.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[Exports_js_2.CancellationErrorCode.ServiceError]);
  11230. }
  11231. }
  11232. get reason() {
  11233. return this.privReason;
  11234. }
  11235. get enrollmentsCount() {
  11236. return this.privDetails.enrollmentsCount;
  11237. }
  11238. get enrollmentsLength() {
  11239. return this.privDetails.enrollmentsLength;
  11240. }
  11241. get properties() {
  11242. return this.privProperties;
  11243. }
  11244. get enrollmentResultDetails() {
  11245. return this.privDetails;
  11246. }
  11247. get errorDetails() {
  11248. return this.privErrorDetails;
  11249. }
  11250. static FromIdentificationProfileList(json) {
  11251. const results = [];
  11252. for (const item of json.value) {
  11253. const reason = item.enrollmentStatus.toLowerCase() === "enrolling" ?
  11254. Exports_js_2.ResultReason.EnrollingVoiceProfile : item.enrollmentStatus.toLowerCase() === "enrolled" ?
  11255. Exports_js_2.ResultReason.EnrolledVoiceProfile : Exports_js_2.ResultReason.Canceled;
  11256. const result = new VoiceProfileEnrollmentResult(reason, null, null);
  11257. result.privDetails = this.getIdentificationDetails(item);
  11258. results.push(result);
  11259. }
  11260. return results;
  11261. }
  11262. static FromVerificationProfileList(json) {
  11263. const results = [];
  11264. for (const item of json.value) {
  11265. const reason = item.enrollmentStatus.toLowerCase() === "enrolling" ?
  11266. Exports_js_2.ResultReason.EnrollingVoiceProfile : item.enrollmentStatus.toLowerCase() === "enrolled" ?
  11267. Exports_js_2.ResultReason.EnrolledVoiceProfile : Exports_js_2.ResultReason.Canceled;
  11268. const result = new VoiceProfileEnrollmentResult(reason, null, null);
  11269. result.privDetails = this.getVerificationDetails(item);
  11270. results.push(result);
  11271. }
  11272. return results;
  11273. }
  11274. static getIdentificationDetails(json) {
  11275. return {
  11276. audioLength: json.audioLength ? parseFloat(json.audioLength) : 0,
  11277. audioSpeechLength: json.audioSpeechLength ? parseFloat(json.audioSpeechLength) : 0,
  11278. enrollmentStatus: json.enrollmentStatus,
  11279. enrollmentsCount: json.enrollmentsCount || 0,
  11280. enrollmentsLength: json.enrollmentsLength ? parseFloat(json.enrollmentsLength) : 0,
  11281. enrollmentsSpeechLength: json.enrollmentsSpeechLength ? parseFloat(json.enrollmentsSpeechLength) : 0,
  11282. profileId: json.profileId || json.identificationProfileId,
  11283. remainingEnrollmentsSpeechLength: json.remainingEnrollmentsSpeechLength ? parseFloat(json.remainingEnrollmentsSpeechLength) : 0
  11284. };
  11285. }
  11286. static getVerificationDetails(json) {
  11287. return {
  11288. audioLength: json.audioLength ? parseFloat(json.audioLength) : 0,
  11289. audioSpeechLength: json.audioSpeechLength ? parseFloat(json.audioSpeechLength) : 0,
  11290. enrollmentStatus: json.enrollmentStatus,
  11291. enrollmentsCount: json.enrollmentsCount,
  11292. enrollmentsLength: json.enrollmentsLength ? parseFloat(json.enrollmentsLength) : 0,
  11293. enrollmentsSpeechLength: json.enrollmentsSpeechLength ? parseFloat(json.enrollmentsSpeechLength) : 0,
  11294. profileId: json.profileId || json.verificationProfileId,
  11295. remainingEnrollmentsCount: json.remainingEnrollments || json.remainingEnrollmentsCount,
  11296. remainingEnrollmentsSpeechLength: json.remainingEnrollmentsSpeechLength ? parseFloat(json.remainingEnrollmentsSpeechLength) : 0
  11297. };
  11298. }
  11299. }
  11300. exports.VoiceProfileEnrollmentResult = VoiceProfileEnrollmentResult;
  11301. /**
  11302. * @class VoiceProfileEnrollmentCancellationDetails
  11303. */
  11304. class VoiceProfileEnrollmentCancellationDetails extends Exports_js_2.CancellationDetailsBase {
  11305. constructor(reason, errorDetails, errorCode) {
  11306. super(reason, errorDetails, errorCode);
  11307. }
  11308. /**
  11309. * Creates an instance of VoiceProfileEnrollmentCancellationDetails object for the canceled VoiceProfileEnrollmentResult.
  11310. * @member VoiceProfileEnrollmentCancellationDetails.fromResult
  11311. * @function
  11312. * @public
  11313. * @param {VoiceProfileEnrollmentResult} result - The result that was canceled.
  11314. * @returns {VoiceProfileEnrollmentCancellationDetails} The cancellation details object being created.
  11315. */
  11316. static fromResult(result) {
  11317. const reason = Exports_js_2.CancellationReason.Error;
  11318. let errorCode = Exports_js_2.CancellationErrorCode.NoError;
  11319. if (!!result.properties) {
  11320. errorCode = Exports_js_2.CancellationErrorCode[result.properties.getProperty(Exports_js_1.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[Exports_js_2.CancellationErrorCode.NoError])]; //eslint-disable-line
  11321. }
  11322. return new VoiceProfileEnrollmentCancellationDetails(reason, result.errorDetails, errorCode);
  11323. }
  11324. }
  11325. exports.VoiceProfileEnrollmentCancellationDetails = VoiceProfileEnrollmentCancellationDetails;
  11326. /***/ }),
  11327. /* 146 */
  11328. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11329. "use strict";
  11330. // Copyright (c) Microsoft Corporation. All rights reserved.
  11331. // Licensed under the MIT license.
  11332. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11333. exports.VoiceProfileCancellationDetails = exports.VoiceProfileResult = void 0;
  11334. /* eslint-disable max-classes-per-file */
  11335. const Exports_js_1 = __webpack_require__(2);
  11336. const Contracts_js_1 = __webpack_require__(64);
  11337. const Exports_js_2 = __webpack_require__(79);
  11338. /**
  11339. * Output format
  11340. * @class VoiceProfileResult
  11341. */
  11342. class VoiceProfileResult {
  11343. constructor(reason, statusText) {
  11344. this.privReason = reason;
  11345. this.privProperties = new Exports_js_2.PropertyCollection();
  11346. if (reason === Exports_js_2.ResultReason.Canceled) {
  11347. Contracts_js_1.Contracts.throwIfNullOrUndefined(statusText, "statusText");
  11348. this.privErrorDetails = statusText;
  11349. this.privProperties.setProperty(Exports_js_1.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[Exports_js_2.CancellationErrorCode.ServiceError]);
  11350. }
  11351. }
  11352. get reason() {
  11353. return this.privReason;
  11354. }
  11355. get properties() {
  11356. return this.privProperties;
  11357. }
  11358. get errorDetails() {
  11359. return this.privErrorDetails;
  11360. }
  11361. }
  11362. exports.VoiceProfileResult = VoiceProfileResult;
  11363. /**
  11364. * @class VoiceProfileCancellationDetails
  11365. */
  11366. class VoiceProfileCancellationDetails extends Exports_js_2.CancellationDetailsBase {
  11367. constructor(reason, errorDetails, errorCode) {
  11368. super(reason, errorDetails, errorCode);
  11369. }
  11370. /**
  11371. * Creates an instance of VoiceProfileCancellationDetails object for the canceled VoiceProfileResult.
  11372. * @member VoiceProfileCancellationDetails.fromResult
  11373. * @function
  11374. * @public
  11375. * @param {VoiceProfileResult} result - The result that was canceled.
  11376. * @returns {VoiceProfileCancellationDetails} The cancellation details object being created.
  11377. */
  11378. static fromResult(result) {
  11379. const reason = Exports_js_2.CancellationReason.Error;
  11380. let errorCode = Exports_js_2.CancellationErrorCode.NoError;
  11381. if (!!result.properties) {
  11382. errorCode = Exports_js_2.CancellationErrorCode[result.properties.getProperty(Exports_js_1.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[Exports_js_2.CancellationErrorCode.NoError])]; //eslint-disable-line
  11383. }
  11384. return new VoiceProfileCancellationDetails(reason, result.errorDetails, errorCode);
  11385. }
  11386. }
  11387. exports.VoiceProfileCancellationDetails = VoiceProfileCancellationDetails;
  11388. /***/ }),
  11389. /* 147 */
  11390. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11391. "use strict";
  11392. // Copyright (c) Microsoft Corporation. All rights reserved.
  11393. // Licensed under the MIT license.
  11394. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11395. exports.VoiceProfilePhraseResult = void 0;
  11396. const Contracts_js_1 = __webpack_require__(64);
  11397. const Exports_js_1 = __webpack_require__(79);
  11398. /**
  11399. * Output format
  11400. * @class VoiceProfilePhraseResult
  11401. */
  11402. class VoiceProfilePhraseResult extends Exports_js_1.VoiceProfileResult {
  11403. constructor(reason, statusText, type, phraseArray) {
  11404. super(reason, statusText);
  11405. this.privPhrases = [];
  11406. Contracts_js_1.Contracts.throwIfNullOrUndefined(phraseArray, "phrase array");
  11407. this.privType = type;
  11408. if (!!phraseArray && !!phraseArray[0]) {
  11409. this.privPhrases = phraseArray;
  11410. }
  11411. }
  11412. get phrases() {
  11413. return this.privPhrases;
  11414. }
  11415. get type() {
  11416. return this.privType;
  11417. }
  11418. }
  11419. exports.VoiceProfilePhraseResult = VoiceProfilePhraseResult;
  11420. /***/ }),
  11421. /* 148 */
  11422. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11423. "use strict";
  11424. // Copyright (c) Microsoft Corporation. All rights reserved.
  11425. // Licensed under the MIT license.
  11426. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11427. exports.VoiceProfileClient = void 0;
  11428. const Exports_js_1 = __webpack_require__(2);
  11429. const AudioConfig_js_1 = __webpack_require__(80);
  11430. const Contracts_js_1 = __webpack_require__(64);
  11431. const Exports_js_2 = __webpack_require__(79);
  11432. /**
  11433. * Defines VoiceProfileClient class for Speaker Recognition
  11434. * Handles operations from user for Voice Profile operations (e.g. createProfile, deleteProfile)
  11435. * @class VoiceProfileClient
  11436. */
  11437. class VoiceProfileClient extends Exports_js_2.Recognizer {
  11438. /**
  11439. * VoiceProfileClient constructor.
  11440. * @constructor
  11441. * @param {SpeechConfig} speechConfig - An set of initial properties for this synthesizer (authentication key, region, &c)
  11442. */
  11443. constructor(speechConfig) {
  11444. Contracts_js_1.Contracts.throwIfNullOrUndefined(speechConfig, "speechConfig");
  11445. const speechConfigImpl = speechConfig;
  11446. Contracts_js_1.Contracts.throwIfNull(speechConfigImpl, "speechConfig");
  11447. super(AudioConfig_js_1.AudioConfig.fromStreamInput(Exports_js_2.AudioInputStream.createPushStream()), speechConfigImpl.properties, new Exports_js_1.VoiceProfileConnectionFactory());
  11448. this.privProperties = speechConfigImpl.properties.clone();
  11449. this.privVoiceAdapter = this.privReco;
  11450. this.privDisposedVoiceAdapter = false;
  11451. }
  11452. /**
  11453. * The collection of properties and their values defined for this VoiceProfileClient.
  11454. * @member VoiceProfileClient.prototype.properties
  11455. * @function
  11456. * @public
  11457. * @returns {PropertyCollection} The collection of properties and their values defined for this VoiceProfileClient.
  11458. */
  11459. get properties() {
  11460. return this.privProperties;
  11461. }
  11462. /**
  11463. * Gets the authorization token used to communicate with the service.
  11464. * @member VoiceProfileClient.prototype.authorizationToken
  11465. * @function
  11466. * @public
  11467. * @returns {string} Authorization token.
  11468. */
  11469. get authorizationToken() {
  11470. return this.properties.getProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token);
  11471. }
  11472. /**
  11473. * Gets/Sets the authorization token used to communicate with the service.
  11474. * @member VoiceProfileClient.prototype.authorizationToken
  11475. * @function
  11476. * @public
  11477. * @param {string} token - Authorization token.
  11478. */
  11479. set authorizationToken(token) {
  11480. Contracts_js_1.Contracts.throwIfNullOrWhitespace(token, "token");
  11481. this.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token, token);
  11482. }
  11483. /**
  11484. * Create a speaker recognition voice profile
  11485. * @member VoiceProfileClient.prototype.createProfileAsync
  11486. * @function
  11487. * @public
  11488. * @async
  11489. * @param {VoiceProfileType} profileType Type of Voice Profile to be created
  11490. * @param {string} lang Language string (locale) for Voice Profile
  11491. * @return {Promise<VoiceProfile>} - Promise of a VoiceProfile.
  11492. */
  11493. async createProfileAsync(profileType, lang) {
  11494. const profileIds = await this.privVoiceAdapter.createProfile(profileType, lang);
  11495. return new Exports_js_2.VoiceProfile(profileIds[0], profileType);
  11496. }
  11497. /**
  11498. * Get current information of a voice profile
  11499. * @member VoiceProfileClient.prototype.retrieveEnrollmentResultAsync
  11500. * @function
  11501. * @public
  11502. * @async
  11503. * @param {VoiceProfile} profile Voice Profile to retrieve info for
  11504. * @return {Promise<VoiceProfileEnrollmentResult>} - Promise of a VoiceProfileEnrollmentResult.
  11505. */
  11506. async retrieveEnrollmentResultAsync(profile) {
  11507. return this.privVoiceAdapter.retrieveEnrollmentResult(profile);
  11508. }
  11509. /**
  11510. * Get all voice profiles on account with given voice profile type
  11511. * @member VoiceProfileClient.prototype.getAllProfilesAsync
  11512. * @function
  11513. * @public
  11514. * @async
  11515. * @param {VoiceProfileType} profileType profile type (identification/verification) for which to list profiles
  11516. * @return {Promise<VoiceProfileEnrollmentResult[]>} - Promise of an array of VoiceProfileEnrollmentResults.
  11517. */
  11518. async getAllProfilesAsync(profileType) {
  11519. return this.privVoiceAdapter.getAllProfiles(profileType);
  11520. /*
  11521. const result: { json: { value: EnrollmentResultJSON[] } } = await this.privAdapter.getProfiles(profileType);
  11522. if (profileType === VoiceProfileType.TextIndependentIdentification) {
  11523. return VoiceProfileEnrollmentResult.FromIdentificationProfileList(result.json);
  11524. }
  11525. return VoiceProfileEnrollmentResult.FromVerificationProfileList(result.json);
  11526. */
  11527. }
  11528. /**
  11529. * Get valid authorization phrases for voice profile enrollment
  11530. * @member VoiceProfileClient.prototype.getActivationPhrasesAsync
  11531. * @function
  11532. * @public
  11533. * @async
  11534. * @param {VoiceProfileType} profileType Profile Type to get activation phrases for
  11535. * @param {string} lang Language string (locale) for Voice Profile
  11536. */
  11537. async getActivationPhrasesAsync(profileType, lang) {
  11538. return this.privVoiceAdapter.getActivationPhrases(profileType, lang);
  11539. }
  11540. /**
  11541. * Create a speaker recognition voice profile
  11542. * @member VoiceProfileClient.prototype.enrollProfileAsync
  11543. * @function
  11544. * @public
  11545. * @async
  11546. * @param {VoiceProfile} profile Voice Profile to create enrollment for
  11547. * @param {AudioConfig} audioConfig source info from which to create enrollment
  11548. * @return {Promise<VoiceProfileEnrollmentResult>} - Promise of a VoiceProfileEnrollmentResult.
  11549. */
  11550. async enrollProfileAsync(profile, audioConfig) {
  11551. const configImpl = audioConfig;
  11552. Contracts_js_1.Contracts.throwIfNullOrUndefined(configImpl, "audioConfig");
  11553. this.audioConfig = audioConfig;
  11554. this.privVoiceAdapter.SpeakerAudioSource = configImpl;
  11555. return this.privVoiceAdapter.enrollProfile(profile);
  11556. }
  11557. /**
  11558. * Delete a speaker recognition voice profile
  11559. * @member VoiceProfileClient.prototype.deleteProfileAsync
  11560. * @function
  11561. * @public
  11562. * @async
  11563. * @param {VoiceProfile} profile Voice Profile to be deleted
  11564. * @return {Promise<VoiceProfileResult>} - Promise of a VoiceProfileResult.
  11565. */
  11566. async deleteProfileAsync(profile) {
  11567. return this.privVoiceAdapter.deleteProfile(profile);
  11568. }
  11569. /**
  11570. * Remove all enrollments for a speaker recognition voice profile
  11571. * @member VoiceProfileClient.prototype.resetProfileAsync
  11572. * @function
  11573. * @public
  11574. * @async
  11575. * @param {VoiceProfile} profile Voice Profile to be reset
  11576. * @return {Promise<VoiceProfileResult>} - Promise of a VoiceProfileResult.
  11577. */
  11578. async resetProfileAsync(profile) {
  11579. return this.privVoiceAdapter.resetProfile(profile);
  11580. }
  11581. /**
  11582. * Clean up object and close underlying connection
  11583. * @member VoiceProfileClient.prototype.close
  11584. * @function
  11585. * @async
  11586. * @public
  11587. */
  11588. async close() {
  11589. await this.dispose(true);
  11590. }
  11591. createServiceRecognizer(authentication, connectionFactory, audioConfig, recognizerConfig) {
  11592. const audioImpl = audioConfig;
  11593. return new Exports_js_1.VoiceServiceRecognizer(authentication, connectionFactory, audioImpl, recognizerConfig, this);
  11594. }
  11595. async dispose(disposing) {
  11596. if (this.privDisposedVoiceAdapter) {
  11597. return;
  11598. }
  11599. this.privDisposedVoiceAdapter = true;
  11600. if (disposing) {
  11601. await super.dispose(disposing);
  11602. }
  11603. }
  11604. createRecognizerConfig(speechConfig) {
  11605. return new Exports_js_1.RecognizerConfig(speechConfig, this.properties);
  11606. }
  11607. getResult(result, successReason) {
  11608. const response = new Exports_js_2.VoiceProfileResult(result.ok ? successReason : Exports_js_2.ResultReason.Canceled, result.statusText);
  11609. return (response);
  11610. }
  11611. }
  11612. exports.VoiceProfileClient = VoiceProfileClient;
  11613. /***/ }),
  11614. /* 149 */
  11615. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11616. "use strict";
  11617. // Copyright (c) Microsoft Corporation. All rights reserved.
  11618. // Licensed under the MIT license.
  11619. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11620. exports.SpeakerRecognizer = void 0;
  11621. const Exports_js_1 = __webpack_require__(2);
  11622. const Contracts_js_1 = __webpack_require__(64);
  11623. const Exports_js_2 = __webpack_require__(79);
  11624. /**
  11625. * Defines SpeakerRecognizer class for Speaker Recognition
  11626. * Handles operations from user for Voice Profile operations (e.g. createProfile, deleteProfile)
  11627. * @class SpeakerRecognizer
  11628. */
  11629. class SpeakerRecognizer extends Exports_js_2.Recognizer {
  11630. /**
  11631. * Initializes an instance of the SpeakerRecognizer.
  11632. * @constructor
  11633. * @param {SpeechConfig} speechConfig - The set of configuration properties.
  11634. * @param {AudioConfig} audioConfig - An optional audio input config associated with the recognizer
  11635. */
  11636. constructor(speechConfig, audioConfig) {
  11637. Contracts_js_1.Contracts.throwIfNullOrUndefined(speechConfig, "speechConfig");
  11638. const configImpl = speechConfig;
  11639. Contracts_js_1.Contracts.throwIfNullOrUndefined(configImpl, "speechConfig");
  11640. super(audioConfig, configImpl.properties, new Exports_js_1.SpeakerRecognitionConnectionFactory());
  11641. this.privAudioConfigImpl = audioConfig;
  11642. Contracts_js_1.Contracts.throwIfNull(this.privAudioConfigImpl, "audioConfig");
  11643. this.privDisposedSpeakerRecognizer = false;
  11644. this.privProperties = configImpl.properties;
  11645. }
  11646. /**
  11647. * Gets the authorization token used to communicate with the service.
  11648. * @member SpeakerRecognizer.prototype.authorizationToken
  11649. * @function
  11650. * @public
  11651. * @returns {string} Authorization token.
  11652. */
  11653. get authorizationToken() {
  11654. return this.properties.getProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token);
  11655. }
  11656. /**
  11657. * Gets/Sets the authorization token used to communicate with the service.
  11658. * @member SpeakerRecognizer.prototype.authorizationToken
  11659. * @function
  11660. * @public
  11661. * @param {string} token - Authorization token.
  11662. */
  11663. set authorizationToken(token) {
  11664. Contracts_js_1.Contracts.throwIfNullOrWhitespace(token, "token");
  11665. this.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token, token);
  11666. }
  11667. /**
  11668. * The collection of properties and their values defined for this SpeakerRecognizer.
  11669. * @member SpeakerRecognizer.prototype.properties
  11670. * @function
  11671. * @public
  11672. * @returns {PropertyCollection} The collection of properties and their values defined for this SpeakerRecognizer.
  11673. */
  11674. get properties() {
  11675. return this.privProperties;
  11676. }
  11677. /**
  11678. * Get recognition result for model using given audio
  11679. * @member SpeakerRecognizer.prototype.recognizeOnceAsync
  11680. * @function
  11681. * @public
  11682. * @async
  11683. * @param {SpeakerIdentificationModel | SpeakerVerificationModel} model Model containing Voice Profiles to be identified
  11684. * @param cb - Callback invoked once result is returned.
  11685. * @param err - Callback invoked in case of an error.
  11686. */
  11687. async recognizeOnceAsync(model) {
  11688. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedSpeakerRecognizer);
  11689. return this.recognizeSpeakerOnceAsyncImpl(model);
  11690. }
  11691. /**
  11692. * Included for compatibility
  11693. * @member SpeakerRecognizer.prototype.close
  11694. * @function
  11695. * @public
  11696. * @async
  11697. */
  11698. async close() {
  11699. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedSpeakerRecognizer);
  11700. await this.dispose(true);
  11701. }
  11702. async recognizeSpeakerOnceAsyncImpl(model) {
  11703. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedSpeakerRecognizer);
  11704. await this.implRecognizerStop();
  11705. const result = await this.privReco.recognizeSpeaker(model);
  11706. await this.implRecognizerStop();
  11707. return result;
  11708. }
  11709. async implRecognizerStop() {
  11710. if (this.privReco) {
  11711. await this.privReco.stopRecognizing();
  11712. }
  11713. return;
  11714. }
  11715. createRecognizerConfig(speechConfig) {
  11716. return new Exports_js_1.RecognizerConfig(speechConfig, this.privProperties);
  11717. }
  11718. createServiceRecognizer(authentication, connectionFactory, audioConfig, recognizerConfig) {
  11719. const audioImpl = audioConfig;
  11720. return new Exports_js_1.SpeakerServiceRecognizer(authentication, connectionFactory, audioImpl, recognizerConfig, this);
  11721. }
  11722. async dispose(disposing) {
  11723. if (this.privDisposedSpeakerRecognizer) {
  11724. return;
  11725. }
  11726. if (disposing) {
  11727. this.privDisposedSpeakerRecognizer = true;
  11728. await super.dispose(disposing);
  11729. }
  11730. }
  11731. }
  11732. exports.SpeakerRecognizer = SpeakerRecognizer;
  11733. /***/ }),
  11734. /* 150 */
  11735. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11736. "use strict";
  11737. // Copyright (c) Microsoft Corporation. All rights reserved.
  11738. // Licensed under the MIT license.
  11739. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11740. exports.SpeakerIdentificationModel = void 0;
  11741. const Contracts_js_1 = __webpack_require__(64);
  11742. const Exports_js_1 = __webpack_require__(79);
  11743. /**
  11744. * Defines SpeakerIdentificationModel class for Speaker Recognition
  11745. * Model contains a set of profiles against which to identify speaker(s)
  11746. * @class SpeakerIdentificationModel
  11747. */
  11748. class SpeakerIdentificationModel {
  11749. constructor(profiles) {
  11750. this.privVoiceProfiles = [];
  11751. this.privProfileIds = [];
  11752. Contracts_js_1.Contracts.throwIfNullOrUndefined(profiles, "VoiceProfiles");
  11753. if (profiles.length === 0) {
  11754. throw new Error("Empty Voice Profiles array");
  11755. }
  11756. for (const profile of profiles) {
  11757. if (profile.profileType !== Exports_js_1.VoiceProfileType.TextIndependentIdentification) {
  11758. throw new Error("Identification model can only be created from Identification profile: " + profile.profileId);
  11759. }
  11760. this.privVoiceProfiles.push(profile);
  11761. this.privProfileIds.push(profile.profileId);
  11762. }
  11763. }
  11764. static fromProfiles(profiles) {
  11765. return new SpeakerIdentificationModel(profiles);
  11766. }
  11767. get voiceProfileIds() {
  11768. return this.privProfileIds.join(",");
  11769. }
  11770. get profileIds() {
  11771. return this.privProfileIds;
  11772. }
  11773. get scenario() {
  11774. return "TextIndependentIdentification";
  11775. }
  11776. }
  11777. exports.SpeakerIdentificationModel = SpeakerIdentificationModel;
  11778. /***/ }),
  11779. /* 151 */
  11780. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11781. "use strict";
  11782. // Copyright (c) Microsoft Corporation. All rights reserved.
  11783. // Licensed under the MIT license.
  11784. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11785. exports.SpeakerVerificationModel = void 0;
  11786. const Contracts_js_1 = __webpack_require__(64);
  11787. const Exports_js_1 = __webpack_require__(79);
  11788. /**
  11789. * Defines SpeakerVerificationModel class for Speaker Recognition
  11790. * Model contains a profile against which to verify a speaker
  11791. * @class SpeakerVerificationModel
  11792. */
  11793. class SpeakerVerificationModel {
  11794. constructor(profile) {
  11795. Contracts_js_1.Contracts.throwIfNullOrUndefined(profile, "VoiceProfile");
  11796. if (profile.profileType === Exports_js_1.VoiceProfileType.TextIndependentIdentification) {
  11797. throw new Error("Verification model cannot be created from Identification profile");
  11798. }
  11799. this.privVoiceProfile = profile;
  11800. }
  11801. static fromProfile(profile) {
  11802. return new SpeakerVerificationModel(profile);
  11803. }
  11804. get voiceProfile() {
  11805. return this.privVoiceProfile;
  11806. }
  11807. get profileIds() {
  11808. return [this.voiceProfile.profileId];
  11809. }
  11810. get scenario() {
  11811. if (this.voiceProfile.profileType === Exports_js_1.VoiceProfileType.TextDependentVerification) {
  11812. return "TextDependentVerification";
  11813. }
  11814. else {
  11815. return "TextIndependentVerification";
  11816. }
  11817. }
  11818. }
  11819. exports.SpeakerVerificationModel = SpeakerVerificationModel;
  11820. /***/ }),
  11821. /* 152 */
  11822. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11823. "use strict";
  11824. // Copyright (c) Microsoft Corporation. All rights reserved.
  11825. // Licensed under the MIT license.
  11826. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11827. exports.AutoDetectSourceLanguageConfig = void 0;
  11828. const Exports_js_1 = __webpack_require__(2);
  11829. const Contracts_js_1 = __webpack_require__(64);
  11830. const Exports_js_2 = __webpack_require__(79);
  11831. const LanguageIdMode_js_1 = __webpack_require__(153);
  11832. /**
  11833. * Language auto detect configuration.
  11834. * @class AutoDetectSourceLanguageConfig
  11835. * Added in version 1.13.0.
  11836. */
  11837. class AutoDetectSourceLanguageConfig {
  11838. constructor() {
  11839. this.privProperties = new Exports_js_2.PropertyCollection();
  11840. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_LanguageIdMode, "AtStart");
  11841. this.privLanguageIdMode = LanguageIdMode_js_1.LanguageIdMode.AtStart;
  11842. }
  11843. /**
  11844. * @member AutoDetectSourceLanguageConfig.fromOpenRange
  11845. * @function
  11846. * @public
  11847. * Only [[SpeechSynthesizer]] supports source language auto detection from open range,
  11848. * for [[Recognizer]], please use AutoDetectSourceLanguageConfig with specific source languages.
  11849. * @return {AutoDetectSourceLanguageConfig} Instance of AutoDetectSourceLanguageConfig
  11850. * @summary Creates an instance of the AutoDetectSourceLanguageConfig with open range.
  11851. */
  11852. static fromOpenRange() {
  11853. const config = new AutoDetectSourceLanguageConfig();
  11854. config.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages, Exports_js_1.AutoDetectSourceLanguagesOpenRangeOptionName);
  11855. config.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage, "en-US");
  11856. return config;
  11857. }
  11858. /**
  11859. * @member AutoDetectSourceLanguageConfig.fromLanguages
  11860. * @function
  11861. * @public
  11862. * @param {string[]} languages Comma-separated string of languages (eg. "en-US,fr-FR") to populate properties of config.
  11863. * @return {AutoDetectSourceLanguageConfig} Instance of AutoDetectSourceLanguageConfig
  11864. * @summary Creates an instance of the AutoDetectSourceLanguageConfig with given languages.
  11865. */
  11866. static fromLanguages(languages) {
  11867. Contracts_js_1.Contracts.throwIfArrayEmptyOrWhitespace(languages, "languages");
  11868. const config = new AutoDetectSourceLanguageConfig();
  11869. config.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages, languages.join());
  11870. return config;
  11871. }
  11872. /**
  11873. * @member AutoDetectSourceLanguageConfig.fromSourceLanguageConfigs
  11874. * @function
  11875. * @public
  11876. * @param {SourceLanguageConfig[]} configs SourceLanguageConfigs to populate properties of config.
  11877. * @return {AutoDetectSourceLanguageConfig} Instance of AutoDetectSourceLanguageConfig
  11878. * @summary Creates an instance of the AutoDetectSourceLanguageConfig with given SourceLanguageConfigs.
  11879. */
  11880. static fromSourceLanguageConfigs(configs) {
  11881. if (configs.length < 1) {
  11882. throw new Error("Expected non-empty SourceLanguageConfig array.");
  11883. }
  11884. const autoConfig = new AutoDetectSourceLanguageConfig();
  11885. const langs = [];
  11886. configs.forEach((config) => {
  11887. langs.push(config.language);
  11888. if (config.endpointId !== undefined && config.endpointId !== "") {
  11889. const customProperty = config.language + Exports_js_2.PropertyId.SpeechServiceConnection_EndpointId.toString();
  11890. autoConfig.properties.setProperty(customProperty, config.endpointId);
  11891. }
  11892. });
  11893. autoConfig.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages, langs.join());
  11894. return autoConfig;
  11895. }
  11896. /**
  11897. * @member AutoDetectSourceLanguageConfig.prototype.properties
  11898. * @function
  11899. * @public
  11900. * @return {PropertyCollection} Properties of the config.
  11901. * @summary Gets an auto detected language config properties
  11902. */
  11903. get properties() {
  11904. return this.privProperties;
  11905. }
  11906. /**
  11907. * @member AutoDetectSourceLanguageConfig.prototype.mode
  11908. * @function
  11909. * @public
  11910. * @param {LanguageIdMode} mode LID mode desired.
  11911. * @summary Sets LID operation to desired mode
  11912. */
  11913. set mode(mode) {
  11914. if (mode === LanguageIdMode_js_1.LanguageIdMode.Continuous) {
  11915. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecognitionEndpointVersion, "2");
  11916. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_LanguageIdMode, "Continuous");
  11917. }
  11918. else { // LanguageIdMode.AtStart
  11919. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecognitionEndpointVersion, "1");
  11920. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_LanguageIdMode, "AtStart");
  11921. }
  11922. this.privLanguageIdMode = mode;
  11923. }
  11924. }
  11925. exports.AutoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig;
  11926. /***/ }),
  11927. /* 153 */
  11928. /***/ ((__unused_webpack_module, exports) => {
  11929. "use strict";
  11930. // Copyright (c) Microsoft Corporation. All rights reserved.
  11931. // Licensed under the MIT license.
  11932. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11933. exports.LanguageIdMode = void 0;
  11934. /**
  11935. * Language Identification mode
  11936. * @class LanguageIdMode
  11937. */
  11938. var LanguageIdMode;
  11939. (function (LanguageIdMode) {
  11940. /**
  11941. * Detect language at audio start
  11942. * @member LanguageIdMode.AtStart
  11943. */
  11944. LanguageIdMode[LanguageIdMode["AtStart"] = 0] = "AtStart";
  11945. /**
  11946. * Continuously detect language
  11947. * @member LanguageIdMode.Continuous
  11948. */
  11949. LanguageIdMode[LanguageIdMode["Continuous"] = 1] = "Continuous";
  11950. })(LanguageIdMode = exports.LanguageIdMode || (exports.LanguageIdMode = {}));
  11951. /***/ }),
  11952. /* 154 */
  11953. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11954. "use strict";
  11955. // Copyright (c) Microsoft Corporation. All rights reserved.
  11956. // Licensed under the MIT license.
  11957. Object.defineProperty(exports, "__esModule", ({ value: true }));
  11958. exports.AutoDetectSourceLanguageResult = void 0;
  11959. const Contracts_js_1 = __webpack_require__(64);
  11960. /**
  11961. * Output format
  11962. * @class AutoDetectSourceLanguageResult
  11963. */
  11964. class AutoDetectSourceLanguageResult {
  11965. constructor(language, languageDetectionConfidence) {
  11966. Contracts_js_1.Contracts.throwIfNullOrUndefined(language, "language");
  11967. Contracts_js_1.Contracts.throwIfNullOrUndefined(languageDetectionConfidence, "languageDetectionConfidence");
  11968. this.privLanguage = language;
  11969. this.privLanguageDetectionConfidence = languageDetectionConfidence;
  11970. }
  11971. /**
  11972. * Creates an instance of AutoDetectSourceLanguageResult object from a SpeechRecognitionResult instance.
  11973. * @member AutoDetectSourceLanguageResult.fromResult
  11974. * @function
  11975. * @public
  11976. * @param {SpeechRecognitionResult} result - The recognition result.
  11977. * @returns {AutoDetectSourceLanguageResult} AutoDetectSourceLanguageResult object being created.
  11978. */
  11979. static fromResult(result) {
  11980. return new AutoDetectSourceLanguageResult(result.language, result.languageDetectionConfidence);
  11981. }
  11982. /**
  11983. * Creates an instance of AutoDetectSourceLanguageResult object from a ConversationTranscriptionResult instance.
  11984. * @member AutoDetectSourceLanguageResult.fromConversationTranscriptionResult
  11985. * @function
  11986. * @public
  11987. * @param {ConversationTranscriptionResult} result - The transcription result.
  11988. * @returns {AutoDetectSourceLanguageResult} AutoDetectSourceLanguageResult object being created.
  11989. */
  11990. static fromConversationTranscriptionResult(result) {
  11991. return new AutoDetectSourceLanguageResult(result.language, result.languageDetectionConfidence);
  11992. }
  11993. get language() {
  11994. return this.privLanguage;
  11995. }
  11996. get languageDetectionConfidence() {
  11997. return this.privLanguageDetectionConfidence;
  11998. }
  11999. }
  12000. exports.AutoDetectSourceLanguageResult = AutoDetectSourceLanguageResult;
  12001. /***/ }),
  12002. /* 155 */
  12003. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12004. "use strict";
  12005. // Copyright (c) Microsoft Corporation. All rights reserved.
  12006. // Licensed under the MIT license.
  12007. Object.defineProperty(exports, "__esModule", ({ value: true }));
  12008. exports.SourceLanguageConfig = void 0;
  12009. const Contracts_js_1 = __webpack_require__(64);
  12010. /**
  12011. * Source Language configuration.
  12012. * @class SourceLanguageConfig
  12013. */
  12014. class SourceLanguageConfig {
  12015. constructor(language, endpointId) {
  12016. Contracts_js_1.Contracts.throwIfNullOrUndefined(language, "language");
  12017. this.privLanguage = language;
  12018. this.privEndpointId = endpointId;
  12019. }
  12020. /**
  12021. * @member SourceLanguageConfig.fromLanguage
  12022. * @function
  12023. * @public
  12024. * @param {string} language language (eg. "en-US") value of config.
  12025. * @param {string?} endpointId endpointId of model bound to given language of config.
  12026. * @return {SourceLanguageConfig} Instance of SourceLanguageConfig
  12027. * @summary Creates an instance of the SourceLanguageConfig with the given language and optional endpointId.
  12028. * Added in version 1.13.0.
  12029. */
  12030. static fromLanguage(language, endpointId) {
  12031. return new SourceLanguageConfig(language, endpointId);
  12032. }
  12033. get language() {
  12034. return this.privLanguage;
  12035. }
  12036. get endpointId() {
  12037. return this.privEndpointId;
  12038. }
  12039. }
  12040. exports.SourceLanguageConfig = SourceLanguageConfig;
  12041. /***/ }),
  12042. /* 156 */
  12043. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12044. "use strict";
  12045. // Copyright (c) Microsoft Corporation. All rights reserved.
  12046. // Licensed under the MIT license.
  12047. Object.defineProperty(exports, "__esModule", ({ value: true }));
  12048. exports.SpeakerRecognitionCancellationDetails = exports.SpeakerRecognitionResult = exports.SpeakerRecognitionResultType = void 0;
  12049. /* eslint-disable max-classes-per-file */
  12050. const Exports_js_1 = __webpack_require__(2);
  12051. const Exports_js_2 = __webpack_require__(79);
  12052. var SpeakerRecognitionResultType;
  12053. (function (SpeakerRecognitionResultType) {
  12054. SpeakerRecognitionResultType[SpeakerRecognitionResultType["Verify"] = 0] = "Verify";
  12055. SpeakerRecognitionResultType[SpeakerRecognitionResultType["Identify"] = 1] = "Identify";
  12056. })(SpeakerRecognitionResultType = exports.SpeakerRecognitionResultType || (exports.SpeakerRecognitionResultType = {}));
  12057. /**
  12058. * Output format
  12059. * @class SpeakerRecognitionResult
  12060. */
  12061. class SpeakerRecognitionResult {
  12062. constructor(response, resultReason = Exports_js_2.ResultReason.RecognizedSpeaker, cancellationErrorCode = Exports_js_2.CancellationErrorCode.NoError, errorDetails = "") {
  12063. this.privProperties = new Exports_js_2.PropertyCollection();
  12064. const resultType = response.scenario === "TextIndependentIdentification" ? SpeakerRecognitionResultType.Identify : SpeakerRecognitionResultType.Verify;
  12065. this.privReason = resultReason;
  12066. if (this.privReason !== Exports_js_2.ResultReason.Canceled) {
  12067. if (resultType === SpeakerRecognitionResultType.Identify) {
  12068. this.privProfileId = response.identificationResult.identifiedProfile.profileId;
  12069. this.privScore = response.identificationResult.identifiedProfile.score;
  12070. this.privReason = Exports_js_2.ResultReason.RecognizedSpeakers;
  12071. }
  12072. else {
  12073. this.privScore = response.verificationResult.score;
  12074. if (response.verificationResult.recognitionResult.toLowerCase() !== "accept") {
  12075. this.privReason = Exports_js_2.ResultReason.NoMatch;
  12076. }
  12077. if (response.verificationResult.profileId !== undefined && response.verificationResult.profileId !== "") {
  12078. this.privProfileId = response.verificationResult.profileId;
  12079. }
  12080. }
  12081. }
  12082. else {
  12083. this.privErrorDetails = errorDetails;
  12084. this.privProperties.setProperty(Exports_js_1.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[cancellationErrorCode]);
  12085. }
  12086. this.privProperties.setProperty(Exports_js_2.PropertyId.SpeechServiceResponse_JsonResult, JSON.stringify(response));
  12087. }
  12088. get properties() {
  12089. return this.privProperties;
  12090. }
  12091. get reason() {
  12092. return this.privReason;
  12093. }
  12094. get profileId() {
  12095. return this.privProfileId;
  12096. }
  12097. get errorDetails() {
  12098. return this.privErrorDetails;
  12099. }
  12100. get score() {
  12101. return this.privScore;
  12102. }
  12103. }
  12104. exports.SpeakerRecognitionResult = SpeakerRecognitionResult;
  12105. /**
  12106. * @class SpeakerRecognitionCancellationDetails
  12107. */
  12108. class SpeakerRecognitionCancellationDetails extends Exports_js_2.CancellationDetailsBase {
  12109. constructor(reason, errorDetails, errorCode) {
  12110. super(reason, errorDetails, errorCode);
  12111. }
  12112. /**
  12113. * Creates an instance of SpeakerRecognitionCancellationDetails object for the canceled SpeakerRecognitionResult
  12114. * @member SpeakerRecognitionCancellationDetails.fromResult
  12115. * @function
  12116. * @public
  12117. * @param {SpeakerRecognitionResult} result - The result that was canceled.
  12118. * @returns {SpeakerRecognitionCancellationDetails} The cancellation details object being created.
  12119. */
  12120. static fromResult(result) {
  12121. const reason = Exports_js_2.CancellationReason.Error;
  12122. let errorCode = Exports_js_2.CancellationErrorCode.NoError;
  12123. if (!!result.properties) {
  12124. errorCode = Exports_js_2.CancellationErrorCode[result.properties.getProperty(Exports_js_1.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[Exports_js_2.CancellationErrorCode.NoError])];
  12125. }
  12126. return new SpeakerRecognitionCancellationDetails(reason, result.errorDetails, errorCode);
  12127. }
  12128. }
  12129. exports.SpeakerRecognitionCancellationDetails = SpeakerRecognitionCancellationDetails;
  12130. /***/ }),
  12131. /* 157 */
  12132. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12133. "use strict";
  12134. // Copyright (c) Microsoft Corporation. All rights reserved.
  12135. // Licensed under the MIT license.
  12136. // Multi-device Conversation is a Preview feature.
  12137. Object.defineProperty(exports, "__esModule", ({ value: true }));
  12138. exports.ConversationTranscriptionResult = exports.MeetingTranscriber = exports.MeetingTranscriptionCanceledEventArgs = exports.MeetingImpl = exports.Meeting = exports.ParticipantChangedReason = exports.User = exports.Participant = exports.ConversationTranscriber = exports.ConversationTranslator = exports.ConversationTranslationResult = exports.ConversationTranslationEventArgs = exports.ConversationTranslationCanceledEventArgs = exports.ConversationParticipantsChangedEventArgs = exports.ConversationExpirationEventArgs = exports.ConversationCommon = exports.ConversationImpl = exports.Conversation = void 0;
  12139. var Conversation_js_1 = __webpack_require__(158);
  12140. Object.defineProperty(exports, "Conversation", ({ enumerable: true, get: function () { return Conversation_js_1.Conversation; } }));
  12141. Object.defineProperty(exports, "ConversationImpl", ({ enumerable: true, get: function () { return Conversation_js_1.ConversationImpl; } }));
  12142. var ConversationCommon_js_1 = __webpack_require__(159);
  12143. Object.defineProperty(exports, "ConversationCommon", ({ enumerable: true, get: function () { return ConversationCommon_js_1.ConversationCommon; } }));
  12144. var ConversationExpirationEventArgs_js_1 = __webpack_require__(160);
  12145. Object.defineProperty(exports, "ConversationExpirationEventArgs", ({ enumerable: true, get: function () { return ConversationExpirationEventArgs_js_1.ConversationExpirationEventArgs; } }));
  12146. var ConversationParticipantsChangedEventArgs_js_1 = __webpack_require__(161);
  12147. Object.defineProperty(exports, "ConversationParticipantsChangedEventArgs", ({ enumerable: true, get: function () { return ConversationParticipantsChangedEventArgs_js_1.ConversationParticipantsChangedEventArgs; } }));
  12148. var ConversationTranslationCanceledEventArgs_js_1 = __webpack_require__(162);
  12149. Object.defineProperty(exports, "ConversationTranslationCanceledEventArgs", ({ enumerable: true, get: function () { return ConversationTranslationCanceledEventArgs_js_1.ConversationTranslationCanceledEventArgs; } }));
  12150. var ConversationTranslationEventArgs_js_1 = __webpack_require__(163);
  12151. Object.defineProperty(exports, "ConversationTranslationEventArgs", ({ enumerable: true, get: function () { return ConversationTranslationEventArgs_js_1.ConversationTranslationEventArgs; } }));
  12152. var ConversationTranslationResult_js_1 = __webpack_require__(164);
  12153. Object.defineProperty(exports, "ConversationTranslationResult", ({ enumerable: true, get: function () { return ConversationTranslationResult_js_1.ConversationTranslationResult; } }));
  12154. var ConversationTranslator_js_1 = __webpack_require__(165);
  12155. Object.defineProperty(exports, "ConversationTranslator", ({ enumerable: true, get: function () { return ConversationTranslator_js_1.ConversationTranslator; } }));
  12156. var ConversationTranscriber_js_1 = __webpack_require__(168);
  12157. Object.defineProperty(exports, "ConversationTranscriber", ({ enumerable: true, get: function () { return ConversationTranscriber_js_1.ConversationTranscriber; } }));
  12158. var IParticipant_js_1 = __webpack_require__(169);
  12159. Object.defineProperty(exports, "Participant", ({ enumerable: true, get: function () { return IParticipant_js_1.Participant; } }));
  12160. Object.defineProperty(exports, "User", ({ enumerable: true, get: function () { return IParticipant_js_1.User; } }));
  12161. var ParticipantChangedReason_js_1 = __webpack_require__(170);
  12162. Object.defineProperty(exports, "ParticipantChangedReason", ({ enumerable: true, get: function () { return ParticipantChangedReason_js_1.ParticipantChangedReason; } }));
  12163. var Meeting_js_1 = __webpack_require__(171);
  12164. Object.defineProperty(exports, "Meeting", ({ enumerable: true, get: function () { return Meeting_js_1.Meeting; } }));
  12165. Object.defineProperty(exports, "MeetingImpl", ({ enumerable: true, get: function () { return Meeting_js_1.MeetingImpl; } }));
  12166. var MeetingTranscriptionCanceledEventArgs_js_1 = __webpack_require__(172);
  12167. Object.defineProperty(exports, "MeetingTranscriptionCanceledEventArgs", ({ enumerable: true, get: function () { return MeetingTranscriptionCanceledEventArgs_js_1.MeetingTranscriptionCanceledEventArgs; } }));
  12168. var MeetingTranscriber_js_1 = __webpack_require__(173);
  12169. Object.defineProperty(exports, "MeetingTranscriber", ({ enumerable: true, get: function () { return MeetingTranscriber_js_1.MeetingTranscriber; } }));
  12170. var ConversationTranscriptionResult_js_1 = __webpack_require__(174);
  12171. Object.defineProperty(exports, "ConversationTranscriptionResult", ({ enumerable: true, get: function () { return ConversationTranscriptionResult_js_1.ConversationTranscriptionResult; } }));
  12172. /***/ }),
  12173. /* 158 */
  12174. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12175. "use strict";
  12176. // Copyright (c) Microsoft Corporation. All rights reserved.
  12177. // Licensed under the MIT license.
  12178. // Multi-device Conversation is a Preview feature.
  12179. Object.defineProperty(exports, "__esModule", ({ value: true }));
  12180. exports.ConversationImpl = exports.Conversation = void 0;
  12181. /* eslint-disable max-classes-per-file */
  12182. const Exports_js_1 = __webpack_require__(2);
  12183. const Exports_js_2 = __webpack_require__(4);
  12184. const Contracts_js_1 = __webpack_require__(64);
  12185. const Exports_js_3 = __webpack_require__(79);
  12186. class Conversation {
  12187. constructor() {
  12188. return;
  12189. }
  12190. /**
  12191. * Create a conversation
  12192. * @param speechConfig
  12193. * @param cb
  12194. * @param err
  12195. */
  12196. static createConversationAsync(speechConfig, arg2, arg3, arg4) {
  12197. Contracts_js_1.Contracts.throwIfNullOrUndefined(speechConfig, Exports_js_1.ConversationConnectionConfig.restErrors.invalidArgs.replace("{arg}", "config"));
  12198. Contracts_js_1.Contracts.throwIfNullOrUndefined(speechConfig.region, Exports_js_1.ConversationConnectionConfig.restErrors.invalidArgs.replace("{arg}", "SpeechServiceConnection_Region"));
  12199. if (!speechConfig.subscriptionKey && !speechConfig.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceAuthorization_Token])) {
  12200. Contracts_js_1.Contracts.throwIfNullOrUndefined(speechConfig.subscriptionKey, Exports_js_1.ConversationConnectionConfig.restErrors.invalidArgs.replace("{arg}", "SpeechServiceConnection_Key"));
  12201. }
  12202. let conversationImpl;
  12203. let cb;
  12204. let err;
  12205. if (typeof arg2 === "string") {
  12206. conversationImpl = new ConversationImpl(speechConfig, arg2);
  12207. // eslint-disable-next-line @typescript-eslint/no-empty-function
  12208. (0, Exports_js_2.marshalPromiseToCallbacks)((async () => { })(), arg3, arg4);
  12209. }
  12210. else {
  12211. conversationImpl = new ConversationImpl(speechConfig);
  12212. cb = arg2;
  12213. err = arg3;
  12214. conversationImpl.createConversationAsync((() => {
  12215. if (!!cb) {
  12216. cb();
  12217. }
  12218. }), (error) => {
  12219. if (!!err) {
  12220. err(error);
  12221. }
  12222. });
  12223. }
  12224. return conversationImpl;
  12225. }
  12226. }
  12227. exports.Conversation = Conversation;
  12228. class ConversationImpl extends Conversation {
  12229. /**
  12230. * Create a conversation impl
  12231. * @param speechConfig
  12232. * @param {string} id - optional conversationId
  12233. */
  12234. constructor(speechConfig, id) {
  12235. super();
  12236. this.privErrors = Exports_js_1.ConversationConnectionConfig.restErrors;
  12237. /** websocket callbacks */
  12238. /* eslint-disable @typescript-eslint/typedef */
  12239. this.onConnected = (e) => {
  12240. this.privIsConnected = true;
  12241. try {
  12242. if (!!this.privConversationTranslator?.sessionStarted) {
  12243. this.privConversationTranslator.sessionStarted(this.privConversationTranslator, e);
  12244. }
  12245. }
  12246. catch (e) {
  12247. //
  12248. }
  12249. };
  12250. this.onDisconnected = (e) => {
  12251. try {
  12252. if (!!this.privConversationTranslator?.sessionStopped) {
  12253. this.privConversationTranslator.sessionStopped(this.privConversationTranslator, e);
  12254. }
  12255. }
  12256. catch (e) {
  12257. //
  12258. }
  12259. finally {
  12260. void this.close(false);
  12261. }
  12262. };
  12263. this.onCanceled = (r, e) => {
  12264. try {
  12265. if (!!this.privConversationTranslator?.canceled) {
  12266. this.privConversationTranslator.canceled(this.privConversationTranslator, e);
  12267. }
  12268. }
  12269. catch (e) {
  12270. //
  12271. }
  12272. };
  12273. this.onParticipantUpdateCommandReceived = (r, e) => {
  12274. try {
  12275. const updatedParticipant = this.privParticipants.getParticipant(e.id);
  12276. if (updatedParticipant !== undefined) {
  12277. switch (e.key) {
  12278. case Exports_js_1.ConversationTranslatorCommandTypes.changeNickname:
  12279. updatedParticipant.displayName = e.value;
  12280. break;
  12281. case Exports_js_1.ConversationTranslatorCommandTypes.setUseTTS:
  12282. updatedParticipant.isUsingTts = e.value;
  12283. break;
  12284. case Exports_js_1.ConversationTranslatorCommandTypes.setProfanityFiltering:
  12285. updatedParticipant.profanity = e.value;
  12286. break;
  12287. case Exports_js_1.ConversationTranslatorCommandTypes.setMute:
  12288. updatedParticipant.isMuted = e.value;
  12289. break;
  12290. case Exports_js_1.ConversationTranslatorCommandTypes.setTranslateToLanguages:
  12291. updatedParticipant.translateToLanguages = e.value;
  12292. break;
  12293. }
  12294. this.privParticipants.addOrUpdateParticipant(updatedParticipant);
  12295. if (!!this.privConversationTranslator) {
  12296. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.Updated, [this.toParticipant(updatedParticipant)], e.sessionId));
  12297. }
  12298. }
  12299. }
  12300. catch (e) {
  12301. //
  12302. }
  12303. };
  12304. this.onLockRoomCommandReceived = () => {
  12305. // TODO
  12306. };
  12307. this.onMuteAllCommandReceived = (r, e) => {
  12308. try {
  12309. this.privParticipants.participants.forEach((p) => p.isMuted = (p.isHost ? false : e.isMuted));
  12310. if (!!this.privConversationTranslator) {
  12311. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.Updated, this.toParticipants(false), e.sessionId));
  12312. }
  12313. }
  12314. catch (e) {
  12315. //
  12316. }
  12317. };
  12318. this.onParticipantJoinCommandReceived = (r, e) => {
  12319. try {
  12320. const newParticipant = this.privParticipants.addOrUpdateParticipant(e.participant);
  12321. if (newParticipant !== undefined) {
  12322. if (!!this.privConversationTranslator) {
  12323. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.JoinedConversation, [this.toParticipant(newParticipant)], e.sessionId));
  12324. }
  12325. }
  12326. }
  12327. catch (e) {
  12328. //
  12329. }
  12330. };
  12331. this.onParticipantLeaveCommandReceived = (r, e) => {
  12332. try {
  12333. const ejectedParticipant = this.privParticipants.getParticipant(e.participant.id);
  12334. if (ejectedParticipant !== undefined) {
  12335. // remove the participant from the internal participants list
  12336. this.privParticipants.deleteParticipant(e.participant.id);
  12337. if (!!this.privConversationTranslator) {
  12338. // notify subscribers that the participant has left the conversation
  12339. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.LeftConversation, [this.toParticipant(ejectedParticipant)], e.sessionId));
  12340. }
  12341. }
  12342. }
  12343. catch (e) {
  12344. //
  12345. }
  12346. };
  12347. this.onTranslationReceived = (r, e) => {
  12348. try {
  12349. switch (e.command) {
  12350. case Exports_js_1.ConversationTranslatorMessageTypes.final:
  12351. if (!!this.privConversationTranslator) {
  12352. this.privConversationTranslator.transcribed(this.privConversationTranslator, new Exports_js_3.ConversationTranslationEventArgs(e.payload, undefined, e.sessionId));
  12353. }
  12354. break;
  12355. case Exports_js_1.ConversationTranslatorMessageTypes.partial:
  12356. if (!!this.privConversationTranslator) {
  12357. this.privConversationTranslator.transcribing(this.privConversationTranslator, new Exports_js_3.ConversationTranslationEventArgs(e.payload, undefined, e.sessionId));
  12358. }
  12359. break;
  12360. case Exports_js_1.ConversationTranslatorMessageTypes.instantMessage:
  12361. if (!!this.privConversationTranslator) {
  12362. this.privConversationTranslator.textMessageReceived(this.privConversationTranslator, new Exports_js_3.ConversationTranslationEventArgs(e.payload, undefined, e.sessionId));
  12363. }
  12364. break;
  12365. }
  12366. }
  12367. catch (e) {
  12368. //
  12369. }
  12370. };
  12371. this.onParticipantsListReceived = (r, e) => {
  12372. try {
  12373. // check if the session token needs to be updated
  12374. if (e.sessionToken !== undefined && e.sessionToken !== null) {
  12375. this.privRoom.token = e.sessionToken;
  12376. }
  12377. // save the participants
  12378. this.privParticipants.participants = [...e.participants];
  12379. // enable the conversation
  12380. if (this.privParticipants.me !== undefined) {
  12381. this.privIsReady = true;
  12382. }
  12383. if (!!this.privConversationTranslator) {
  12384. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.JoinedConversation, this.toParticipants(true), e.sessionId));
  12385. }
  12386. // if this is the host, update the nickname if needed
  12387. if (this.me.isHost) {
  12388. const nickname = this.privConversationTranslator?.properties.getProperty(Exports_js_3.PropertyId.ConversationTranslator_Name);
  12389. if (nickname !== undefined && nickname.length > 0 && nickname !== this.me.displayName) {
  12390. // issue a change nickname request
  12391. this.changeNicknameAsync(nickname);
  12392. }
  12393. }
  12394. }
  12395. catch (e) {
  12396. //
  12397. }
  12398. };
  12399. this.onConversationExpiration = (r, e) => {
  12400. try {
  12401. if (!!this.privConversationTranslator) {
  12402. this.privConversationTranslator.conversationExpiration(this.privConversationTranslator, e);
  12403. }
  12404. }
  12405. catch (e) {
  12406. //
  12407. }
  12408. };
  12409. this.privIsConnected = false;
  12410. this.privIsDisposed = false;
  12411. this.privConversationId = "";
  12412. this.privProperties = new Exports_js_3.PropertyCollection();
  12413. this.privManager = new Exports_js_1.ConversationManager();
  12414. // check the speech language
  12415. const language = speechConfig.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage]);
  12416. if (!language) {
  12417. speechConfig.setProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage], Exports_js_1.ConversationConnectionConfig.defaultLanguageCode);
  12418. }
  12419. this.privLanguage = speechConfig.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage]);
  12420. if (!id) {
  12421. // check the target language(s)
  12422. if (speechConfig.targetLanguages.length === 0) {
  12423. speechConfig.addTargetLanguage(this.privLanguage);
  12424. }
  12425. // check the profanity setting: speech and conversationTranslator should be in sync
  12426. const profanity = speechConfig.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceResponse_ProfanityOption]);
  12427. if (!profanity) {
  12428. speechConfig.setProfanity(Exports_js_3.ProfanityOption.Masked);
  12429. }
  12430. // check the nickname: it should pass this regex: ^\w+([\s-][\w\(\)]+)*$"
  12431. // TODO: specify the regex required. Nicknames must be unique or get the duplicate nickname error
  12432. // TODO: check what the max length is and if a truncation is required or if the service handles it without an error
  12433. let hostNickname = speechConfig.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.ConversationTranslator_Name]);
  12434. if (hostNickname === undefined || hostNickname === null) {
  12435. hostNickname = "Host";
  12436. }
  12437. Contracts_js_1.Contracts.throwIfNullOrTooLong(hostNickname, "nickname", 50);
  12438. Contracts_js_1.Contracts.throwIfNullOrTooShort(hostNickname, "nickname", 2);
  12439. speechConfig.setProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.ConversationTranslator_Name], hostNickname);
  12440. }
  12441. else {
  12442. this.privConversationId = id;
  12443. }
  12444. // save the speech config for future usage
  12445. this.privConfig = speechConfig;
  12446. // save the config properties
  12447. const configImpl = speechConfig;
  12448. Contracts_js_1.Contracts.throwIfNull(configImpl, "speechConfig");
  12449. this.privProperties = configImpl.properties.clone();
  12450. this.privIsConnected = false;
  12451. this.privParticipants = new Exports_js_1.InternalParticipants();
  12452. this.privIsReady = false;
  12453. this.privTextMessageMaxLength = 1000;
  12454. }
  12455. // get the internal data about a conversation
  12456. get room() {
  12457. return this.privRoom;
  12458. }
  12459. // get the wrapper for connecting to the websockets
  12460. get connection() {
  12461. return this.privConversationRecognizer; // this.privConnection;
  12462. }
  12463. // get the config
  12464. get config() {
  12465. return this.privConfig;
  12466. }
  12467. // get the conversation Id
  12468. get conversationId() {
  12469. return this.privRoom ? this.privRoom.roomId : this.privConversationId;
  12470. }
  12471. // get the properties
  12472. get properties() {
  12473. return this.privProperties;
  12474. }
  12475. // get the speech language
  12476. get speechRecognitionLanguage() {
  12477. return this.privLanguage;
  12478. }
  12479. get isMutedByHost() {
  12480. return this.privParticipants.me?.isHost ? false : this.privParticipants.me?.isMuted;
  12481. }
  12482. get isConnected() {
  12483. return this.privIsConnected && this.privIsReady;
  12484. }
  12485. get participants() {
  12486. return this.toParticipants(true);
  12487. }
  12488. get me() {
  12489. return this.toParticipant(this.privParticipants.me);
  12490. }
  12491. get host() {
  12492. return this.toParticipant(this.privParticipants.host);
  12493. }
  12494. get transcriberRecognizer() {
  12495. return this.privTranscriberRecognizer;
  12496. }
  12497. get conversationInfo() {
  12498. const convId = this.conversationId;
  12499. const p = this.participants.map((part) => ({
  12500. id: part.id,
  12501. preferredLanguage: part.preferredLanguage,
  12502. voice: part.voice
  12503. }));
  12504. const props = {};
  12505. for (const key of Exports_js_1.ConversationConnectionConfig.transcriptionEventKeys) {
  12506. const val = this.properties.getProperty(key, "");
  12507. if (val !== "") {
  12508. props[key] = val;
  12509. }
  12510. }
  12511. const info = { id: convId, participants: p, conversationProperties: props };
  12512. return info;
  12513. }
  12514. get canSend() {
  12515. return this.privIsConnected && !this.privParticipants.me?.isMuted;
  12516. }
  12517. get canSendAsHost() {
  12518. return this.privIsConnected && this.privParticipants.me?.isHost;
  12519. }
  12520. // get / set the speech auth token
  12521. // eslint-disable-next-line @typescript-eslint/member-ordering
  12522. get authorizationToken() {
  12523. return this.privToken;
  12524. }
  12525. set authorizationToken(value) {
  12526. Contracts_js_1.Contracts.throwIfNullOrWhitespace(value, "authorizationToken");
  12527. this.privToken = value;
  12528. }
  12529. set conversationTranslator(conversationTranslator) {
  12530. this.privConversationTranslator = conversationTranslator;
  12531. }
  12532. onToken(token) {
  12533. this.privConversationTranslator.onToken(token);
  12534. }
  12535. /**
  12536. * Create a new conversation as Host
  12537. * @param cb
  12538. * @param err
  12539. */
  12540. createConversationAsync(cb, err) {
  12541. try {
  12542. if (!!this.privConversationRecognizer) {
  12543. this.handleError(new Error(this.privErrors.permissionDeniedStart), err);
  12544. }
  12545. this.privManager.createOrJoin(this.privProperties, undefined, ((room) => {
  12546. if (!room) {
  12547. this.handleError(new Error(this.privErrors.permissionDeniedConnect), err);
  12548. }
  12549. this.privRoom = room;
  12550. this.handleCallback(cb, err);
  12551. }), ((error) => {
  12552. this.handleError(error, err);
  12553. }));
  12554. }
  12555. catch (error) {
  12556. this.handleError(error, err);
  12557. }
  12558. }
  12559. /**
  12560. * Starts a new conversation as host.
  12561. * @param cb
  12562. * @param err
  12563. */
  12564. startConversationAsync(cb, err) {
  12565. try {
  12566. // check if there is already a recognizer
  12567. if (!!this.privConversationRecognizer) {
  12568. this.handleError(new Error(this.privErrors.permissionDeniedStart), err);
  12569. }
  12570. // check if there is conversation data available
  12571. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedConnect);
  12572. // connect to the conversation websocket
  12573. this.privParticipants.meId = this.privRoom.participantId;
  12574. this.privConversationRecognizer = Exports_js_1.ConversationRecognizerFactory.fromConfig(this, this.privConfig);
  12575. // Because ConversationTranslator manually sets up and manages the connection, Conversation
  12576. // has to forward serviceRecognizer connection events that usually get passed automatically
  12577. this.privConversationRecognizer.connected = this.onConnected;
  12578. this.privConversationRecognizer.disconnected = this.onDisconnected;
  12579. this.privConversationRecognizer.canceled = this.onCanceled;
  12580. this.privConversationRecognizer.participantUpdateCommandReceived = this.onParticipantUpdateCommandReceived;
  12581. this.privConversationRecognizer.lockRoomCommandReceived = this.onLockRoomCommandReceived;
  12582. this.privConversationRecognizer.muteAllCommandReceived = this.onMuteAllCommandReceived;
  12583. this.privConversationRecognizer.participantJoinCommandReceived = this.onParticipantJoinCommandReceived;
  12584. this.privConversationRecognizer.participantLeaveCommandReceived = this.onParticipantLeaveCommandReceived;
  12585. this.privConversationRecognizer.translationReceived = this.onTranslationReceived;
  12586. this.privConversationRecognizer.participantsListReceived = this.onParticipantsListReceived;
  12587. this.privConversationRecognizer.conversationExpiration = this.onConversationExpiration;
  12588. this.privConversationRecognizer.connect(this.privRoom.token, (() => {
  12589. this.handleCallback(cb, err);
  12590. }), ((error) => {
  12591. this.handleError(error, err);
  12592. }));
  12593. }
  12594. catch (error) {
  12595. this.handleError(error, err);
  12596. }
  12597. }
  12598. /**
  12599. * Join a conversation as a participant.
  12600. * @param { IParticipant } participant - participant to add
  12601. * @param cb
  12602. * @param err
  12603. */
  12604. addParticipantAsync(participant, cb, err) {
  12605. Contracts_js_1.Contracts.throwIfNullOrUndefined(participant, "Participant");
  12606. (0, Exports_js_2.marshalPromiseToCallbacks)(this.addParticipantImplAsync(participant), cb, err);
  12607. }
  12608. /**
  12609. * Join a conversation as a participant.
  12610. * @param conversation
  12611. * @param nickname
  12612. * @param lang
  12613. * @param cb
  12614. * @param err
  12615. */
  12616. joinConversationAsync(conversationId, nickname, lang, cb, err) {
  12617. try {
  12618. // TODO
  12619. // if (!!this.privConversationRecognizer) {
  12620. // throw new Error(this.privErrors.permissionDeniedStart);
  12621. // }
  12622. Contracts_js_1.Contracts.throwIfNullOrWhitespace(conversationId, this.privErrors.invalidArgs.replace("{arg}", "conversationId"));
  12623. Contracts_js_1.Contracts.throwIfNullOrWhitespace(nickname, this.privErrors.invalidArgs.replace("{arg}", "nickname"));
  12624. Contracts_js_1.Contracts.throwIfNullOrWhitespace(lang, this.privErrors.invalidArgs.replace("{arg}", "language"));
  12625. // join the conversation
  12626. this.privManager.createOrJoin(this.privProperties, conversationId, ((room) => {
  12627. Contracts_js_1.Contracts.throwIfNullOrUndefined(room, this.privErrors.permissionDeniedConnect);
  12628. this.privRoom = room;
  12629. this.privConfig.authorizationToken = room.cognitiveSpeechAuthToken;
  12630. // join callback
  12631. if (!!cb) {
  12632. cb(room.cognitiveSpeechAuthToken);
  12633. }
  12634. }), ((error) => {
  12635. this.handleError(error, err);
  12636. }));
  12637. }
  12638. catch (error) {
  12639. this.handleError(error, err);
  12640. }
  12641. }
  12642. /**
  12643. * Deletes a conversation
  12644. * @param cb
  12645. * @param err
  12646. */
  12647. deleteConversationAsync(cb, err) {
  12648. (0, Exports_js_2.marshalPromiseToCallbacks)(this.deleteConversationImplAsync(), cb, err);
  12649. }
  12650. async deleteConversationImplAsync() {
  12651. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privProperties, this.privErrors.permissionDeniedConnect);
  12652. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.token, this.privErrors.permissionDeniedConnect);
  12653. await this.privManager.leave(this.privProperties, this.privRoom.token);
  12654. this.dispose();
  12655. }
  12656. /**
  12657. * Issues a request to close the client websockets
  12658. * @param cb
  12659. * @param err
  12660. */
  12661. endConversationAsync(cb, err) {
  12662. (0, Exports_js_2.marshalPromiseToCallbacks)(this.endConversationImplAsync(), cb, err);
  12663. }
  12664. endConversationImplAsync() {
  12665. return this.close(true);
  12666. }
  12667. /**
  12668. * Issues a request to lock the conversation
  12669. * @param cb
  12670. * @param err
  12671. */
  12672. lockConversationAsync(cb, err) {
  12673. try {
  12674. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12675. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12676. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12677. if (!this.canSendAsHost) {
  12678. this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}", "lock")), err);
  12679. }
  12680. if (!!this.privConversationRecognizer) {
  12681. this.privConversationRecognizer.sendRequest(this.getLockCommand(true), (() => {
  12682. this.handleCallback(cb, err);
  12683. }), ((error) => {
  12684. this.handleError(error, err);
  12685. }));
  12686. }
  12687. }
  12688. catch (error) {
  12689. this.handleError(error, err);
  12690. }
  12691. }
  12692. /**
  12693. * Issues a request to mute the conversation
  12694. * @param cb
  12695. * @param err
  12696. */
  12697. muteAllParticipantsAsync(cb, err) {
  12698. try {
  12699. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12700. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12701. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privConversationRecognizer, this.privErrors.permissionDeniedSend);
  12702. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12703. // check the user's permissions
  12704. if (!this.canSendAsHost) {
  12705. this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}", "mute")), err);
  12706. }
  12707. if (!!this.privConversationRecognizer) {
  12708. this.privConversationRecognizer.sendRequest(this.getMuteAllCommand(true), (() => {
  12709. this.handleCallback(cb, err);
  12710. }), ((error) => {
  12711. this.handleError(error, err);
  12712. }));
  12713. }
  12714. }
  12715. catch (error) {
  12716. this.handleError(error, err);
  12717. }
  12718. }
  12719. /**
  12720. * Issues a request to mute a participant in the conversation
  12721. * @param userId
  12722. * @param cb
  12723. * @param err
  12724. */
  12725. muteParticipantAsync(userId, cb, err) {
  12726. try {
  12727. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12728. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12729. Contracts_js_1.Contracts.throwIfNullOrWhitespace(userId, this.privErrors.invalidArgs.replace("{arg}", "userId"));
  12730. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12731. // check the connection is open (host + participant can perform the mute command)
  12732. if (!this.canSend) {
  12733. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  12734. }
  12735. // if not host, check the participant is not muting another participant
  12736. if (!this.me.isHost && this.me.id !== userId) {
  12737. this.handleError(new Error(this.privErrors.permissionDeniedParticipant.replace("{command}", "mute")), err);
  12738. }
  12739. // check the user exists
  12740. const exists = this.privParticipants.getParticipantIndex(userId);
  12741. if (exists === -1) {
  12742. this.handleError(new Error(this.privErrors.invalidParticipantRequest), err);
  12743. }
  12744. if (!!this.privConversationRecognizer) {
  12745. this.privConversationRecognizer.sendRequest(this.getMuteCommand(userId, true), (() => {
  12746. this.handleCallback(cb, err);
  12747. }), ((error) => {
  12748. this.handleError(error, err);
  12749. }));
  12750. }
  12751. }
  12752. catch (error) {
  12753. this.handleError(error, err);
  12754. }
  12755. }
  12756. /**
  12757. * Issues a request to remove a participant from the conversation
  12758. * @param userId
  12759. * @param cb
  12760. * @param err
  12761. */
  12762. removeParticipantAsync(userId, cb, err) {
  12763. try {
  12764. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12765. if (!!this.privTranscriberRecognizer && userId.hasOwnProperty("id")) {
  12766. // Assume this is a transcription participant
  12767. (0, Exports_js_2.marshalPromiseToCallbacks)(this.removeParticipantImplAsync(userId), cb, err);
  12768. }
  12769. else {
  12770. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12771. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12772. if (!this.canSendAsHost) {
  12773. this.handleError(new Error(this.privErrors.permissionDeniedParticipant.replace("{command}", "remove")), err);
  12774. }
  12775. let participantId = "";
  12776. if (typeof userId === "string") {
  12777. participantId = userId;
  12778. }
  12779. else if (userId.hasOwnProperty("id")) {
  12780. const participant = userId;
  12781. participantId = participant.id;
  12782. }
  12783. else if (userId.hasOwnProperty("userId")) {
  12784. const user = userId;
  12785. participantId = user.userId;
  12786. }
  12787. Contracts_js_1.Contracts.throwIfNullOrWhitespace(participantId, this.privErrors.invalidArgs.replace("{arg}", "userId"));
  12788. // check the participant exists
  12789. const index = this.participants.findIndex((p) => p.id === participantId);
  12790. if (index === -1) {
  12791. this.handleError(new Error(this.privErrors.invalidParticipantRequest), err);
  12792. }
  12793. if (!!this.privConversationRecognizer) {
  12794. this.privConversationRecognizer.sendRequest(this.getEjectCommand(participantId), (() => {
  12795. this.handleCallback(cb, err);
  12796. }), ((error) => {
  12797. this.handleError(error, err);
  12798. }));
  12799. }
  12800. }
  12801. }
  12802. catch (error) {
  12803. this.handleError(error, err);
  12804. }
  12805. }
  12806. /**
  12807. * Issues a request to unlock the conversation
  12808. * @param cb
  12809. * @param err
  12810. */
  12811. unlockConversationAsync(cb, err) {
  12812. try {
  12813. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12814. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12815. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12816. if (!this.canSendAsHost) {
  12817. this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}", "unlock")), err);
  12818. }
  12819. if (!!this.privConversationRecognizer) {
  12820. this.privConversationRecognizer.sendRequest(this.getLockCommand(false), (() => {
  12821. this.handleCallback(cb, err);
  12822. }), ((error) => {
  12823. this.handleError(error, err);
  12824. }));
  12825. }
  12826. }
  12827. catch (error) {
  12828. this.handleError(error, err);
  12829. }
  12830. }
  12831. /**
  12832. * Issues a request to unmute all participants in the conversation
  12833. * @param cb
  12834. * @param err
  12835. */
  12836. unmuteAllParticipantsAsync(cb, err) {
  12837. try {
  12838. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12839. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12840. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12841. if (!this.canSendAsHost) {
  12842. this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}", "unmute all")), err);
  12843. }
  12844. if (!!this.privConversationRecognizer) {
  12845. this.privConversationRecognizer.sendRequest(this.getMuteAllCommand(false), (() => {
  12846. this.handleCallback(cb, err);
  12847. }), ((error) => {
  12848. this.handleError(error, err);
  12849. }));
  12850. }
  12851. }
  12852. catch (error) {
  12853. this.handleError(error, err);
  12854. }
  12855. }
  12856. /**
  12857. * Issues a request to unmute a participant in the conversation
  12858. * @param userId
  12859. * @param cb
  12860. * @param err
  12861. */
  12862. unmuteParticipantAsync(userId, cb, err) {
  12863. try {
  12864. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12865. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12866. Contracts_js_1.Contracts.throwIfNullOrWhitespace(userId, this.privErrors.invalidArgs.replace("{arg}", "userId"));
  12867. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12868. // check the connection is open (host + participant can perform the mute command)
  12869. if (!this.canSend) {
  12870. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  12871. }
  12872. // if not host, check the participant is not muting another participant
  12873. if (!this.me.isHost && this.me.id !== userId) {
  12874. this.handleError(new Error(this.privErrors.permissionDeniedParticipant.replace("{command}", "mute")), err);
  12875. }
  12876. // check the user exists
  12877. const exists = this.privParticipants.getParticipantIndex(userId);
  12878. if (exists === -1) {
  12879. this.handleError(new Error(this.privErrors.invalidParticipantRequest), err);
  12880. }
  12881. if (!!this.privConversationRecognizer) {
  12882. this.privConversationRecognizer.sendRequest(this.getMuteCommand(userId, false), (() => {
  12883. this.handleCallback(cb, err);
  12884. }), ((error) => {
  12885. this.handleError(error, err);
  12886. }));
  12887. }
  12888. }
  12889. catch (error) {
  12890. this.handleError(error, err);
  12891. }
  12892. }
  12893. /**
  12894. * Send a text message
  12895. * @param message
  12896. * @param cb
  12897. * @param err
  12898. */
  12899. sendTextMessageAsync(message, cb, err) {
  12900. try {
  12901. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12902. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12903. Contracts_js_1.Contracts.throwIfNullOrWhitespace(message, this.privErrors.invalidArgs.replace("{arg}", "message"));
  12904. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12905. if (!this.canSend) {
  12906. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  12907. }
  12908. // TODO: is a max length check required?
  12909. if (message.length > this.privTextMessageMaxLength) {
  12910. this.handleError(new Error(this.privErrors.invalidArgs.replace("{arg}", "message length")), err);
  12911. }
  12912. if (!!this.privConversationRecognizer) {
  12913. this.privConversationRecognizer.sendRequest(this.getMessageCommand(message), (() => {
  12914. this.handleCallback(cb, err);
  12915. }), ((error) => {
  12916. this.handleError(error, err);
  12917. }));
  12918. }
  12919. }
  12920. catch (error) {
  12921. this.handleError(error, err);
  12922. }
  12923. }
  12924. /**
  12925. * Set translated to languages
  12926. * @param {string[]} languages - languages to translate to
  12927. * @param cb
  12928. * @param err
  12929. */
  12930. setTranslatedLanguagesAsync(languages, cb, err) {
  12931. try {
  12932. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12933. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12934. Contracts_js_1.Contracts.throwIfArrayEmptyOrWhitespace(languages, this.privErrors.invalidArgs.replace("{arg}", "languages"));
  12935. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12936. if (!this.canSend) {
  12937. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  12938. }
  12939. if (!!this.privConversationRecognizer) {
  12940. this.privConversationRecognizer.sendRequest(this.getSetTranslateToLanguagesCommand(languages), (() => {
  12941. this.handleCallback(cb, err);
  12942. }), ((error) => {
  12943. this.handleError(error, err);
  12944. }));
  12945. }
  12946. }
  12947. catch (error) {
  12948. this.handleError(error, err);
  12949. }
  12950. }
  12951. /**
  12952. * Change nickname
  12953. * @param {string} nickname - new nickname for the room
  12954. * @param cb
  12955. * @param err
  12956. */
  12957. changeNicknameAsync(nickname, cb, err) {
  12958. try {
  12959. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  12960. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  12961. Contracts_js_1.Contracts.throwIfNullOrWhitespace(nickname, this.privErrors.invalidArgs.replace("{arg}", "nickname"));
  12962. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  12963. if (!this.canSend) {
  12964. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  12965. }
  12966. if (!!this.privConversationRecognizer) {
  12967. this.privConversationRecognizer.sendRequest(this.getChangeNicknameCommand(nickname), (() => {
  12968. this.handleCallback(cb, err);
  12969. }), ((error) => {
  12970. this.handleError(error, err);
  12971. }));
  12972. }
  12973. }
  12974. catch (error) {
  12975. this.handleError(error, err);
  12976. }
  12977. }
  12978. isDisposed() {
  12979. return this.privIsDisposed;
  12980. }
  12981. dispose() {
  12982. if (this.isDisposed) {
  12983. return;
  12984. }
  12985. this.privIsDisposed = true;
  12986. if (!!this.config) {
  12987. this.config.close();
  12988. }
  12989. this.privConfig = undefined;
  12990. this.privLanguage = undefined;
  12991. this.privProperties = undefined;
  12992. this.privRoom = undefined;
  12993. this.privToken = undefined;
  12994. this.privManager = undefined;
  12995. this.privIsConnected = false;
  12996. this.privIsReady = false;
  12997. this.privParticipants = undefined;
  12998. }
  12999. async connectTranscriberRecognizer(recognizer) {
  13000. if (!!this.privTranscriberRecognizer) {
  13001. await this.privTranscriberRecognizer.close();
  13002. }
  13003. await recognizer.enforceAudioGating();
  13004. this.privTranscriberRecognizer = recognizer;
  13005. this.privTranscriberRecognizer.conversation = this;
  13006. }
  13007. getKeepAlive() {
  13008. const nickname = (!!this.me) ? this.me.displayName : "default_nickname";
  13009. return JSON.stringify({
  13010. id: "0",
  13011. nickname,
  13012. participantId: this.privRoom.participantId,
  13013. roomId: this.privRoom.roomId,
  13014. type: Exports_js_1.ConversationTranslatorMessageTypes.keepAlive
  13015. });
  13016. }
  13017. /* eslint-enable @typescript-eslint/typedef */
  13018. addParticipantImplAsync(participant) {
  13019. const newParticipant = this.privParticipants.addOrUpdateParticipant(participant);
  13020. if (newParticipant !== undefined) {
  13021. if (!!this.privTranscriberRecognizer) {
  13022. const conversationInfo = this.conversationInfo;
  13023. conversationInfo.participants = [participant];
  13024. return this.privTranscriberRecognizer.pushConversationEvent(conversationInfo, "join");
  13025. }
  13026. }
  13027. }
  13028. removeParticipantImplAsync(participant) {
  13029. this.privParticipants.deleteParticipant(participant.id);
  13030. const conversationInfo = this.conversationInfo;
  13031. conversationInfo.participants = [participant];
  13032. return this.privTranscriberRecognizer.pushConversationEvent(conversationInfo, "leave");
  13033. }
  13034. async close(dispose) {
  13035. try {
  13036. this.privIsConnected = false;
  13037. await this.privConversationRecognizer?.close();
  13038. this.privConversationRecognizer = undefined;
  13039. if (!!this.privConversationTranslator) {
  13040. this.privConversationTranslator.dispose();
  13041. }
  13042. }
  13043. catch (e) {
  13044. // ignore error
  13045. throw e;
  13046. }
  13047. if (dispose) {
  13048. this.dispose();
  13049. }
  13050. }
  13051. /** Helpers */
  13052. handleCallback(cb, err) {
  13053. if (!!cb) {
  13054. try {
  13055. cb();
  13056. }
  13057. catch (e) {
  13058. if (!!err) {
  13059. err(e);
  13060. }
  13061. }
  13062. cb = undefined;
  13063. }
  13064. }
  13065. handleError(error, err) {
  13066. if (!!err) {
  13067. if (error instanceof Error) {
  13068. const typedError = error;
  13069. err(typedError.name + ": " + typedError.message);
  13070. }
  13071. else {
  13072. err(error);
  13073. }
  13074. }
  13075. }
  13076. /** Participant Helpers */
  13077. toParticipants(includeHost) {
  13078. const participants = this.privParticipants.participants.map((p) => (this.toParticipant(p)));
  13079. if (!includeHost) {
  13080. return participants.filter((p) => p.isHost === false);
  13081. }
  13082. else {
  13083. return participants;
  13084. }
  13085. }
  13086. toParticipant(p) {
  13087. return new Exports_js_3.Participant(p.id, p.avatar, p.displayName, p.isHost, p.isMuted, p.isUsingTts, p.preferredLanguage, p.voice);
  13088. }
  13089. getMuteAllCommand(isMuted) {
  13090. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "conversationId");
  13091. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  13092. return JSON.stringify({
  13093. command: Exports_js_1.ConversationTranslatorCommandTypes.setMuteAll,
  13094. participantId: this.privRoom.participantId,
  13095. roomid: this.privRoom.roomId,
  13096. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  13097. value: isMuted
  13098. });
  13099. }
  13100. getMuteCommand(participantId, isMuted) {
  13101. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "conversationId");
  13102. Contracts_js_1.Contracts.throwIfNullOrWhitespace(participantId, "participantId");
  13103. return JSON.stringify({
  13104. command: Exports_js_1.ConversationTranslatorCommandTypes.setMute,
  13105. // eslint-disable-next-line object-shorthand
  13106. participantId: participantId,
  13107. roomid: this.privRoom.roomId,
  13108. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  13109. value: isMuted
  13110. });
  13111. }
  13112. getLockCommand(isLocked) {
  13113. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "conversationId");
  13114. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  13115. return JSON.stringify({
  13116. command: Exports_js_1.ConversationTranslatorCommandTypes.setLockState,
  13117. participantId: this.privRoom.participantId,
  13118. roomid: this.privRoom.roomId,
  13119. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  13120. value: isLocked
  13121. });
  13122. }
  13123. getEjectCommand(participantId) {
  13124. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "conversationId");
  13125. Contracts_js_1.Contracts.throwIfNullOrWhitespace(participantId, "participantId");
  13126. return JSON.stringify({
  13127. command: Exports_js_1.ConversationTranslatorCommandTypes.ejectParticipant,
  13128. // eslint-disable-next-line object-shorthand
  13129. participantId: participantId,
  13130. roomid: this.privRoom.roomId,
  13131. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  13132. });
  13133. }
  13134. getSetTranslateToLanguagesCommand(languages) {
  13135. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "conversationId");
  13136. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  13137. return JSON.stringify({
  13138. command: Exports_js_1.ConversationTranslatorCommandTypes.setTranslateToLanguages,
  13139. participantId: this.privRoom.participantId,
  13140. roomid: this.privRoom.roomId,
  13141. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  13142. value: languages
  13143. });
  13144. }
  13145. getChangeNicknameCommand(nickname) {
  13146. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "conversationId");
  13147. Contracts_js_1.Contracts.throwIfNullOrWhitespace(nickname, "nickname");
  13148. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  13149. return JSON.stringify({
  13150. command: Exports_js_1.ConversationTranslatorCommandTypes.changeNickname,
  13151. nickname,
  13152. participantId: this.privRoom.participantId,
  13153. roomid: this.privRoom.roomId,
  13154. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  13155. value: nickname
  13156. });
  13157. }
  13158. getMessageCommand(message) {
  13159. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "conversationId");
  13160. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  13161. Contracts_js_1.Contracts.throwIfNullOrWhitespace(message, "message");
  13162. return JSON.stringify({
  13163. participantId: this.privRoom.participantId,
  13164. roomId: this.privRoom.roomId,
  13165. text: message,
  13166. type: Exports_js_1.ConversationTranslatorMessageTypes.instantMessage
  13167. });
  13168. }
  13169. }
  13170. exports.ConversationImpl = ConversationImpl;
  13171. /***/ }),
  13172. /* 159 */
  13173. /***/ ((__unused_webpack_module, exports) => {
  13174. "use strict";
  13175. // Copyright (c) Microsoft Corporation. All rights reserved.
  13176. // Licensed under the MIT license.
  13177. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13178. exports.ConversationCommon = void 0;
  13179. class ConversationCommon {
  13180. constructor(audioConfig) {
  13181. this.privAudioConfig = audioConfig;
  13182. }
  13183. handleCallback(cb, err) {
  13184. if (!!cb) {
  13185. try {
  13186. cb();
  13187. }
  13188. catch (e) {
  13189. if (!!err) {
  13190. err(e);
  13191. }
  13192. }
  13193. cb = undefined;
  13194. }
  13195. }
  13196. handleError(error, err) {
  13197. if (!!err) {
  13198. if (error instanceof Error) {
  13199. const typedError = error;
  13200. err(typedError.name + ": " + typedError.message);
  13201. }
  13202. else {
  13203. err(error);
  13204. }
  13205. }
  13206. }
  13207. }
  13208. exports.ConversationCommon = ConversationCommon;
  13209. /***/ }),
  13210. /* 160 */
  13211. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13212. "use strict";
  13213. // Copyright (c) Microsoft Corporation. All rights reserved.
  13214. // Licensed under the MIT license.
  13215. // Multi-device Conversation is a Preview feature.
  13216. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13217. exports.ConversationExpirationEventArgs = void 0;
  13218. const Exports_js_1 = __webpack_require__(79);
  13219. class ConversationExpirationEventArgs extends Exports_js_1.SessionEventArgs {
  13220. constructor(expirationTime, sessionId) {
  13221. super(sessionId);
  13222. this.privExpirationTime = expirationTime;
  13223. }
  13224. /** How much longer until the conversation expires (in minutes). */
  13225. get expirationTime() {
  13226. return this.privExpirationTime;
  13227. }
  13228. }
  13229. exports.ConversationExpirationEventArgs = ConversationExpirationEventArgs;
  13230. /***/ }),
  13231. /* 161 */
  13232. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13233. "use strict";
  13234. // Copyright (c) Microsoft Corporation. All rights reserved.
  13235. // Licensed under the MIT license.
  13236. // Multi-device Conversation is a Preview feature.
  13237. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13238. exports.ConversationParticipantsChangedEventArgs = void 0;
  13239. const Exports_js_1 = __webpack_require__(79);
  13240. class ConversationParticipantsChangedEventArgs extends Exports_js_1.SessionEventArgs {
  13241. constructor(reason, participants, sessionId) {
  13242. super(sessionId);
  13243. this.privReason = reason;
  13244. this.privParticipant = participants;
  13245. }
  13246. get reason() {
  13247. return this.privReason;
  13248. }
  13249. get participants() {
  13250. return this.privParticipant;
  13251. }
  13252. }
  13253. exports.ConversationParticipantsChangedEventArgs = ConversationParticipantsChangedEventArgs;
  13254. /***/ }),
  13255. /* 162 */
  13256. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13257. "use strict";
  13258. // Copyright (c) Microsoft Corporation. All rights reserved.
  13259. // Licensed under the MIT license.
  13260. // Multi-device Conversation is a Preview feature.
  13261. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13262. exports.ConversationTranslationCanceledEventArgs = void 0;
  13263. const CancellationEventArgsBase_js_1 = __webpack_require__(101);
  13264. class ConversationTranslationCanceledEventArgs extends CancellationEventArgsBase_js_1.CancellationEventArgsBase {
  13265. }
  13266. exports.ConversationTranslationCanceledEventArgs = ConversationTranslationCanceledEventArgs;
  13267. /***/ }),
  13268. /* 163 */
  13269. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13270. "use strict";
  13271. // Copyright (c) Microsoft Corporation. All rights reserved.
  13272. // Licensed under the MIT license.
  13273. // Multi-device Conversation is a Preview feature.
  13274. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13275. exports.ConversationTranslationEventArgs = void 0;
  13276. const Exports_js_1 = __webpack_require__(79);
  13277. class ConversationTranslationEventArgs extends Exports_js_1.RecognitionEventArgs {
  13278. /**
  13279. * Creates and initializes an instance of this class.
  13280. * @constructor
  13281. * @param {ConversationTranslationResult} result - The translation recognition result.
  13282. * @param {number} offset - The offset.
  13283. * @param {string} sessionId - The session id.
  13284. */
  13285. constructor(result, offset, sessionId) {
  13286. super(offset, sessionId);
  13287. this.privResult = result;
  13288. }
  13289. /**
  13290. * Specifies the recognition result.
  13291. * @returns {ConversationTranslationResult} the recognition result.
  13292. */
  13293. get result() {
  13294. return this.privResult;
  13295. }
  13296. }
  13297. exports.ConversationTranslationEventArgs = ConversationTranslationEventArgs;
  13298. /***/ }),
  13299. /* 164 */
  13300. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13301. "use strict";
  13302. // Copyright (c) Microsoft Corporation. All rights reserved.
  13303. // Licensed under the MIT license.
  13304. // Multi-device Conversation is a Preview feature.
  13305. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13306. exports.ConversationTranslationResult = void 0;
  13307. const TranslationRecognitionResult_js_1 = __webpack_require__(104);
  13308. class ConversationTranslationResult extends TranslationRecognitionResult_js_1.TranslationRecognitionResult {
  13309. constructor(participantId, translations, originalLanguage, resultId, reason, text, duration, offset, errorDetails, json, properties) {
  13310. super(translations, resultId, reason, text, duration, offset, undefined, undefined, errorDetails, json, properties);
  13311. this.privId = participantId;
  13312. this.privOrigLang = originalLanguage;
  13313. }
  13314. /**
  13315. * The unique identifier for the participant this result is for.
  13316. */
  13317. get participantId() {
  13318. return this.privId;
  13319. }
  13320. /**
  13321. * The original language this result was in.
  13322. */
  13323. get originalLang() {
  13324. return this.privOrigLang;
  13325. }
  13326. }
  13327. exports.ConversationTranslationResult = ConversationTranslationResult;
  13328. /***/ }),
  13329. /* 165 */
  13330. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13331. "use strict";
  13332. // Copyright (c) Microsoft Corporation. All rights reserved.
  13333. // Licensed under the MIT license.
  13334. // Multi-device Conversation is a Preview feature.
  13335. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13336. exports.ConversationTranslator = exports.SpeechState = void 0;
  13337. /* eslint-disable max-classes-per-file */
  13338. const Exports_js_1 = __webpack_require__(2);
  13339. const ConversationTranslatorConnectionFactory_js_1 = __webpack_require__(166);
  13340. const Exports_js_2 = __webpack_require__(4);
  13341. const Contracts_js_1 = __webpack_require__(64);
  13342. const Exports_js_3 = __webpack_require__(79);
  13343. const Conversation_js_1 = __webpack_require__(158);
  13344. const Exports_js_4 = __webpack_require__(157);
  13345. var SpeechState;
  13346. (function (SpeechState) {
  13347. SpeechState[SpeechState["Inactive"] = 0] = "Inactive";
  13348. SpeechState[SpeechState["Connecting"] = 1] = "Connecting";
  13349. SpeechState[SpeechState["Connected"] = 2] = "Connected";
  13350. })(SpeechState = exports.SpeechState || (exports.SpeechState = {}));
  13351. // child class of TranslationRecognizer meant only for use with ConversationTranslator
  13352. class ConversationTranslationRecognizer extends Exports_js_3.TranslationRecognizer {
  13353. constructor(speechConfig, audioConfig, translator, convGetter) {
  13354. super(speechConfig, audioConfig, new ConversationTranslatorConnectionFactory_js_1.ConversationTranslatorConnectionFactory(convGetter));
  13355. this.privSpeechState = SpeechState.Inactive;
  13356. if (!!translator) {
  13357. this.privTranslator = translator;
  13358. this.sessionStarted = () => {
  13359. this.privSpeechState = SpeechState.Connected;
  13360. };
  13361. this.sessionStopped = () => {
  13362. this.privSpeechState = SpeechState.Inactive;
  13363. };
  13364. this.recognizing = (tr, e) => {
  13365. if (!!this.privTranslator.recognizing) {
  13366. this.privTranslator.recognizing(this.privTranslator, e);
  13367. }
  13368. };
  13369. // eslint-disable-next-line @typescript-eslint/no-misused-promises
  13370. this.recognized = async (tr, e) => {
  13371. // if there is an error connecting to the conversation service from the speech service the error will be returned in the ErrorDetails field.
  13372. if (e.result?.errorDetails) {
  13373. await this.cancelSpeech();
  13374. // TODO: format the error message contained in 'errorDetails'
  13375. this.fireCancelEvent(e.result.errorDetails);
  13376. }
  13377. else {
  13378. if (!!this.privTranslator.recognized) {
  13379. this.privTranslator.recognized(this.privTranslator, e);
  13380. }
  13381. }
  13382. return;
  13383. };
  13384. // eslint-disable-next-line @typescript-eslint/no-misused-promises
  13385. this.canceled = async () => {
  13386. if (this.privSpeechState !== SpeechState.Inactive) {
  13387. try {
  13388. await this.cancelSpeech();
  13389. }
  13390. catch (error) {
  13391. this.privSpeechState = SpeechState.Inactive;
  13392. }
  13393. }
  13394. };
  13395. }
  13396. }
  13397. get state() {
  13398. return this.privSpeechState;
  13399. }
  13400. set state(newState) {
  13401. this.privSpeechState = newState;
  13402. }
  13403. set authentication(token) {
  13404. this.privReco.authentication = token;
  13405. }
  13406. onConnection() {
  13407. this.privSpeechState = SpeechState.Connected;
  13408. }
  13409. async onCancelSpeech() {
  13410. this.privSpeechState = SpeechState.Inactive;
  13411. await this.cancelSpeech();
  13412. }
  13413. /**
  13414. * Fire a cancel event
  13415. * @param error
  13416. */
  13417. fireCancelEvent(error) {
  13418. try {
  13419. if (!!this.privTranslator.canceled) {
  13420. const cancelEvent = new Exports_js_4.ConversationTranslationCanceledEventArgs(Exports_js_3.CancellationReason.Error, error, Exports_js_3.CancellationErrorCode.RuntimeError);
  13421. this.privTranslator.canceled(this.privTranslator, cancelEvent);
  13422. }
  13423. }
  13424. catch (e) {
  13425. //
  13426. }
  13427. }
  13428. async cancelSpeech() {
  13429. try {
  13430. this.stopContinuousRecognitionAsync();
  13431. await this.privReco?.disconnect();
  13432. this.privSpeechState = SpeechState.Inactive;
  13433. }
  13434. catch (e) {
  13435. // ignore the error
  13436. }
  13437. }
  13438. }
  13439. /**
  13440. * Join, leave or connect to a conversation.
  13441. */
  13442. class ConversationTranslator extends Exports_js_4.ConversationCommon {
  13443. constructor(audioConfig) {
  13444. super(audioConfig);
  13445. this.privErrors = Exports_js_1.ConversationConnectionConfig.restErrors;
  13446. this.privIsDisposed = false;
  13447. this.privIsSpeaking = false;
  13448. this.privPlaceholderKey = "abcdefghijklmnopqrstuvwxyz012345";
  13449. this.privPlaceholderRegion = "westus";
  13450. this.privProperties = new Exports_js_3.PropertyCollection();
  13451. }
  13452. get properties() {
  13453. return this.privProperties;
  13454. }
  13455. get speechRecognitionLanguage() {
  13456. return this.privSpeechRecognitionLanguage;
  13457. }
  13458. get participants() {
  13459. return this.privConversation?.participants;
  13460. }
  13461. get canSpeak() {
  13462. // is there a Conversation websocket available and has the Recognizer been set up
  13463. if (!this.privConversation.isConnected || !this.privCTRecognizer) {
  13464. return false;
  13465. }
  13466. // is the user already speaking
  13467. if (this.privIsSpeaking || this.privCTRecognizer.state === SpeechState.Connected || this.privCTRecognizer.state === SpeechState.Connecting) {
  13468. return false;
  13469. }
  13470. // is the user muted
  13471. if (this.privConversation.isMutedByHost) {
  13472. return false;
  13473. }
  13474. return true;
  13475. }
  13476. onToken(token) {
  13477. this.privCTRecognizer.authentication = token;
  13478. }
  13479. setServiceProperty(name, value) {
  13480. const currentProperties = JSON.parse(this.privProperties.getProperty(Exports_js_1.ServicePropertiesPropertyName, "{}"));
  13481. currentProperties[name] = value;
  13482. this.privProperties.setProperty(Exports_js_1.ServicePropertiesPropertyName, JSON.stringify(currentProperties));
  13483. }
  13484. joinConversationAsync(conversation, nickname, param1, param2, param3) {
  13485. try {
  13486. if (typeof conversation === "string") {
  13487. Contracts_js_1.Contracts.throwIfNullOrUndefined(conversation, this.privErrors.invalidArgs.replace("{arg}", "conversation id"));
  13488. Contracts_js_1.Contracts.throwIfNullOrWhitespace(nickname, this.privErrors.invalidArgs.replace("{arg}", "nickname"));
  13489. if (!!this.privConversation) {
  13490. this.handleError(new Error(this.privErrors.permissionDeniedStart), param3);
  13491. }
  13492. let lang = param1;
  13493. if (lang === undefined || lang === null || lang === "") {
  13494. lang = Exports_js_1.ConversationConnectionConfig.defaultLanguageCode;
  13495. }
  13496. // create a placeholder config
  13497. this.privSpeechTranslationConfig = Exports_js_3.SpeechTranslationConfig.fromSubscription(this.privPlaceholderKey, this.privPlaceholderRegion);
  13498. this.privSpeechTranslationConfig.setProfanity(Exports_js_3.ProfanityOption.Masked);
  13499. this.privSpeechTranslationConfig.addTargetLanguage(lang);
  13500. this.privSpeechTranslationConfig.setProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage], lang);
  13501. this.privSpeechTranslationConfig.setProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.ConversationTranslator_Name], nickname);
  13502. const propertyIdsToCopy = [
  13503. Exports_js_3.PropertyId.SpeechServiceConnection_Host,
  13504. Exports_js_3.PropertyId.ConversationTranslator_Host,
  13505. Exports_js_3.PropertyId.SpeechServiceConnection_Endpoint,
  13506. Exports_js_3.PropertyId.SpeechServiceConnection_ProxyHostName,
  13507. Exports_js_3.PropertyId.SpeechServiceConnection_ProxyPassword,
  13508. Exports_js_3.PropertyId.SpeechServiceConnection_ProxyPort,
  13509. Exports_js_3.PropertyId.SpeechServiceConnection_ProxyUserName,
  13510. "ConversationTranslator_MultiChannelAudio",
  13511. "ConversationTranslator_Region"
  13512. ];
  13513. for (const prop of propertyIdsToCopy) {
  13514. const value = this.privProperties.getProperty(prop);
  13515. if (value) {
  13516. const key = typeof prop === "string" ? prop : Exports_js_3.PropertyId[prop];
  13517. this.privSpeechTranslationConfig.setProperty(key, value);
  13518. }
  13519. }
  13520. const currentProperties = JSON.parse(this.privProperties.getProperty(Exports_js_1.ServicePropertiesPropertyName, "{}"));
  13521. for (const prop of Object.keys(currentProperties)) {
  13522. this.privSpeechTranslationConfig.setServiceProperty(prop, currentProperties[prop], Exports_js_3.ServicePropertyChannel.UriQueryParameter);
  13523. }
  13524. // join the conversation
  13525. this.privConversation = new Conversation_js_1.ConversationImpl(this.privSpeechTranslationConfig);
  13526. this.privConversation.conversationTranslator = this;
  13527. this.privConversation.joinConversationAsync(conversation, nickname, lang, ((result) => {
  13528. if (!result) {
  13529. this.handleError(new Error(this.privErrors.permissionDeniedConnect), param3);
  13530. }
  13531. this.privSpeechTranslationConfig.authorizationToken = result;
  13532. this.privConversation.room.isHost = false;
  13533. // connect to the ws
  13534. this.privConversation.startConversationAsync((() => {
  13535. this.handleCallback(param2, param3);
  13536. }), ((error) => {
  13537. this.handleError(error, param3);
  13538. }));
  13539. }), ((error) => {
  13540. this.handleError(error, param3);
  13541. }));
  13542. }
  13543. else if (typeof conversation === "object") {
  13544. Contracts_js_1.Contracts.throwIfNullOrUndefined(conversation, this.privErrors.invalidArgs.replace("{arg}", "conversation id"));
  13545. Contracts_js_1.Contracts.throwIfNullOrWhitespace(nickname, this.privErrors.invalidArgs.replace("{arg}", "nickname"));
  13546. // save the nickname
  13547. this.privProperties.setProperty(Exports_js_3.PropertyId.ConversationTranslator_Name, nickname);
  13548. // ref the conversation object
  13549. this.privConversation = conversation;
  13550. // ref the conversation translator object
  13551. this.privConversation.conversationTranslator = this;
  13552. this.privConversation.room.isHost = true;
  13553. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privConversation, this.privErrors.permissionDeniedConnect);
  13554. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privConversation.room.token, this.privErrors.permissionDeniedConnect);
  13555. this.privSpeechTranslationConfig = conversation.config;
  13556. this.handleCallback(param1, param2);
  13557. }
  13558. else {
  13559. this.handleError(new Error(this.privErrors.invalidArgs.replace("{arg}", "invalid conversation type")), param2);
  13560. }
  13561. }
  13562. catch (error) {
  13563. this.handleError(error, typeof param1 === "string" ? param3 : param2);
  13564. }
  13565. }
  13566. /**
  13567. * Leave the conversation
  13568. * @param cb
  13569. * @param err
  13570. */
  13571. leaveConversationAsync(cb, err) {
  13572. (0, Exports_js_2.marshalPromiseToCallbacks)((async () => {
  13573. // stop the speech websocket
  13574. await this.cancelSpeech();
  13575. // stop the websocket
  13576. await this.privConversation.endConversationImplAsync();
  13577. // https delete request
  13578. await this.privConversation.deleteConversationImplAsync();
  13579. this.dispose();
  13580. })(), cb, err);
  13581. }
  13582. /**
  13583. * Send a text message
  13584. * @param message
  13585. * @param cb
  13586. * @param err
  13587. */
  13588. sendTextMessageAsync(message, cb, err) {
  13589. try {
  13590. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privConversation, this.privErrors.permissionDeniedSend);
  13591. Contracts_js_1.Contracts.throwIfNullOrWhitespace(message, this.privErrors.invalidArgs.replace("{arg}", message));
  13592. this.privConversation.sendTextMessageAsync(message, cb, err);
  13593. }
  13594. catch (error) {
  13595. this.handleError(error, err);
  13596. }
  13597. }
  13598. /**
  13599. * Start speaking
  13600. * @param cb
  13601. * @param err
  13602. */
  13603. startTranscribingAsync(cb, err) {
  13604. (0, Exports_js_2.marshalPromiseToCallbacks)((async () => {
  13605. try {
  13606. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privConversation, this.privErrors.permissionDeniedSend);
  13607. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privConversation.room.token, this.privErrors.permissionDeniedConnect);
  13608. if (this.privCTRecognizer === undefined) {
  13609. await this.connectTranslatorRecognizer();
  13610. }
  13611. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privCTRecognizer, this.privErrors.permissionDeniedSend);
  13612. if (!this.canSpeak) {
  13613. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  13614. }
  13615. await this.startContinuousRecognition();
  13616. this.privIsSpeaking = true;
  13617. }
  13618. catch (error) {
  13619. this.privIsSpeaking = false;
  13620. await this.cancelSpeech();
  13621. throw error;
  13622. }
  13623. })(), cb, err);
  13624. }
  13625. /**
  13626. * Stop speaking
  13627. * @param cb
  13628. * @param err
  13629. */
  13630. stopTranscribingAsync(cb, err) {
  13631. (0, Exports_js_2.marshalPromiseToCallbacks)((async () => {
  13632. try {
  13633. if (!this.privIsSpeaking) {
  13634. // stop speech
  13635. await this.cancelSpeech();
  13636. return;
  13637. }
  13638. // stop the recognition but leave the websocket open
  13639. this.privIsSpeaking = false;
  13640. await new Promise((resolve, reject) => {
  13641. this.privCTRecognizer.stopContinuousRecognitionAsync(resolve, reject);
  13642. });
  13643. }
  13644. catch (error) {
  13645. await this.cancelSpeech();
  13646. }
  13647. })(), cb, err);
  13648. }
  13649. isDisposed() {
  13650. return this.privIsDisposed;
  13651. }
  13652. dispose(reason, success, err) {
  13653. (0, Exports_js_2.marshalPromiseToCallbacks)((async () => {
  13654. if (this.isDisposed && !this.privIsSpeaking) {
  13655. return;
  13656. }
  13657. await this.cancelSpeech();
  13658. this.privIsDisposed = true;
  13659. this.privSpeechTranslationConfig.close();
  13660. this.privSpeechRecognitionLanguage = undefined;
  13661. this.privProperties = undefined;
  13662. this.privAudioConfig = undefined;
  13663. this.privSpeechTranslationConfig = undefined;
  13664. this.privConversation.dispose();
  13665. this.privConversation = undefined;
  13666. })(), success, err);
  13667. }
  13668. /**
  13669. * Cancel the speech websocket
  13670. */
  13671. async cancelSpeech() {
  13672. try {
  13673. this.privIsSpeaking = false;
  13674. await this.privCTRecognizer?.onCancelSpeech();
  13675. this.privCTRecognizer = undefined;
  13676. }
  13677. catch (e) {
  13678. // ignore the error
  13679. }
  13680. }
  13681. /**
  13682. * Connect to the speech translation recognizer.
  13683. * Currently there is no language validation performed before sending the SpeechLanguage code to the service.
  13684. * If it's an invalid language the raw error will be: 'Error during WebSocket handshake: Unexpected response code: 400'
  13685. * e.g. pass in 'fr' instead of 'fr-FR', or a text-only language 'cy'
  13686. */
  13687. async connectTranslatorRecognizer() {
  13688. try {
  13689. if (this.privAudioConfig === undefined) {
  13690. this.privAudioConfig = Exports_js_3.AudioConfig.fromDefaultMicrophoneInput();
  13691. }
  13692. // clear the temp subscription key if it's a participant joining
  13693. if (this.privSpeechTranslationConfig.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_Key])
  13694. === this.privPlaceholderKey) {
  13695. this.privSpeechTranslationConfig.setProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_Key], "");
  13696. }
  13697. const convGetter = () => this.privConversation;
  13698. this.privCTRecognizer = new ConversationTranslationRecognizer(this.privSpeechTranslationConfig, this.privAudioConfig, this, convGetter);
  13699. }
  13700. catch (error) {
  13701. await this.cancelSpeech();
  13702. throw error;
  13703. }
  13704. }
  13705. /**
  13706. * Handle the start speaking request
  13707. */
  13708. startContinuousRecognition() {
  13709. return new Promise((resolve, reject) => {
  13710. this.privCTRecognizer.startContinuousRecognitionAsync(resolve, reject);
  13711. });
  13712. }
  13713. }
  13714. exports.ConversationTranslator = ConversationTranslator;
  13715. /***/ }),
  13716. /* 166 */
  13717. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13718. "use strict";
  13719. // Copyright (c) Microsoft Corporation. All rights reserved.
  13720. // Licensed under the MIT license.
  13721. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13722. exports.ConversationTranslatorConnectionFactory = void 0;
  13723. const Exports_js_1 = __webpack_require__(60);
  13724. const StringUtils_js_1 = __webpack_require__(167);
  13725. const Contracts_js_1 = __webpack_require__(64);
  13726. const Exports_js_2 = __webpack_require__(79);
  13727. const HeaderNames_js_1 = __webpack_require__(54);
  13728. const QueryParameterNames_js_1 = __webpack_require__(136);
  13729. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  13730. const Exports_js_3 = __webpack_require__(2);
  13731. /**
  13732. * Connection factory for the conversation translator. Handles connecting to the regular translator endpoint,
  13733. * as well as the virtual microphone array transcription endpoint
  13734. */
  13735. class ConversationTranslatorConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {
  13736. constructor(convGetter) {
  13737. super();
  13738. Contracts_js_1.Contracts.throwIfNullOrUndefined(convGetter, "convGetter");
  13739. this.privConvGetter = convGetter;
  13740. }
  13741. create(config, authInfo, connectionId) {
  13742. const isVirtMicArrayEndpoint = config.parameters.getProperty("ConversationTranslator_MultiChannelAudio", "").toUpperCase() === "TRUE";
  13743. const convInfo = this.privConvGetter().room;
  13744. const region = convInfo.cognitiveSpeechRegion || config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region, "");
  13745. const replacementValues = {
  13746. hostSuffix: ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region),
  13747. path: ConversationTranslatorConnectionFactory.CTS_VIRT_MIC_PATH,
  13748. region: encodeURIComponent(region)
  13749. };
  13750. replacementValues[QueryParameterNames_js_1.QueryParameterNames.Language] = encodeURIComponent(config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage, ""));
  13751. replacementValues[QueryParameterNames_js_1.QueryParameterNames.CtsMeetingId] = encodeURIComponent(convInfo.roomId);
  13752. replacementValues[QueryParameterNames_js_1.QueryParameterNames.CtsDeviceId] = encodeURIComponent(convInfo.participantId);
  13753. replacementValues[QueryParameterNames_js_1.QueryParameterNames.CtsIsParticipant] = convInfo.isHost ? "" : ("&" + QueryParameterNames_js_1.QueryParameterNames.CtsIsParticipant);
  13754. let endpointUrl = "";
  13755. const queryParams = {};
  13756. const headers = {};
  13757. if (isVirtMicArrayEndpoint) {
  13758. // connecting to the conversation transcription virtual microphone array endpoint
  13759. endpointUrl = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint);
  13760. if (!endpointUrl) {
  13761. const hostName = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, "transcribe.{region}.cts.speech{hostSuffix}");
  13762. endpointUrl = "wss://" + hostName + "{path}";
  13763. }
  13764. // because the region can change during a session, we support being passed a format string which we can then
  13765. // replace with the correct information.
  13766. endpointUrl = StringUtils_js_1.StringUtils.formatString(endpointUrl, replacementValues);
  13767. const parsedUrl = new URL(endpointUrl);
  13768. parsedUrl.searchParams.forEach((val, key) => {
  13769. queryParams[key] = val;
  13770. });
  13771. const connFactory = new Exports_js_3.TranscriberConnectionFactory();
  13772. connFactory.setQueryParams(queryParams, config, endpointUrl);
  13773. // Some query parameters are required for the CTS endpoint, let's explicity set them here
  13774. queryParams[QueryParameterNames_js_1.QueryParameterNames.CtsMeetingId] = replacementValues[QueryParameterNames_js_1.QueryParameterNames.CtsMeetingId];
  13775. queryParams[QueryParameterNames_js_1.QueryParameterNames.CtsDeviceId] = replacementValues[QueryParameterNames_js_1.QueryParameterNames.CtsDeviceId];
  13776. if (!convInfo.isHost) {
  13777. queryParams[QueryParameterNames_js_1.QueryParameterNames.CtsIsParticipant] = ""; // this doesn't have a value so set to an empty string
  13778. }
  13779. if (!(QueryParameterNames_js_1.QueryParameterNames.Format in queryParams)) {
  13780. queryParams[QueryParameterNames_js_1.QueryParameterNames.Format] = "simple";
  13781. }
  13782. parsedUrl.searchParams.forEach((val, key) => {
  13783. parsedUrl.searchParams.set(key, queryParams[key]);
  13784. delete queryParams[key];
  13785. });
  13786. endpointUrl = parsedUrl.toString();
  13787. }
  13788. else {
  13789. // connecting to regular translation endpoint
  13790. const connFactory = new Exports_js_3.TranslationConnectionFactory();
  13791. endpointUrl = connFactory.getEndpointUrl(config, true);
  13792. endpointUrl = StringUtils_js_1.StringUtils.formatString(endpointUrl, replacementValues);
  13793. connFactory.setQueryParams(queryParams, config, endpointUrl);
  13794. }
  13795. headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;
  13796. headers[Exports_js_1.RestConfigBase.configParams.token] = convInfo.token;
  13797. if (!!authInfo.token) {
  13798. headers[authInfo.headerName] = authInfo.token;
  13799. }
  13800. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "").toUpperCase() === "TRUE";
  13801. return Promise.resolve(new Exports_js_1.WebsocketConnection(endpointUrl, queryParams, headers, new Exports_js_3.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId));
  13802. }
  13803. }
  13804. exports.ConversationTranslatorConnectionFactory = ConversationTranslatorConnectionFactory;
  13805. ConversationTranslatorConnectionFactory.CTS_VIRT_MIC_PATH = "/speech/recognition/dynamicaudio";
  13806. /***/ }),
  13807. /* 167 */
  13808. /***/ ((__unused_webpack_module, exports) => {
  13809. "use strict";
  13810. // Copyright (c) Microsoft Corporation. All rights reserved.
  13811. // Licensed under the MIT license.
  13812. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13813. exports.StringUtils = void 0;
  13814. /**
  13815. * String helper functions
  13816. */
  13817. class StringUtils {
  13818. /**
  13819. * Formats a string by replacing the named {keys} in the string with the values contained in the replacement dictionary.
  13820. * @param format The format string that contains the parts to replace surrounded by {}. For example: "wss://{region}.cts.speech.microsoft.com".
  13821. * If your string needs to contain a { or } you can use the {{ and }} escape sequences respectively.
  13822. * @param replacements The dictionary of replacements. If a replacement is not found, it is replaced with an empty string
  13823. * @returns The formatted string. If you pass in a null or undefined format string, an empty string will be returned
  13824. */
  13825. static formatString(format, replacements) {
  13826. if (!format) {
  13827. return "";
  13828. }
  13829. if (!replacements) {
  13830. return format;
  13831. }
  13832. let formatted = "";
  13833. let key = "";
  13834. const appendToFormatted = (str) => {
  13835. formatted += str;
  13836. };
  13837. const appendToKey = (str) => {
  13838. key += str;
  13839. };
  13840. let appendFunc = appendToFormatted;
  13841. for (let i = 0; i < format.length; i++) {
  13842. const c = format[i];
  13843. const next = i + 1 < format.length ? format[i + 1] : "";
  13844. switch (c) {
  13845. case "{":
  13846. if (next === "{") {
  13847. appendFunc("{");
  13848. i++;
  13849. }
  13850. else {
  13851. appendFunc = appendToKey;
  13852. }
  13853. break;
  13854. case "}":
  13855. if (next === "}") {
  13856. appendFunc("}");
  13857. i++;
  13858. }
  13859. else {
  13860. if (replacements.hasOwnProperty(key)) {
  13861. formatted += replacements[key];
  13862. }
  13863. appendFunc = appendToFormatted;
  13864. key = "";
  13865. }
  13866. break;
  13867. default:
  13868. appendFunc(c);
  13869. break;
  13870. }
  13871. }
  13872. return formatted;
  13873. }
  13874. }
  13875. exports.StringUtils = StringUtils;
  13876. /***/ }),
  13877. /* 168 */
  13878. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13879. "use strict";
  13880. // Copyright (c) Microsoft Corporation. All rights reserved.
  13881. // Licensed under the MIT license.
  13882. Object.defineProperty(exports, "__esModule", ({ value: true }));
  13883. exports.ConversationTranscriber = void 0;
  13884. const Exports_js_1 = __webpack_require__(2);
  13885. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  13886. const Exports_js_2 = __webpack_require__(4);
  13887. const Contracts_js_1 = __webpack_require__(64);
  13888. const Exports_js_3 = __webpack_require__(79);
  13889. /**
  13890. * Performs speech recognition with speaker separation from microphone, file, or other audio input streams, and gets transcribed text as result.
  13891. * @class ConversationTranscriber
  13892. */
  13893. class ConversationTranscriber extends Exports_js_3.Recognizer {
  13894. /**
  13895. * ConversationTranscriber constructor.
  13896. * @constructor
  13897. * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer
  13898. * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer
  13899. */
  13900. constructor(speechConfig, audioConfig) {
  13901. const speechConfigImpl = speechConfig;
  13902. Contracts_js_1.Contracts.throwIfNull(speechConfigImpl, "speechConfig");
  13903. Contracts_js_1.Contracts.throwIfNullOrWhitespace(speechConfigImpl.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage), Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage]);
  13904. super(audioConfig, speechConfigImpl.properties, new Exports_js_1.ConversationTranscriberConnectionFactory(), speechConfig.tokenCredential);
  13905. this.privProperties.setProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecognitionEndpointVersion, "2");
  13906. this.privDisposedRecognizer = false;
  13907. }
  13908. /**
  13909. * ConversationTranscriber constructor.
  13910. * @constructor
  13911. * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer
  13912. * @param {AutoDetectSourceLanguageConfig} autoDetectSourceLanguageConfig - An source language detection configuration associated with the recognizer
  13913. * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer
  13914. */
  13915. static FromConfig(speechConfig, autoDetectSourceLanguageConfig, audioConfig) {
  13916. const speechConfigImpl = speechConfig;
  13917. autoDetectSourceLanguageConfig.properties.mergeTo(speechConfigImpl.properties);
  13918. const recognizer = new ConversationTranscriber(speechConfig, audioConfig);
  13919. return recognizer;
  13920. }
  13921. /**
  13922. * Gets the endpoint id of a customized speech model that is used for transcription.
  13923. * @member ConversationTranscriber.prototype.endpointId
  13924. * @function
  13925. * @public
  13926. * @returns {string} the endpoint id of a customized speech model that is used for speech recognition.
  13927. */
  13928. get endpointId() {
  13929. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  13930. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_EndpointId, "00000000-0000-0000-0000-000000000000");
  13931. }
  13932. /**
  13933. * Gets the authorization token used to communicate with the service.
  13934. * @member ConversationTranscriber.prototype.authorizationToken
  13935. * @function
  13936. * @public
  13937. * @returns {string} Authorization token.
  13938. */
  13939. get authorizationToken() {
  13940. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token);
  13941. }
  13942. /**
  13943. * Gets/Sets the authorization token used to communicate with the service.
  13944. * @member ConversationTranscriber.prototype.authorizationToken
  13945. * @function
  13946. * @public
  13947. * @param {string} token - Authorization token.
  13948. */
  13949. set authorizationToken(token) {
  13950. Contracts_js_1.Contracts.throwIfNullOrWhitespace(token, "token");
  13951. this.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, token);
  13952. }
  13953. /**
  13954. * Gets the spoken language of transcription.
  13955. * @member ConversationTranscriber.prototype.speechRecognitionLanguage
  13956. * @function
  13957. * @public
  13958. * @returns {string} The spoken language of transcription.
  13959. */
  13960. get speechRecognitionLanguage() {
  13961. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  13962. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage);
  13963. }
  13964. /**
  13965. * Gets the output format of transcription.
  13966. * @member ConversationTranscriber.prototype.outputFormat
  13967. * @function
  13968. * @public
  13969. * @returns {OutputFormat} The output format of transcription.
  13970. */
  13971. get outputFormat() {
  13972. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  13973. if (this.properties.getProperty(Exports_js_1.OutputFormatPropertyName, Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Simple]) === Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Simple]) {
  13974. return Exports_js_3.OutputFormat.Simple;
  13975. }
  13976. else {
  13977. return Exports_js_3.OutputFormat.Detailed;
  13978. }
  13979. }
  13980. /**
  13981. * The collection of properties and their values defined for this conversation transcriber.
  13982. * @member ConversationTranscriber.prototype.properties
  13983. * @function
  13984. * @public
  13985. * @returns {PropertyCollection} The collection of properties and their values defined for this SpeechRecognizer.
  13986. */
  13987. get properties() {
  13988. return this.privProperties;
  13989. }
  13990. /**
  13991. * Starts conversation transcription, until stopTranscribingAsync() is called.
  13992. * User must subscribe to events to receive transcription results.
  13993. * @member ConversationTranscriber.prototype.startTranscribingAsync
  13994. * @function
  13995. * @public
  13996. * @param cb - Callback invoked once the transcription has started.
  13997. * @param err - Callback invoked in case of an error.
  13998. */
  13999. startTranscribingAsync(cb, err) {
  14000. (0, Exports_js_2.marshalPromiseToCallbacks)(this.startContinuousRecognitionAsyncImpl(PhraseDetectionContext_js_1.RecognitionMode.Conversation), cb, err);
  14001. }
  14002. /**
  14003. * Stops conversation transcription.
  14004. * @member ConversationTranscriber.prototype.stopTranscribingAsync
  14005. * @function
  14006. * @public
  14007. * @param cb - Callback invoked once the transcription has stopped.
  14008. * @param err - Callback invoked in case of an error.
  14009. */
  14010. stopTranscribingAsync(cb, err) {
  14011. (0, Exports_js_2.marshalPromiseToCallbacks)(this.stopContinuousRecognitionAsyncImpl(), cb, err);
  14012. }
  14013. /**
  14014. * closes all external resources held by an instance of this class.
  14015. * @member ConversationTranscriber.prototype.close
  14016. * @function
  14017. * @public
  14018. */
  14019. close(cb, errorCb) {
  14020. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  14021. (0, Exports_js_2.marshalPromiseToCallbacks)(this.dispose(true), cb, errorCb);
  14022. }
  14023. /**
  14024. * Disposes any resources held by the object.
  14025. * @member SpeechRecognizer.prototype.dispose
  14026. * @function
  14027. * @public
  14028. * @param {boolean} disposing - true if disposing the object.
  14029. */
  14030. async dispose(disposing) {
  14031. if (this.privDisposedRecognizer) {
  14032. return;
  14033. }
  14034. if (disposing) {
  14035. this.privDisposedRecognizer = true;
  14036. await this.implRecognizerStop();
  14037. }
  14038. await super.dispose(disposing);
  14039. }
  14040. createRecognizerConfig(speechConfig) {
  14041. return new Exports_js_1.RecognizerConfig(speechConfig, this.privProperties);
  14042. }
  14043. createServiceRecognizer(authentication, connectionFactory, audioConfig, recognizerConfig) {
  14044. const configImpl = audioConfig;
  14045. recognizerConfig.isSpeakerDiarizationEnabled = true;
  14046. return new Exports_js_1.ConversationTranscriptionServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);
  14047. }
  14048. }
  14049. exports.ConversationTranscriber = ConversationTranscriber;
  14050. /***/ }),
  14051. /* 169 */
  14052. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  14053. "use strict";
  14054. // Copyright (c) Microsoft Corporation. All rights reserved.
  14055. // Licensed under the MIT license.
  14056. // Multi-device Conversation is a Preview feature.
  14057. Object.defineProperty(exports, "__esModule", ({ value: true }));
  14058. exports.Participant = exports.User = void 0;
  14059. /* eslint-disable max-classes-per-file */
  14060. const Exports_js_1 = __webpack_require__(79);
  14061. class User {
  14062. constructor(userId) {
  14063. this.privUserId = userId;
  14064. }
  14065. get userId() {
  14066. return this.privUserId;
  14067. }
  14068. }
  14069. exports.User = User;
  14070. class Participant {
  14071. constructor(id, avatar, displayName, isHost, isMuted, isUsingTts, preferredLanguage, voice) {
  14072. this.privId = id;
  14073. this.privAvatar = avatar;
  14074. this.privDisplayName = displayName;
  14075. this.privIsHost = isHost;
  14076. this.privIsMuted = isMuted;
  14077. this.privIsUsingTts = isUsingTts;
  14078. this.privPreferredLanguage = preferredLanguage;
  14079. this.privVoice = voice;
  14080. this.privProperties = new Exports_js_1.PropertyCollection();
  14081. }
  14082. get avatar() {
  14083. return this.privAvatar;
  14084. }
  14085. get displayName() {
  14086. return this.privDisplayName;
  14087. }
  14088. get id() {
  14089. return this.privId;
  14090. }
  14091. get preferredLanguage() {
  14092. return this.privPreferredLanguage;
  14093. }
  14094. get isHost() {
  14095. return this.privIsHost;
  14096. }
  14097. get isMuted() {
  14098. return this.privIsMuted;
  14099. }
  14100. get isUsingTts() {
  14101. return this.privIsUsingTts;
  14102. }
  14103. get voice() {
  14104. return this.privVoice;
  14105. }
  14106. get properties() {
  14107. return this.privProperties;
  14108. }
  14109. static From(id, language, voice) {
  14110. return new Participant(id, "", id, false, false, false, language, voice);
  14111. }
  14112. }
  14113. exports.Participant = Participant;
  14114. /***/ }),
  14115. /* 170 */
  14116. /***/ ((__unused_webpack_module, exports) => {
  14117. "use strict";
  14118. // Copyright (c) Microsoft Corporation. All rights reserved.
  14119. // Licensed under the MIT license.
  14120. // Multi-device Conversation is a Preview feature.
  14121. Object.defineProperty(exports, "__esModule", ({ value: true }));
  14122. exports.ParticipantChangedReason = void 0;
  14123. var ParticipantChangedReason;
  14124. (function (ParticipantChangedReason) {
  14125. /** Participant has joined the conversation. */
  14126. ParticipantChangedReason[ParticipantChangedReason["JoinedConversation"] = 0] = "JoinedConversation";
  14127. /** Participant has left the conversation. This could be voluntary, or involuntary
  14128. * (e.g. they are experiencing networking issues).
  14129. */
  14130. ParticipantChangedReason[ParticipantChangedReason["LeftConversation"] = 1] = "LeftConversation";
  14131. /** The participants' state has changed (e.g. they became muted, changed their nickname). */
  14132. ParticipantChangedReason[ParticipantChangedReason["Updated"] = 2] = "Updated";
  14133. })(ParticipantChangedReason = exports.ParticipantChangedReason || (exports.ParticipantChangedReason = {}));
  14134. /***/ }),
  14135. /* 171 */
  14136. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  14137. "use strict";
  14138. // Copyright (c) Microsoft Corporation. All rights reserved.
  14139. // Licensed under the MIT license.
  14140. // Multi-device Conversation is a Preview feature.
  14141. Object.defineProperty(exports, "__esModule", ({ value: true }));
  14142. exports.MeetingImpl = exports.Meeting = void 0;
  14143. /* eslint-disable max-classes-per-file */
  14144. const Exports_js_1 = __webpack_require__(2);
  14145. const Exports_js_2 = __webpack_require__(4);
  14146. const Contracts_js_1 = __webpack_require__(64);
  14147. const Exports_js_3 = __webpack_require__(79);
  14148. class Meeting {
  14149. constructor() {
  14150. return;
  14151. }
  14152. /**
  14153. * Create a meeting
  14154. * @param speechConfig
  14155. * @param meetingId
  14156. * @param cb
  14157. * @param err
  14158. */
  14159. static createMeetingAsync(speechConfig, meetingId, arg3, arg4) {
  14160. Contracts_js_1.Contracts.throwIfNullOrUndefined(speechConfig, Exports_js_1.ConversationConnectionConfig.restErrors.invalidArgs.replace("{arg}", "config"));
  14161. Contracts_js_1.Contracts.throwIfNullOrUndefined(speechConfig.region, Exports_js_1.ConversationConnectionConfig.restErrors.invalidArgs.replace("{arg}", "SpeechServiceConnection_Region"));
  14162. Contracts_js_1.Contracts.throwIfNull(meetingId, "meetingId");
  14163. if (meetingId.length === 0) {
  14164. throw new Error("meetingId cannot be empty");
  14165. }
  14166. if (!speechConfig.subscriptionKey && !speechConfig.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceAuthorization_Token])) {
  14167. Contracts_js_1.Contracts.throwIfNullOrUndefined(speechConfig.subscriptionKey, Exports_js_1.ConversationConnectionConfig.restErrors.invalidArgs.replace("{arg}", "SpeechServiceConnection_Key"));
  14168. }
  14169. const meetingImpl = new MeetingImpl(speechConfig, meetingId);
  14170. // eslint-disable-next-line @typescript-eslint/no-empty-function
  14171. (0, Exports_js_2.marshalPromiseToCallbacks)((async () => { })(), arg3, arg4);
  14172. return meetingImpl;
  14173. }
  14174. }
  14175. exports.Meeting = Meeting;
  14176. class MeetingImpl extends Meeting {
  14177. /**
  14178. * Create a Meeting impl
  14179. * @param speechConfig
  14180. * @param {string} id - optional conversationId
  14181. */
  14182. constructor(speechConfig, id) {
  14183. super();
  14184. this.privErrors = Exports_js_1.ConversationConnectionConfig.restErrors;
  14185. /** websocket callbacks */
  14186. /* eslint-disable @typescript-eslint/typedef */
  14187. this.onConnected = (e) => {
  14188. this.privIsConnected = true;
  14189. try {
  14190. if (!!this.privConversationTranslator?.sessionStarted) {
  14191. this.privConversationTranslator.sessionStarted(this.privConversationTranslator, e);
  14192. }
  14193. }
  14194. catch (e) {
  14195. //
  14196. }
  14197. };
  14198. this.onDisconnected = (e) => {
  14199. try {
  14200. if (!!this.privConversationTranslator?.sessionStopped) {
  14201. this.privConversationTranslator.sessionStopped(this.privConversationTranslator, e);
  14202. }
  14203. }
  14204. catch (e) {
  14205. //
  14206. }
  14207. finally {
  14208. void this.close(false);
  14209. }
  14210. };
  14211. this.onCanceled = (r, e) => {
  14212. try {
  14213. if (!!this.privConversationTranslator?.canceled) {
  14214. this.privConversationTranslator.canceled(this.privConversationTranslator, e);
  14215. }
  14216. }
  14217. catch (e) {
  14218. //
  14219. }
  14220. };
  14221. this.onParticipantUpdateCommandReceived = (r, e) => {
  14222. try {
  14223. const updatedParticipant = this.privParticipants.getParticipant(e.id);
  14224. if (updatedParticipant !== undefined) {
  14225. switch (e.key) {
  14226. case Exports_js_1.ConversationTranslatorCommandTypes.changeNickname:
  14227. updatedParticipant.displayName = e.value;
  14228. break;
  14229. case Exports_js_1.ConversationTranslatorCommandTypes.setUseTTS:
  14230. updatedParticipant.isUsingTts = e.value;
  14231. break;
  14232. case Exports_js_1.ConversationTranslatorCommandTypes.setProfanityFiltering:
  14233. updatedParticipant.profanity = e.value;
  14234. break;
  14235. case Exports_js_1.ConversationTranslatorCommandTypes.setMute:
  14236. updatedParticipant.isMuted = e.value;
  14237. break;
  14238. case Exports_js_1.ConversationTranslatorCommandTypes.setTranslateToLanguages:
  14239. updatedParticipant.translateToLanguages = e.value;
  14240. break;
  14241. }
  14242. this.privParticipants.addOrUpdateParticipant(updatedParticipant);
  14243. if (!!this.privConversationTranslator) {
  14244. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.Updated, [this.toParticipant(updatedParticipant)], e.sessionId));
  14245. }
  14246. }
  14247. }
  14248. catch (e) {
  14249. //
  14250. }
  14251. };
  14252. this.onLockRoomCommandReceived = () => {
  14253. // TODO
  14254. };
  14255. this.onMuteAllCommandReceived = (r, e) => {
  14256. try {
  14257. this.privParticipants.participants.forEach((p) => p.isMuted = (p.isHost ? false : e.isMuted));
  14258. if (!!this.privConversationTranslator) {
  14259. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.Updated, this.toParticipants(false), e.sessionId));
  14260. }
  14261. }
  14262. catch (e) {
  14263. //
  14264. }
  14265. };
  14266. this.onParticipantJoinCommandReceived = (r, e) => {
  14267. try {
  14268. const newParticipant = this.privParticipants.addOrUpdateParticipant(e.participant);
  14269. if (newParticipant !== undefined) {
  14270. if (!!this.privConversationTranslator) {
  14271. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.JoinedConversation, [this.toParticipant(newParticipant)], e.sessionId));
  14272. }
  14273. }
  14274. }
  14275. catch (e) {
  14276. //
  14277. }
  14278. };
  14279. this.onParticipantLeaveCommandReceived = (r, e) => {
  14280. try {
  14281. const ejectedParticipant = this.privParticipants.getParticipant(e.participant.id);
  14282. if (ejectedParticipant !== undefined) {
  14283. // remove the participant from the internal participants list
  14284. this.privParticipants.deleteParticipant(e.participant.id);
  14285. if (!!this.privConversationTranslator) {
  14286. // notify subscribers that the participant has left the conversation
  14287. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.LeftConversation, [this.toParticipant(ejectedParticipant)], e.sessionId));
  14288. }
  14289. }
  14290. }
  14291. catch (e) {
  14292. //
  14293. }
  14294. };
  14295. this.onTranslationReceived = (r, e) => {
  14296. try {
  14297. switch (e.command) {
  14298. case Exports_js_1.ConversationTranslatorMessageTypes.final:
  14299. if (!!this.privConversationTranslator) {
  14300. this.privConversationTranslator.transcribed(this.privConversationTranslator, new Exports_js_3.ConversationTranslationEventArgs(e.payload, undefined, e.sessionId));
  14301. }
  14302. break;
  14303. case Exports_js_1.ConversationTranslatorMessageTypes.partial:
  14304. if (!!this.privConversationTranslator) {
  14305. this.privConversationTranslator.transcribing(this.privConversationTranslator, new Exports_js_3.ConversationTranslationEventArgs(e.payload, undefined, e.sessionId));
  14306. }
  14307. break;
  14308. case Exports_js_1.ConversationTranslatorMessageTypes.instantMessage:
  14309. if (!!this.privConversationTranslator) {
  14310. this.privConversationTranslator.textMessageReceived(this.privConversationTranslator, new Exports_js_3.ConversationTranslationEventArgs(e.payload, undefined, e.sessionId));
  14311. }
  14312. break;
  14313. }
  14314. }
  14315. catch (e) {
  14316. //
  14317. }
  14318. };
  14319. this.onParticipantsListReceived = (r, e) => {
  14320. try {
  14321. // check if the session token needs to be updated
  14322. if (e.sessionToken !== undefined && e.sessionToken !== null) {
  14323. this.privRoom.token = e.sessionToken;
  14324. }
  14325. // save the participants
  14326. this.privParticipants.participants = [...e.participants];
  14327. // enable the conversation
  14328. if (this.privParticipants.me !== undefined) {
  14329. this.privIsReady = true;
  14330. }
  14331. if (!!this.privConversationTranslator) {
  14332. this.privConversationTranslator.participantsChanged(this.privConversationTranslator, new Exports_js_3.ConversationParticipantsChangedEventArgs(Exports_js_3.ParticipantChangedReason.JoinedConversation, this.toParticipants(true), e.sessionId));
  14333. }
  14334. // if this is the host, update the nickname if needed
  14335. if (this.me.isHost) {
  14336. const nickname = this.privConversationTranslator?.properties.getProperty(Exports_js_3.PropertyId.ConversationTranslator_Name);
  14337. if (nickname !== undefined && nickname.length > 0 && nickname !== this.me.displayName) {
  14338. // issue a change nickname request
  14339. this.changeNicknameAsync(nickname);
  14340. }
  14341. }
  14342. }
  14343. catch (e) {
  14344. //
  14345. }
  14346. };
  14347. this.onConversationExpiration = (r, e) => {
  14348. try {
  14349. if (!!this.privConversationTranslator) {
  14350. this.privConversationTranslator.conversationExpiration(this.privConversationTranslator, e);
  14351. }
  14352. }
  14353. catch (e) {
  14354. //
  14355. }
  14356. };
  14357. this.privIsConnected = false;
  14358. this.privIsDisposed = false;
  14359. this.privConversationId = "";
  14360. this.privProperties = new Exports_js_3.PropertyCollection();
  14361. this.privManager = new Exports_js_1.ConversationManager();
  14362. // check the speech language
  14363. const language = speechConfig.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage]);
  14364. if (!language) {
  14365. speechConfig.setProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage], Exports_js_1.ConversationConnectionConfig.defaultLanguageCode);
  14366. }
  14367. this.privLanguage = speechConfig.getProperty(Exports_js_3.PropertyId[Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage]);
  14368. this.privConversationId = id;
  14369. // save the speech config for future usage
  14370. this.privConfig = speechConfig;
  14371. // save the config properties
  14372. const configImpl = speechConfig;
  14373. Contracts_js_1.Contracts.throwIfNull(configImpl, "speechConfig");
  14374. this.privProperties = configImpl.properties.clone();
  14375. this.privIsConnected = false;
  14376. this.privParticipants = new Exports_js_1.InternalParticipants();
  14377. this.privIsReady = false;
  14378. this.privTextMessageMaxLength = 1000;
  14379. }
  14380. // get the internal data about a conversation
  14381. get room() {
  14382. return this.privRoom;
  14383. }
  14384. // get the wrapper for connecting to the websockets
  14385. get connection() {
  14386. return this.privConversationRecognizer; // this.privConnection;
  14387. }
  14388. // get the config
  14389. get config() {
  14390. return this.privConfig;
  14391. }
  14392. // get the meeting Id
  14393. get meetingId() {
  14394. return this.privRoom ? this.privRoom.roomId : this.privConversationId;
  14395. }
  14396. // get the properties
  14397. get properties() {
  14398. return this.privProperties;
  14399. }
  14400. // get the speech language
  14401. get speechRecognitionLanguage() {
  14402. return this.privLanguage;
  14403. }
  14404. get isMutedByHost() {
  14405. return this.privParticipants.me?.isHost ? false : this.privParticipants.me?.isMuted;
  14406. }
  14407. get isConnected() {
  14408. return this.privIsConnected && this.privIsReady;
  14409. }
  14410. get participants() {
  14411. return this.toParticipants(true);
  14412. }
  14413. get me() {
  14414. return this.toParticipant(this.privParticipants.me);
  14415. }
  14416. get host() {
  14417. return this.toParticipant(this.privParticipants.host);
  14418. }
  14419. get transcriberRecognizer() {
  14420. return this.privTranscriberRecognizer;
  14421. }
  14422. get meetingInfo() {
  14423. const convId = this.meetingId;
  14424. const p = this.participants.map((part) => ({
  14425. id: part.id,
  14426. preferredLanguage: part.preferredLanguage,
  14427. voice: part.voice
  14428. }));
  14429. const props = {};
  14430. for (const key of Exports_js_1.ConversationConnectionConfig.transcriptionEventKeys) {
  14431. const val = this.properties.getProperty(key, "");
  14432. if (val !== "") {
  14433. props[key] = val;
  14434. }
  14435. }
  14436. const info = { id: convId, participants: p, meetingProperties: props };
  14437. return info;
  14438. }
  14439. get canSend() {
  14440. return this.privIsConnected && !this.privParticipants.me?.isMuted;
  14441. }
  14442. get canSendAsHost() {
  14443. return this.privIsConnected && this.privParticipants.me?.isHost;
  14444. }
  14445. // get / set the speech auth token
  14446. // eslint-disable-next-line @typescript-eslint/member-ordering
  14447. get authorizationToken() {
  14448. return this.privToken;
  14449. }
  14450. set authorizationToken(value) {
  14451. Contracts_js_1.Contracts.throwIfNullOrWhitespace(value, "authorizationToken");
  14452. this.privToken = value;
  14453. }
  14454. /**
  14455. * Create a new meeting as Host
  14456. * @param cb
  14457. * @param err
  14458. */
  14459. createMeetingAsync(cb, err) {
  14460. try {
  14461. if (!!this.privConversationRecognizer) {
  14462. this.handleError(new Error(this.privErrors.permissionDeniedStart), err);
  14463. }
  14464. this.privManager.createOrJoin(this.privProperties, undefined, ((room) => {
  14465. if (!room) {
  14466. this.handleError(new Error(this.privErrors.permissionDeniedConnect), err);
  14467. }
  14468. this.privRoom = room;
  14469. this.handleCallback(cb, err);
  14470. }), ((error) => {
  14471. this.handleError(error, err);
  14472. }));
  14473. }
  14474. catch (error) {
  14475. this.handleError(error, err);
  14476. }
  14477. }
  14478. /**
  14479. * Starts a new meeting as host.
  14480. * @param cb
  14481. * @param err
  14482. */
  14483. startMeetingAsync(cb, err) {
  14484. try {
  14485. // check if there is already a recognizer
  14486. if (!!this.privConversationRecognizer) {
  14487. this.handleError(new Error(this.privErrors.permissionDeniedStart), err);
  14488. }
  14489. // check if there is conversation data available
  14490. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedConnect);
  14491. // connect to the conversation websocket
  14492. this.privParticipants.meId = this.privRoom.participantId;
  14493. // Because ConversationTranslator manually sets up and manages the connection, Conversation
  14494. // has to forward serviceRecognizer connection events that usually get passed automatically
  14495. this.privConversationRecognizer.connected = this.onConnected;
  14496. this.privConversationRecognizer.disconnected = this.onDisconnected;
  14497. this.privConversationRecognizer.canceled = this.onCanceled;
  14498. this.privConversationRecognizer.participantUpdateCommandReceived = this.onParticipantUpdateCommandReceived;
  14499. this.privConversationRecognizer.lockRoomCommandReceived = this.onLockRoomCommandReceived;
  14500. this.privConversationRecognizer.muteAllCommandReceived = this.onMuteAllCommandReceived;
  14501. this.privConversationRecognizer.participantJoinCommandReceived = this.onParticipantJoinCommandReceived;
  14502. this.privConversationRecognizer.participantLeaveCommandReceived = this.onParticipantLeaveCommandReceived;
  14503. this.privConversationRecognizer.translationReceived = this.onTranslationReceived;
  14504. this.privConversationRecognizer.participantsListReceived = this.onParticipantsListReceived;
  14505. this.privConversationRecognizer.conversationExpiration = this.onConversationExpiration;
  14506. this.privConversationRecognizer.connect(this.privRoom.token, (() => {
  14507. this.handleCallback(cb, err);
  14508. }), ((error) => {
  14509. this.handleError(error, err);
  14510. }));
  14511. }
  14512. catch (error) {
  14513. this.handleError(error, err);
  14514. }
  14515. }
  14516. /**
  14517. * Join a meeting as a participant.
  14518. * @param { IParticipant } participant - participant to add
  14519. * @param cb
  14520. * @param err
  14521. */
  14522. addParticipantAsync(participant, cb, err) {
  14523. Contracts_js_1.Contracts.throwIfNullOrUndefined(participant, "Participant");
  14524. (0, Exports_js_2.marshalPromiseToCallbacks)(this.addParticipantImplAsync(participant), cb, err);
  14525. }
  14526. /**
  14527. * Join a meeting as a participant.
  14528. * @param meeting
  14529. * @param nickname
  14530. * @param lang
  14531. * @param cb
  14532. * @param err
  14533. */
  14534. joinMeetingAsync(meetingId, nickname, lang, cb, err) {
  14535. try {
  14536. // TODO
  14537. // if (!!this.privConversationRecognizer) {
  14538. // throw new Error(this.privErrors.permissionDeniedStart);
  14539. // }
  14540. Contracts_js_1.Contracts.throwIfNullOrWhitespace(meetingId, this.privErrors.invalidArgs.replace("{arg}", "conversationId"));
  14541. Contracts_js_1.Contracts.throwIfNullOrWhitespace(nickname, this.privErrors.invalidArgs.replace("{arg}", "nickname"));
  14542. Contracts_js_1.Contracts.throwIfNullOrWhitespace(lang, this.privErrors.invalidArgs.replace("{arg}", "language"));
  14543. // join the conversation
  14544. this.privManager.createOrJoin(this.privProperties, meetingId, ((room) => {
  14545. Contracts_js_1.Contracts.throwIfNullOrUndefined(room, this.privErrors.permissionDeniedConnect);
  14546. this.privRoom = room;
  14547. this.privConfig.authorizationToken = room.cognitiveSpeechAuthToken;
  14548. // join callback
  14549. if (!!cb) {
  14550. cb(room.cognitiveSpeechAuthToken);
  14551. }
  14552. }), ((error) => {
  14553. this.handleError(error, err);
  14554. }));
  14555. }
  14556. catch (error) {
  14557. this.handleError(error, err);
  14558. }
  14559. }
  14560. /**
  14561. * Deletes a meeting
  14562. * @param cb
  14563. * @param err
  14564. */
  14565. deleteMeetingAsync(cb, err) {
  14566. (0, Exports_js_2.marshalPromiseToCallbacks)(this.deleteMeetingImplAsync(), cb, err);
  14567. }
  14568. async deleteMeetingImplAsync() {
  14569. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privProperties, this.privErrors.permissionDeniedConnect);
  14570. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.token, this.privErrors.permissionDeniedConnect);
  14571. await this.privManager.leave(this.privProperties, this.privRoom.token);
  14572. this.dispose();
  14573. }
  14574. /**
  14575. * Issues a request to close the client websockets
  14576. * @param cb
  14577. * @param err
  14578. */
  14579. endMeetingAsync(cb, err) {
  14580. (0, Exports_js_2.marshalPromiseToCallbacks)(this.endMeetingImplAsync(), cb, err);
  14581. }
  14582. endMeetingImplAsync() {
  14583. return this.close(true);
  14584. }
  14585. /**
  14586. * Issues a request to lock the conversation
  14587. * @param cb
  14588. * @param err
  14589. */
  14590. lockMeetingAsync(cb, err) {
  14591. try {
  14592. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14593. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14594. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14595. if (!this.canSendAsHost) {
  14596. this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}", "lock")), err);
  14597. }
  14598. if (!!this.privConversationRecognizer) {
  14599. this.privConversationRecognizer.sendRequest(this.getLockCommand(true), (() => {
  14600. this.handleCallback(cb, err);
  14601. }), ((error) => {
  14602. this.handleError(error, err);
  14603. }));
  14604. }
  14605. }
  14606. catch (error) {
  14607. this.handleError(error, err);
  14608. }
  14609. }
  14610. /**
  14611. * Issues a request to mute the meeting
  14612. * @param cb
  14613. * @param err
  14614. */
  14615. muteAllParticipantsAsync(cb, err) {
  14616. try {
  14617. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14618. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14619. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privConversationRecognizer, this.privErrors.permissionDeniedSend);
  14620. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14621. // check the user's permissions
  14622. if (!this.canSendAsHost) {
  14623. this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}", "mute")), err);
  14624. }
  14625. if (!!this.privConversationRecognizer) {
  14626. this.privConversationRecognizer.sendRequest(this.getMuteAllCommand(true), (() => {
  14627. this.handleCallback(cb, err);
  14628. }), ((error) => {
  14629. this.handleError(error, err);
  14630. }));
  14631. }
  14632. }
  14633. catch (error) {
  14634. this.handleError(error, err);
  14635. }
  14636. }
  14637. /**
  14638. * Issues a request to mute a participant in the meeting
  14639. * @param userId
  14640. * @param cb
  14641. * @param err
  14642. */
  14643. muteParticipantAsync(userId, cb, err) {
  14644. try {
  14645. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14646. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14647. Contracts_js_1.Contracts.throwIfNullOrWhitespace(userId, this.privErrors.invalidArgs.replace("{arg}", "userId"));
  14648. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14649. // check the connection is open (host + participant can perform the mute command)
  14650. if (!this.canSend) {
  14651. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  14652. }
  14653. // if not host, check the participant is not muting another participant
  14654. if (!this.me.isHost && this.me.id !== userId) {
  14655. this.handleError(new Error(this.privErrors.permissionDeniedParticipant.replace("{command}", "mute")), err);
  14656. }
  14657. // check the user exists
  14658. const exists = this.privParticipants.getParticipantIndex(userId);
  14659. if (exists === -1) {
  14660. this.handleError(new Error(this.privErrors.invalidParticipantRequest), err);
  14661. }
  14662. if (!!this.privConversationRecognizer) {
  14663. this.privConversationRecognizer.sendRequest(this.getMuteCommand(userId, true), (() => {
  14664. this.handleCallback(cb, err);
  14665. }), ((error) => {
  14666. this.handleError(error, err);
  14667. }));
  14668. }
  14669. }
  14670. catch (error) {
  14671. this.handleError(error, err);
  14672. }
  14673. }
  14674. /**
  14675. * Issues a request to remove a participant from the conversation
  14676. * @param userId
  14677. * @param cb
  14678. * @param err
  14679. */
  14680. removeParticipantAsync(userId, cb, err) {
  14681. try {
  14682. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14683. if (!!this.privTranscriberRecognizer && userId.hasOwnProperty("id")) {
  14684. // Assume this is a transcription participant
  14685. (0, Exports_js_2.marshalPromiseToCallbacks)(this.removeParticipantImplAsync(userId), cb, err);
  14686. }
  14687. else {
  14688. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14689. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14690. if (!this.canSendAsHost) {
  14691. this.handleError(new Error(this.privErrors.permissionDeniedParticipant.replace("{command}", "remove")), err);
  14692. }
  14693. let participantId = "";
  14694. if (typeof userId === "string") {
  14695. participantId = userId;
  14696. }
  14697. else if (userId.hasOwnProperty("id")) {
  14698. const participant = userId;
  14699. participantId = participant.id;
  14700. }
  14701. else if (userId.hasOwnProperty("userId")) {
  14702. const user = userId;
  14703. participantId = user.userId;
  14704. }
  14705. Contracts_js_1.Contracts.throwIfNullOrWhitespace(participantId, this.privErrors.invalidArgs.replace("{arg}", "userId"));
  14706. // check the participant exists
  14707. const index = this.participants.findIndex((p) => p.id === participantId);
  14708. if (index === -1) {
  14709. this.handleError(new Error(this.privErrors.invalidParticipantRequest), err);
  14710. }
  14711. if (!!this.privConversationRecognizer) {
  14712. this.privConversationRecognizer.sendRequest(this.getEjectCommand(participantId), (() => {
  14713. this.handleCallback(cb, err);
  14714. }), ((error) => {
  14715. this.handleError(error, err);
  14716. }));
  14717. }
  14718. }
  14719. }
  14720. catch (error) {
  14721. this.handleError(error, err);
  14722. }
  14723. }
  14724. /**
  14725. * Issues a request to unlock the meeting
  14726. * @param cb
  14727. * @param err
  14728. */
  14729. unlockMeetingAsync(cb, err) {
  14730. try {
  14731. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14732. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14733. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14734. if (!this.canSendAsHost) {
  14735. this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}", "unlock")), err);
  14736. }
  14737. if (!!this.privConversationRecognizer) {
  14738. this.privConversationRecognizer.sendRequest(this.getLockCommand(false), (() => {
  14739. this.handleCallback(cb, err);
  14740. }), ((error) => {
  14741. this.handleError(error, err);
  14742. }));
  14743. }
  14744. }
  14745. catch (error) {
  14746. this.handleError(error, err);
  14747. }
  14748. }
  14749. /**
  14750. * Issues a request to unmute all participants in the meeting
  14751. * @param cb
  14752. * @param err
  14753. */
  14754. unmuteAllParticipantsAsync(cb, err) {
  14755. try {
  14756. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14757. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14758. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14759. if (!this.canSendAsHost) {
  14760. this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}", "unmute all")), err);
  14761. }
  14762. if (!!this.privConversationRecognizer) {
  14763. this.privConversationRecognizer.sendRequest(this.getMuteAllCommand(false), (() => {
  14764. this.handleCallback(cb, err);
  14765. }), ((error) => {
  14766. this.handleError(error, err);
  14767. }));
  14768. }
  14769. }
  14770. catch (error) {
  14771. this.handleError(error, err);
  14772. }
  14773. }
  14774. /**
  14775. * Issues a request to unmute a participant in the meeting
  14776. * @param userId
  14777. * @param cb
  14778. * @param err
  14779. */
  14780. unmuteParticipantAsync(userId, cb, err) {
  14781. try {
  14782. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14783. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14784. Contracts_js_1.Contracts.throwIfNullOrWhitespace(userId, this.privErrors.invalidArgs.replace("{arg}", "userId"));
  14785. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14786. // check the connection is open (host + participant can perform the mute command)
  14787. if (!this.canSend) {
  14788. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  14789. }
  14790. // if not host, check the participant is not muting another participant
  14791. if (!this.me.isHost && this.me.id !== userId) {
  14792. this.handleError(new Error(this.privErrors.permissionDeniedParticipant.replace("{command}", "mute")), err);
  14793. }
  14794. // check the user exists
  14795. const exists = this.privParticipants.getParticipantIndex(userId);
  14796. if (exists === -1) {
  14797. this.handleError(new Error(this.privErrors.invalidParticipantRequest), err);
  14798. }
  14799. if (!!this.privConversationRecognizer) {
  14800. this.privConversationRecognizer.sendRequest(this.getMuteCommand(userId, false), (() => {
  14801. this.handleCallback(cb, err);
  14802. }), ((error) => {
  14803. this.handleError(error, err);
  14804. }));
  14805. }
  14806. }
  14807. catch (error) {
  14808. this.handleError(error, err);
  14809. }
  14810. }
  14811. /**
  14812. * Send a text message
  14813. * @param message
  14814. * @param cb
  14815. * @param err
  14816. */
  14817. sendTextMessageAsync(message, cb, err) {
  14818. try {
  14819. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14820. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14821. Contracts_js_1.Contracts.throwIfNullOrWhitespace(message, this.privErrors.invalidArgs.replace("{arg}", "message"));
  14822. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14823. if (!this.canSend) {
  14824. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  14825. }
  14826. // TODO: is a max length check required?
  14827. if (message.length > this.privTextMessageMaxLength) {
  14828. this.handleError(new Error(this.privErrors.invalidArgs.replace("{arg}", "message length")), err);
  14829. }
  14830. if (!!this.privConversationRecognizer) {
  14831. this.privConversationRecognizer.sendRequest(this.getMessageCommand(message), (() => {
  14832. this.handleCallback(cb, err);
  14833. }), ((error) => {
  14834. this.handleError(error, err);
  14835. }));
  14836. }
  14837. }
  14838. catch (error) {
  14839. this.handleError(error, err);
  14840. }
  14841. }
  14842. /**
  14843. * Set translated to languages
  14844. * @param {string[]} languages - languages to translate to
  14845. * @param cb
  14846. * @param err
  14847. */
  14848. setTranslatedLanguagesAsync(languages, cb, err) {
  14849. try {
  14850. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14851. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14852. Contracts_js_1.Contracts.throwIfArrayEmptyOrWhitespace(languages, this.privErrors.invalidArgs.replace("{arg}", "languages"));
  14853. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14854. if (!this.canSend) {
  14855. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  14856. }
  14857. if (!!this.privConversationRecognizer) {
  14858. this.privConversationRecognizer.sendRequest(this.getSetTranslateToLanguagesCommand(languages), (() => {
  14859. this.handleCallback(cb, err);
  14860. }), ((error) => {
  14861. this.handleError(error, err);
  14862. }));
  14863. }
  14864. }
  14865. catch (error) {
  14866. this.handleError(error, err);
  14867. }
  14868. }
  14869. /**
  14870. * Change nickname
  14871. * @param {string} nickname - new nickname for the room
  14872. * @param cb
  14873. * @param err
  14874. */
  14875. changeNicknameAsync(nickname, cb, err) {
  14876. try {
  14877. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  14878. Contracts_js_1.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed());
  14879. Contracts_js_1.Contracts.throwIfNullOrWhitespace(nickname, this.privErrors.invalidArgs.replace("{arg}", "nickname"));
  14880. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRoom, this.privErrors.permissionDeniedSend);
  14881. if (!this.canSend) {
  14882. this.handleError(new Error(this.privErrors.permissionDeniedSend), err);
  14883. }
  14884. if (!!this.privConversationRecognizer) {
  14885. this.privConversationRecognizer.sendRequest(this.getChangeNicknameCommand(nickname), (() => {
  14886. this.handleCallback(cb, err);
  14887. }), ((error) => {
  14888. this.handleError(error, err);
  14889. }));
  14890. }
  14891. }
  14892. catch (error) {
  14893. this.handleError(error, err);
  14894. }
  14895. }
  14896. isDisposed() {
  14897. return this.privIsDisposed;
  14898. }
  14899. dispose() {
  14900. if (this.isDisposed) {
  14901. return;
  14902. }
  14903. this.privIsDisposed = true;
  14904. if (!!this.config) {
  14905. this.config.close();
  14906. }
  14907. this.privConfig = undefined;
  14908. this.privLanguage = undefined;
  14909. this.privProperties = undefined;
  14910. this.privRoom = undefined;
  14911. this.privToken = undefined;
  14912. this.privManager = undefined;
  14913. this.privIsConnected = false;
  14914. this.privIsReady = false;
  14915. this.privParticipants = undefined;
  14916. }
  14917. async connectTranscriberRecognizer(recognizer) {
  14918. if (!!this.privTranscriberRecognizer) {
  14919. await this.privTranscriberRecognizer.close();
  14920. }
  14921. await recognizer.enforceAudioGating();
  14922. this.privTranscriberRecognizer = recognizer;
  14923. this.privTranscriberRecognizer.meeting = this;
  14924. }
  14925. getKeepAlive() {
  14926. const nickname = (!!this.me) ? this.me.displayName : "default_nickname";
  14927. return JSON.stringify({
  14928. id: "0",
  14929. nickname,
  14930. participantId: this.privRoom.participantId,
  14931. roomId: this.privRoom.roomId,
  14932. type: Exports_js_1.ConversationTranslatorMessageTypes.keepAlive
  14933. });
  14934. }
  14935. /* eslint-enable @typescript-eslint/typedef */
  14936. addParticipantImplAsync(participant) {
  14937. const newParticipant = this.privParticipants.addOrUpdateParticipant(participant);
  14938. if (newParticipant !== undefined) {
  14939. if (!!this.privTranscriberRecognizer) {
  14940. const meetingInfo = this.meetingInfo;
  14941. meetingInfo.participants = [participant];
  14942. return this.privTranscriberRecognizer.pushMeetingEvent(meetingInfo, "join");
  14943. }
  14944. }
  14945. }
  14946. removeParticipantImplAsync(participant) {
  14947. this.privParticipants.deleteParticipant(participant.id);
  14948. const meetingInfo = this.meetingInfo;
  14949. meetingInfo.participants = [participant];
  14950. return this.privTranscriberRecognizer.pushMeetingEvent(meetingInfo, "leave");
  14951. }
  14952. async close(dispose) {
  14953. try {
  14954. this.privIsConnected = false;
  14955. await this.privConversationRecognizer?.close();
  14956. this.privConversationRecognizer = undefined;
  14957. if (!!this.privConversationTranslator) {
  14958. this.privConversationTranslator.dispose();
  14959. }
  14960. }
  14961. catch (e) {
  14962. // ignore error
  14963. throw e;
  14964. }
  14965. if (dispose) {
  14966. this.dispose();
  14967. }
  14968. }
  14969. /** Helpers */
  14970. handleCallback(cb, err) {
  14971. if (!!cb) {
  14972. try {
  14973. cb();
  14974. }
  14975. catch (e) {
  14976. if (!!err) {
  14977. err(e);
  14978. }
  14979. }
  14980. cb = undefined;
  14981. }
  14982. }
  14983. handleError(error, err) {
  14984. if (!!err) {
  14985. if (error instanceof Error) {
  14986. const typedError = error;
  14987. err(typedError.name + ": " + typedError.message);
  14988. }
  14989. else {
  14990. err(error);
  14991. }
  14992. }
  14993. }
  14994. /** Participant Helpers */
  14995. toParticipants(includeHost) {
  14996. const participants = this.privParticipants.participants.map((p) => (this.toParticipant(p)));
  14997. if (!includeHost) {
  14998. return participants.filter((p) => p.isHost === false);
  14999. }
  15000. else {
  15001. return participants;
  15002. }
  15003. }
  15004. toParticipant(p) {
  15005. return new Exports_js_3.Participant(p.id, p.avatar, p.displayName, p.isHost, p.isMuted, p.isUsingTts, p.preferredLanguage, p.voice);
  15006. }
  15007. getMuteAllCommand(isMuted) {
  15008. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "meetingd");
  15009. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  15010. return JSON.stringify({
  15011. command: Exports_js_1.ConversationTranslatorCommandTypes.setMuteAll,
  15012. participantId: this.privRoom.participantId,
  15013. roomid: this.privRoom.roomId,
  15014. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  15015. value: isMuted
  15016. });
  15017. }
  15018. getMuteCommand(participantId, isMuted) {
  15019. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "conversationId");
  15020. Contracts_js_1.Contracts.throwIfNullOrWhitespace(participantId, "participantId");
  15021. return JSON.stringify({
  15022. command: Exports_js_1.ConversationTranslatorCommandTypes.setMute,
  15023. // eslint-disable-next-line object-shorthand
  15024. participantId: participantId,
  15025. roomid: this.privRoom.roomId,
  15026. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  15027. value: isMuted
  15028. });
  15029. }
  15030. getLockCommand(isLocked) {
  15031. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "meetingId");
  15032. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  15033. return JSON.stringify({
  15034. command: Exports_js_1.ConversationTranslatorCommandTypes.setLockState,
  15035. participantId: this.privRoom.participantId,
  15036. roomid: this.privRoom.roomId,
  15037. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  15038. value: isLocked
  15039. });
  15040. }
  15041. getEjectCommand(participantId) {
  15042. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "meetingId");
  15043. Contracts_js_1.Contracts.throwIfNullOrWhitespace(participantId, "participantId");
  15044. return JSON.stringify({
  15045. command: Exports_js_1.ConversationTranslatorCommandTypes.ejectParticipant,
  15046. // eslint-disable-next-line object-shorthand
  15047. participantId: participantId,
  15048. roomid: this.privRoom.roomId,
  15049. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  15050. });
  15051. }
  15052. getSetTranslateToLanguagesCommand(languages) {
  15053. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "meetingId");
  15054. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  15055. return JSON.stringify({
  15056. command: Exports_js_1.ConversationTranslatorCommandTypes.setTranslateToLanguages,
  15057. participantId: this.privRoom.participantId,
  15058. roomid: this.privRoom.roomId,
  15059. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  15060. value: languages
  15061. });
  15062. }
  15063. getChangeNicknameCommand(nickname) {
  15064. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "meetingId");
  15065. Contracts_js_1.Contracts.throwIfNullOrWhitespace(nickname, "nickname");
  15066. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  15067. return JSON.stringify({
  15068. command: Exports_js_1.ConversationTranslatorCommandTypes.changeNickname,
  15069. nickname,
  15070. participantId: this.privRoom.participantId,
  15071. roomid: this.privRoom.roomId,
  15072. type: Exports_js_1.ConversationTranslatorMessageTypes.participantCommand,
  15073. value: nickname
  15074. });
  15075. }
  15076. getMessageCommand(message) {
  15077. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId, "meetingId");
  15078. Contracts_js_1.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId, "participantId");
  15079. Contracts_js_1.Contracts.throwIfNullOrWhitespace(message, "message");
  15080. return JSON.stringify({
  15081. participantId: this.privRoom.participantId,
  15082. roomId: this.privRoom.roomId,
  15083. text: message,
  15084. type: Exports_js_1.ConversationTranslatorMessageTypes.instantMessage
  15085. });
  15086. }
  15087. }
  15088. exports.MeetingImpl = MeetingImpl;
  15089. /***/ }),
  15090. /* 172 */
  15091. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  15092. "use strict";
  15093. // Copyright (c) Microsoft Corporation. All rights reserved.
  15094. // Licensed under the MIT license.
  15095. // Multi-device Conversation is a Preview feature.
  15096. Object.defineProperty(exports, "__esModule", ({ value: true }));
  15097. exports.MeetingTranscriptionCanceledEventArgs = void 0;
  15098. const CancellationEventArgsBase_js_1 = __webpack_require__(101);
  15099. class MeetingTranscriptionCanceledEventArgs extends CancellationEventArgsBase_js_1.CancellationEventArgsBase {
  15100. }
  15101. exports.MeetingTranscriptionCanceledEventArgs = MeetingTranscriptionCanceledEventArgs;
  15102. /***/ }),
  15103. /* 173 */
  15104. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  15105. "use strict";
  15106. // Copyright (c) Microsoft Corporation. All rights reserved.
  15107. // Licensed under the MIT license.
  15108. Object.defineProperty(exports, "__esModule", ({ value: true }));
  15109. exports.MeetingTranscriber = void 0;
  15110. const Exports_js_1 = __webpack_require__(2);
  15111. const Exports_js_2 = __webpack_require__(4);
  15112. const Contracts_js_1 = __webpack_require__(64);
  15113. const Exports_js_3 = __webpack_require__(79);
  15114. const Exports_js_4 = __webpack_require__(157);
  15115. class MeetingTranscriber {
  15116. /**
  15117. * MeetingTranscriber constructor.
  15118. * @constructor
  15119. * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer
  15120. */
  15121. constructor(audioConfig) {
  15122. this.privAudioConfig = audioConfig;
  15123. this.privProperties = new Exports_js_3.PropertyCollection();
  15124. this.privRecognizer = undefined;
  15125. this.privDisposedRecognizer = false;
  15126. }
  15127. /**
  15128. * Gets the spoken language of recognition.
  15129. * @member MeetingTranscriber.prototype.speechRecognitionLanguage
  15130. * @function
  15131. * @public
  15132. * @returns {string} The spoken language of recognition.
  15133. */
  15134. get speechRecognitionLanguage() {
  15135. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  15136. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage);
  15137. }
  15138. /**
  15139. * The collection of properties and their values defined for this MeetingTranscriber.
  15140. * @member MeetingTranscriber.prototype.properties
  15141. * @function
  15142. * @public
  15143. * @returns {PropertyCollection} The collection of properties and their values defined for this MeetingTranscriber.
  15144. */
  15145. get properties() {
  15146. return this.privProperties;
  15147. }
  15148. /**
  15149. * @Internal
  15150. * Internal data member to support fromRecognizer* pattern methods on other classes.
  15151. * Do not use externally, object returned will change without warning or notice.
  15152. */
  15153. get internalData() {
  15154. return this.privRecognizer.internalData;
  15155. }
  15156. /**
  15157. * @Deprecated
  15158. * @Obsolete
  15159. * Please use the Connection.fromRecognizer pattern to obtain a connection object
  15160. */
  15161. get connection() {
  15162. return Exports_js_3.Connection.fromRecognizer(this.privRecognizer);
  15163. }
  15164. /**
  15165. * Gets the authorization token used to communicate with the service.
  15166. * @member MeetingTranscriber.prototype.authorizationToken
  15167. * @function
  15168. * @public
  15169. * @returns {string} Authorization token.
  15170. */
  15171. get authorizationToken() {
  15172. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token);
  15173. }
  15174. /**
  15175. * Gets/Sets the authorization token used to communicate with the service.
  15176. * @member MeetingTranscriber.prototype.authorizationToken
  15177. * @function
  15178. * @public
  15179. * @param {string} token - Authorization token.
  15180. */
  15181. set authorizationToken(token) {
  15182. Contracts_js_1.Contracts.throwIfNullOrWhitespace(token, "token");
  15183. this.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, token);
  15184. }
  15185. /**
  15186. * @param {Meeting} meeting - meeting to be recognized
  15187. */
  15188. joinMeetingAsync(meeting, cb, err) {
  15189. /* eslint-disable no-console */
  15190. // console.log(">> MeetingTranscriber::joinMeetingAsync");
  15191. /* eslint-enable no-console */
  15192. const meetingImpl = meeting;
  15193. Contracts_js_1.Contracts.throwIfNullOrUndefined(Exports_js_4.MeetingImpl, "Meeting");
  15194. // ref the meeting object
  15195. // create recognizer and subscribe to recognizer events
  15196. this.privRecognizer = new Exports_js_1.TranscriberRecognizer(meeting.config, this.privAudioConfig);
  15197. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privRecognizer, "Recognizer");
  15198. this.privRecognizer.connectMeetingCallbacks(this);
  15199. (0, Exports_js_2.marshalPromiseToCallbacks)(meetingImpl.connectTranscriberRecognizer(this.privRecognizer), cb, err);
  15200. }
  15201. /**
  15202. * Starts meeting transcription, until stopTranscribingAsync() is called.
  15203. * User must subscribe to events to receive transcription results.
  15204. * @member MeetingTranscriber.prototype.startTranscribingAsync
  15205. * @function
  15206. * @public
  15207. * @param cb - Callback invoked once the transcription has started.
  15208. * @param err - Callback invoked in case of an error.
  15209. */
  15210. startTranscribingAsync(cb, err) {
  15211. this.privRecognizer.startContinuousRecognitionAsync(cb, err);
  15212. }
  15213. /**
  15214. * Starts meeting transcription, until stopTranscribingAsync() is called.
  15215. * User must subscribe to events to receive transcription results.
  15216. * @member MeetingTranscriber.prototype.stopTranscribingAsync
  15217. * @function
  15218. * @public
  15219. * @param cb - Callback invoked once the transcription has started.
  15220. * @param err - Callback invoked in case of an error.
  15221. */
  15222. stopTranscribingAsync(cb, err) {
  15223. this.privRecognizer.stopContinuousRecognitionAsync(cb, err);
  15224. }
  15225. /**
  15226. * Leave the current meeting. After this is called, you will no longer receive any events.
  15227. */
  15228. leaveMeetingAsync(cb, err) {
  15229. this.privRecognizer.disconnectCallbacks();
  15230. // eslint-disable-next-line
  15231. (0, Exports_js_2.marshalPromiseToCallbacks)((async () => { return; })(), cb, err);
  15232. }
  15233. /**
  15234. * closes all external resources held by an instance of this class.
  15235. * @member MeetingTranscriber.prototype.close
  15236. * @function
  15237. * @public
  15238. */
  15239. close(cb, errorCb) {
  15240. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  15241. (0, Exports_js_2.marshalPromiseToCallbacks)(this.dispose(true), cb, errorCb);
  15242. }
  15243. /**
  15244. * Disposes any resources held by the object.
  15245. * @member MeetingTranscriber.prototype.dispose
  15246. * @function
  15247. * @public
  15248. * @param {boolean} disposing - true if disposing the object.
  15249. */
  15250. async dispose(disposing) {
  15251. if (this.privDisposedRecognizer) {
  15252. return;
  15253. }
  15254. if (!!this.privRecognizer) {
  15255. await this.privRecognizer.close();
  15256. this.privRecognizer = undefined;
  15257. }
  15258. if (disposing) {
  15259. this.privDisposedRecognizer = true;
  15260. }
  15261. }
  15262. }
  15263. exports.MeetingTranscriber = MeetingTranscriber;
  15264. /***/ }),
  15265. /* 174 */
  15266. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  15267. "use strict";
  15268. // Copyright (c) Microsoft Corporation. All rights reserved.
  15269. // Licensed under the MIT license.
  15270. Object.defineProperty(exports, "__esModule", ({ value: true }));
  15271. exports.ConversationTranscriptionResult = void 0;
  15272. const Exports_js_1 = __webpack_require__(79);
  15273. /**
  15274. * Defines result of conversation transcription.
  15275. * @class ConversationTranscriptionResult
  15276. */
  15277. class ConversationTranscriptionResult extends Exports_js_1.RecognitionResult {
  15278. /**
  15279. * Creates and initializes an instance of this class.
  15280. * @constructor
  15281. * @public
  15282. * @param {string} resultId - The result id.
  15283. * @param {ResultReason} reason - The reason.
  15284. * @param {string} text - The recognized text.
  15285. * @param {number} duration - The duration.
  15286. * @param {number} offset - The offset into the stream.
  15287. * @param {string} language - Primary Language detected, if provided.
  15288. * @param {string} languageDetectionConfidence - Primary Language confidence ("Unknown," "Low," "Medium," "High"...), if provided.
  15289. * @param {string} speakerId - speaker id for conversation transcription.
  15290. * @param {string} errorDetails - Error details, if provided.
  15291. * @param {string} json - Additional Json, if provided.
  15292. * @param {PropertyCollection} properties - Additional properties, if provided.
  15293. */
  15294. constructor(resultId, reason, text, duration, offset, language, languageDetectionConfidence, speakerId, errorDetails, json, properties) {
  15295. super(resultId, reason, text, duration, offset, language, languageDetectionConfidence, errorDetails, json, properties);
  15296. this.privSpeakerId = speakerId;
  15297. }
  15298. /**
  15299. * speaker id
  15300. * @member ConversationTranscriptionResult.prototype.speakerId
  15301. * @function
  15302. * @public
  15303. * @returns {string} id of speaker in given result
  15304. */
  15305. get speakerId() {
  15306. return this.privSpeakerId;
  15307. }
  15308. }
  15309. exports.ConversationTranscriptionResult = ConversationTranscriptionResult;
  15310. /***/ }),
  15311. /* 175 */
  15312. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  15313. "use strict";
  15314. // Copyright (c) Microsoft Corporation. All rights reserved.
  15315. // Licensed under the MIT license.
  15316. Object.defineProperty(exports, "__esModule", ({ value: true }));
  15317. exports.SynthesisRequest = exports.Synthesizer = void 0;
  15318. const Exports_js_1 = __webpack_require__(2);
  15319. const Exports_js_2 = __webpack_require__(4);
  15320. const Contracts_js_1 = __webpack_require__(64);
  15321. const Exports_js_3 = __webpack_require__(79);
  15322. class Synthesizer {
  15323. /**
  15324. * Creates and initializes an instance of a Recognizer
  15325. * @constructor
  15326. * @param {SpeechConfig} speechConfig - The speech config to initialize the synthesizer.
  15327. */
  15328. constructor(speechConfig) {
  15329. const speechConfigImpl = speechConfig;
  15330. Contracts_js_1.Contracts.throwIfNull(speechConfigImpl, "speechConfig");
  15331. this.privProperties = speechConfigImpl.properties.clone();
  15332. this.privDisposed = false;
  15333. this.privSynthesizing = false;
  15334. this.synthesisRequestQueue = new Exports_js_2.Queue();
  15335. this.tokenCredential = speechConfig.tokenCredential;
  15336. }
  15337. /**
  15338. * Gets the authorization token used to communicate with the service.
  15339. * @member Synthesizer.prototype.authorizationToken
  15340. * @function
  15341. * @public
  15342. * @returns {string} Authorization token.
  15343. */
  15344. get authorizationToken() {
  15345. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token);
  15346. }
  15347. /**
  15348. * Gets/Sets the authorization token used to communicate with the service.
  15349. * @member Synthesizer.prototype.authorizationToken
  15350. * @function
  15351. * @public
  15352. * @param {string} token - Authorization token.
  15353. */
  15354. set authorizationToken(token) {
  15355. Contracts_js_1.Contracts.throwIfNullOrWhitespace(token, "token");
  15356. this.properties.setProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, token);
  15357. }
  15358. /**
  15359. * The collection of properties and their values defined for this Synthesizer.
  15360. * @member Synthesizer.prototype.properties
  15361. * @function
  15362. * @public
  15363. * @returns {PropertyCollection} The collection of properties and their values defined for this SpeechSynthesizer.
  15364. */
  15365. get properties() {
  15366. return this.privProperties;
  15367. }
  15368. /**
  15369. * Indicates if auto detect source language is enabled
  15370. * @member Synthesizer.prototype.autoDetectSourceLanguage
  15371. * @function
  15372. * @public
  15373. * @returns {boolean} if auto detect source language is enabled
  15374. */
  15375. get autoDetectSourceLanguage() {
  15376. return this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages) === Exports_js_1.AutoDetectSourceLanguagesOpenRangeOptionName;
  15377. }
  15378. buildSsml(text) {
  15379. const languageToDefaultVoice = {
  15380. ["af-ZA"]: "af-ZA-AdriNeural",
  15381. ["am-ET"]: "am-ET-AmehaNeural",
  15382. ["ar-AE"]: "ar-AE-FatimaNeural",
  15383. ["ar-BH"]: "ar-BH-AliNeural",
  15384. ["ar-DZ"]: "ar-DZ-AminaNeural",
  15385. ["ar-EG"]: "ar-EG-SalmaNeural",
  15386. ["ar-IQ"]: "ar-IQ-BasselNeural",
  15387. ["ar-JO"]: "ar-JO-SanaNeural",
  15388. ["ar-KW"]: "ar-KW-FahedNeural",
  15389. ["ar-LY"]: "ar-LY-ImanNeural",
  15390. ["ar-MA"]: "ar-MA-JamalNeural",
  15391. ["ar-QA"]: "ar-QA-AmalNeural",
  15392. ["ar-SA"]: "ar-SA-HamedNeural",
  15393. ["ar-SY"]: "ar-SY-AmanyNeural",
  15394. ["ar-TN"]: "ar-TN-HediNeural",
  15395. ["ar-YE"]: "ar-YE-MaryamNeural",
  15396. ["bg-BG"]: "bg-BG-BorislavNeural",
  15397. ["bn-BD"]: "bn-BD-NabanitaNeural",
  15398. ["bn-IN"]: "bn-IN-BashkarNeural",
  15399. ["ca-ES"]: "ca-ES-JoanaNeural",
  15400. ["cs-CZ"]: "cs-CZ-AntoninNeural",
  15401. ["cy-GB"]: "cy-GB-AledNeural",
  15402. ["da-DK"]: "da-DK-ChristelNeural",
  15403. ["de-AT"]: "de-AT-IngridNeural",
  15404. ["de-CH"]: "de-CH-JanNeural",
  15405. ["de-DE"]: "de-DE-KatjaNeural",
  15406. ["el-GR"]: "el-GR-AthinaNeural",
  15407. ["en-AU"]: "en-AU-NatashaNeural",
  15408. ["en-CA"]: "en-CA-ClaraNeural",
  15409. ["en-GB"]: "en-GB-LibbyNeural",
  15410. ["en-HK"]: "en-HK-SamNeural",
  15411. ["en-IE"]: "en-IE-ConnorNeural",
  15412. ["en-IN"]: "en-IN-NeerjaNeural",
  15413. ["en-KE"]: "en-KE-AsiliaNeural",
  15414. ["en-NG"]: "en-NG-AbeoNeural",
  15415. ["en-NZ"]: "en-NZ-MitchellNeural",
  15416. ["en-PH"]: "en-PH-JamesNeural",
  15417. ["en-SG"]: "en-SG-LunaNeural",
  15418. ["en-TZ"]: "en-TZ-ElimuNeural",
  15419. ["en-US"]: "en-US-AvaMultilingualNeural",
  15420. ["en-ZA"]: "en-ZA-LeahNeural",
  15421. ["es-AR"]: "es-AR-ElenaNeural",
  15422. ["es-BO"]: "es-BO-MarceloNeural",
  15423. ["es-CL"]: "es-CL-CatalinaNeural",
  15424. ["es-CO"]: "es-CO-GonzaloNeural",
  15425. ["es-CR"]: "es-CR-JuanNeural",
  15426. ["es-CU"]: "es-CU-BelkysNeural",
  15427. ["es-DO"]: "es-DO-EmilioNeural",
  15428. ["es-EC"]: "es-EC-AndreaNeural",
  15429. ["es-ES"]: "es-ES-AlvaroNeural",
  15430. ["es-GQ"]: "es-GQ-JavierNeural",
  15431. ["es-GT"]: "es-GT-AndresNeural",
  15432. ["es-HN"]: "es-HN-CarlosNeural",
  15433. ["es-MX"]: "es-MX-DaliaNeural",
  15434. ["es-NI"]: "es-NI-FedericoNeural",
  15435. ["es-PA"]: "es-PA-MargaritaNeural",
  15436. ["es-PE"]: "es-PE-AlexNeural",
  15437. ["es-PR"]: "es-PR-KarinaNeural",
  15438. ["es-PY"]: "es-PY-MarioNeural",
  15439. ["es-SV"]: "es-SV-LorenaNeural",
  15440. ["es-US"]: "es-US-AlonsoNeural",
  15441. ["es-UY"]: "es-UY-MateoNeural",
  15442. ["es-VE"]: "es-VE-PaolaNeural",
  15443. ["et-EE"]: "et-EE-AnuNeural",
  15444. ["fa-IR"]: "fa-IR-DilaraNeural",
  15445. ["fi-FI"]: "fi-FI-SelmaNeural",
  15446. ["fil-PH"]: "fil-PH-AngeloNeural",
  15447. ["fr-BE"]: "fr-BE-CharlineNeural",
  15448. ["fr-CA"]: "fr-CA-SylvieNeural",
  15449. ["fr-CH"]: "fr-CH-ArianeNeural",
  15450. ["fr-FR"]: "fr-FR-DeniseNeural",
  15451. ["ga-IE"]: "ga-IE-ColmNeural",
  15452. ["gl-ES"]: "gl-ES-RoiNeural",
  15453. ["gu-IN"]: "gu-IN-DhwaniNeural",
  15454. ["he-IL"]: "he-IL-AvriNeural",
  15455. ["hi-IN"]: "hi-IN-MadhurNeural",
  15456. ["hr-HR"]: "hr-HR-GabrijelaNeural",
  15457. ["hu-HU"]: "hu-HU-NoemiNeural",
  15458. ["id-ID"]: "id-ID-ArdiNeural",
  15459. ["is-IS"]: "is-IS-GudrunNeural",
  15460. ["it-IT"]: "it-IT-IsabellaNeural",
  15461. ["ja-JP"]: "ja-JP-NanamiNeural",
  15462. ["jv-ID"]: "jv-ID-DimasNeural",
  15463. ["kk-KZ"]: "kk-KZ-AigulNeural",
  15464. ["km-KH"]: "km-KH-PisethNeural",
  15465. ["kn-IN"]: "kn-IN-GaganNeural",
  15466. ["ko-KR"]: "ko-KR-SunHiNeural",
  15467. ["lo-LA"]: "lo-LA-ChanthavongNeural",
  15468. ["lt-LT"]: "lt-LT-LeonasNeural",
  15469. ["lv-LV"]: "lv-LV-EveritaNeural",
  15470. ["mk-MK"]: "mk-MK-AleksandarNeural",
  15471. ["ml-IN"]: "ml-IN-MidhunNeural",
  15472. ["mr-IN"]: "mr-IN-AarohiNeural",
  15473. ["ms-MY"]: "ms-MY-OsmanNeural",
  15474. ["mt-MT"]: "mt-MT-GraceNeural",
  15475. ["my-MM"]: "my-MM-NilarNeural",
  15476. ["nb-NO"]: "nb-NO-PernilleNeural",
  15477. ["nl-BE"]: "nl-BE-ArnaudNeural",
  15478. ["nl-NL"]: "nl-NL-ColetteNeural",
  15479. ["pl-PL"]: "pl-PL-AgnieszkaNeural",
  15480. ["ps-AF"]: "ps-AF-GulNawazNeural",
  15481. ["pt-BR"]: "pt-BR-FranciscaNeural",
  15482. ["pt-PT"]: "pt-PT-DuarteNeural",
  15483. ["ro-RO"]: "ro-RO-AlinaNeural",
  15484. ["ru-RU"]: "ru-RU-SvetlanaNeural",
  15485. ["si-LK"]: "si-LK-SameeraNeural",
  15486. ["sk-SK"]: "sk-SK-LukasNeural",
  15487. ["sl-SI"]: "sl-SI-PetraNeural",
  15488. ["so-SO"]: "so-SO-MuuseNeural",
  15489. ["sr-RS"]: "sr-RS-NicholasNeural",
  15490. ["su-ID"]: "su-ID-JajangNeural",
  15491. ["sv-SE"]: "sv-SE-SofieNeural",
  15492. ["sw-KE"]: "sw-KE-RafikiNeural",
  15493. ["sw-TZ"]: "sw-TZ-DaudiNeural",
  15494. ["ta-IN"]: "ta-IN-PallaviNeural",
  15495. ["ta-LK"]: "ta-LK-KumarNeural",
  15496. ["ta-SG"]: "ta-SG-AnbuNeural",
  15497. ["te-IN"]: "te-IN-MohanNeural",
  15498. ["th-TH"]: "th-TH-PremwadeeNeural",
  15499. ["tr-TR"]: "tr-TR-AhmetNeural",
  15500. ["uk-UA"]: "uk-UA-OstapNeural",
  15501. ["ur-IN"]: "ur-IN-GulNeural",
  15502. ["ur-PK"]: "ur-PK-AsadNeural",
  15503. ["uz-UZ"]: "uz-UZ-MadinaNeural",
  15504. ["vi-VN"]: "vi-VN-HoaiMyNeural",
  15505. ["zh-CN"]: "zh-CN-XiaoxiaoNeural",
  15506. ["zh-HK"]: "zh-HK-HiuMaanNeural",
  15507. ["zh-TW"]: "zh-TW-HsiaoChenNeural",
  15508. ["zu-ZA"]: "zu-ZA-ThandoNeural",
  15509. };
  15510. let language = this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_SynthLanguage, "en-US");
  15511. let voice = this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_SynthVoice, "");
  15512. let ssml = Synthesizer.XMLEncode(text);
  15513. if (this.autoDetectSourceLanguage) {
  15514. language = "en-US";
  15515. }
  15516. else {
  15517. voice = voice || languageToDefaultVoice[language];
  15518. }
  15519. if (voice) {
  15520. ssml = `<voice name='${voice}'>${ssml}</voice>`;
  15521. }
  15522. ssml = `<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xmlns:mstts='http://www.w3.org/2001/mstts' xmlns:emo='http://www.w3.org/2009/10/emotionml' xml:lang='${language}'>${ssml}</speak>`;
  15523. return ssml;
  15524. }
  15525. /**
  15526. * This method performs cleanup of resources.
  15527. * The Boolean parameter disposing indicates whether the method is called
  15528. * from Dispose (if disposing is true) or from the finalizer (if disposing is false).
  15529. * Derived classes should override this method to dispose resource if needed.
  15530. * @member Synthesizer.prototype.dispose
  15531. * @function
  15532. * @public
  15533. * @param {boolean} disposing - Flag to request disposal.
  15534. */
  15535. async dispose(disposing) {
  15536. if (this.privDisposed) {
  15537. return;
  15538. }
  15539. if (disposing) {
  15540. if (this.privAdapter) {
  15541. await this.privAdapter.dispose();
  15542. }
  15543. }
  15544. this.privDisposed = true;
  15545. }
  15546. async adapterSpeak() {
  15547. if (!this.privDisposed && !this.privSynthesizing) {
  15548. this.privSynthesizing = true;
  15549. const request = await this.synthesisRequestQueue.dequeue();
  15550. return this.privAdapter.Speak(request.text, request.isSSML, request.requestId, request.cb, request.err, request.dataStream);
  15551. }
  15552. }
  15553. createSynthesizerConfig(speechConfig) {
  15554. return new Exports_js_1.SynthesizerConfig(speechConfig, this.privProperties);
  15555. }
  15556. // Does the generic synthesizer setup that is common across all synthesizer types.
  15557. implCommonSynthesizeSetup() {
  15558. let osPlatform = (typeof window !== "undefined") ? "Browser" : "Node";
  15559. let osName = "unknown";
  15560. let osVersion = "unknown";
  15561. if (typeof navigator !== "undefined") {
  15562. osPlatform = osPlatform + "/" + navigator.platform;
  15563. osName = navigator.userAgent;
  15564. osVersion = navigator.appVersion;
  15565. }
  15566. const synthesizerConfig = this.createSynthesizerConfig(new Exports_js_1.SpeechServiceConfig(new Exports_js_1.Context(new Exports_js_1.OS(osPlatform, osName, osVersion))));
  15567. const subscriptionKey = this.privProperties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Key, undefined);
  15568. const authentication = (subscriptionKey && subscriptionKey !== "")
  15569. ? new Exports_js_1.CognitiveSubscriptionKeyAuthentication(subscriptionKey)
  15570. : (this.tokenCredential)
  15571. ? new Exports_js_1.CognitiveTokenAuthentication(async () => {
  15572. try {
  15573. const tokenResponse = await this.tokenCredential.getToken("https://cognitiveservices.azure.com/.default");
  15574. return tokenResponse?.token ?? "";
  15575. }
  15576. catch (err) {
  15577. throw err;
  15578. }
  15579. }, async () => {
  15580. try {
  15581. const tokenResponse = await this.tokenCredential.getToken("https://cognitiveservices.azure.com/.default");
  15582. return tokenResponse?.token ?? "";
  15583. }
  15584. catch (err) {
  15585. throw err;
  15586. }
  15587. })
  15588. : new Exports_js_1.CognitiveTokenAuthentication(() => {
  15589. const authorizationToken = this.privProperties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, undefined);
  15590. return Promise.resolve(authorizationToken);
  15591. }, () => {
  15592. const authorizationToken = this.privProperties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, undefined);
  15593. return Promise.resolve(authorizationToken);
  15594. });
  15595. this.privAdapter = this.createSynthesisAdapter(authentication, this.privConnectionFactory, synthesizerConfig);
  15596. this.privRestAdapter = this.createRestSynthesisAdapter(authentication, synthesizerConfig);
  15597. }
  15598. static XMLEncode(text) {
  15599. return text.replace(/&/g, "&amp;")
  15600. .replace(/</g, "&lt;")
  15601. .replace(/>/g, "&gt;")
  15602. .replace(/"/g, "&quot;")
  15603. .replace(/'/g, "&apos;");
  15604. }
  15605. }
  15606. exports.Synthesizer = Synthesizer;
  15607. class SynthesisRequest {
  15608. constructor(requestId, text, isSSML, cb, err, dataStream) {
  15609. this.requestId = requestId;
  15610. this.text = text;
  15611. this.isSSML = isSSML;
  15612. this.cb = cb;
  15613. this.err = err;
  15614. this.dataStream = dataStream;
  15615. }
  15616. }
  15617. exports.SynthesisRequest = SynthesisRequest;
  15618. /***/ }),
  15619. /* 176 */
  15620. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  15621. "use strict";
  15622. // Copyright (c) Microsoft Corporation. All rights reserved.
  15623. // Licensed under the MIT license.
  15624. Object.defineProperty(exports, "__esModule", ({ value: true }));
  15625. exports.SpeechSynthesizer = void 0;
  15626. const Exports_js_1 = __webpack_require__(2);
  15627. const Exports_js_2 = __webpack_require__(4);
  15628. const AudioFileWriter_js_1 = __webpack_require__(81);
  15629. const AudioOutputFormat_js_1 = __webpack_require__(85);
  15630. const AudioOutputStream_js_1 = __webpack_require__(84);
  15631. const Contracts_js_1 = __webpack_require__(64);
  15632. const Exports_js_3 = __webpack_require__(79);
  15633. const Synthesizer_js_1 = __webpack_require__(175);
  15634. /**
  15635. * Defines the class SpeechSynthesizer for text to speech.
  15636. * Updated in version 1.16.0
  15637. * @class SpeechSynthesizer
  15638. */
  15639. class SpeechSynthesizer extends Exports_js_3.Synthesizer {
  15640. /**
  15641. * SpeechSynthesizer constructor.
  15642. * @constructor
  15643. * @param {SpeechConfig} speechConfig - An set of initial properties for this synthesizer.
  15644. * @param {AudioConfig} audioConfig - An optional audio configuration associated with the synthesizer.
  15645. */
  15646. constructor(speechConfig, audioConfig) {
  15647. super(speechConfig);
  15648. if (audioConfig !== null) {
  15649. if (audioConfig === undefined) {
  15650. this.audioConfig = (typeof window === "undefined") ? undefined : Exports_js_3.AudioConfig.fromDefaultSpeakerOutput();
  15651. }
  15652. else {
  15653. this.audioConfig = audioConfig;
  15654. }
  15655. }
  15656. this.privConnectionFactory = new Exports_js_1.SpeechSynthesisConnectionFactory();
  15657. this.implCommonSynthesizeSetup();
  15658. }
  15659. /**
  15660. * SpeechSynthesizer constructor.
  15661. * @constructor
  15662. * @param {SpeechConfig} speechConfig - an set of initial properties for this synthesizer
  15663. * @param {AutoDetectSourceLanguageConfig} autoDetectSourceLanguageConfig - An source language detection configuration associated with the synthesizer
  15664. * @param {AudioConfig} audioConfig - An optional audio configuration associated with the synthesizer
  15665. */
  15666. static FromConfig(speechConfig, autoDetectSourceLanguageConfig, audioConfig) {
  15667. const speechConfigImpl = speechConfig;
  15668. autoDetectSourceLanguageConfig.properties.mergeTo(speechConfigImpl.properties);
  15669. return new SpeechSynthesizer(speechConfig, audioConfig);
  15670. }
  15671. /**
  15672. * Executes speech synthesis on plain text.
  15673. * The task returns the synthesis result.
  15674. * @member SpeechSynthesizer.prototype.speakTextAsync
  15675. * @function
  15676. * @public
  15677. * @param text - Text to be synthesized.
  15678. * @param cb - Callback that received the SpeechSynthesisResult.
  15679. * @param err - Callback invoked in case of an error.
  15680. * @param stream - AudioOutputStream to receive the synthesized audio.
  15681. */
  15682. speakTextAsync(text, cb, err, stream) {
  15683. this.speakImpl(text, false, cb, err, stream);
  15684. }
  15685. /**
  15686. * Executes speech synthesis on SSML.
  15687. * The task returns the synthesis result.
  15688. * @member SpeechSynthesizer.prototype.speakSsmlAsync
  15689. * @function
  15690. * @public
  15691. * @param ssml - SSML to be synthesized.
  15692. * @param cb - Callback that received the SpeechSynthesisResult.
  15693. * @param err - Callback invoked in case of an error.
  15694. * @param stream - AudioOutputStream to receive the synthesized audio.
  15695. */
  15696. speakSsmlAsync(ssml, cb, err, stream) {
  15697. this.speakImpl(ssml, true, cb, err, stream);
  15698. }
  15699. /**
  15700. * Get list of synthesis voices available.
  15701. * The task returns the synthesis voice result.
  15702. * @member SpeechSynthesizer.prototype.getVoicesAsync
  15703. * @function
  15704. * @async
  15705. * @public
  15706. * @param locale - Locale of voices in BCP-47 format; if left empty, get all available voices.
  15707. * @return {Promise<SynthesisVoicesResult>} - Promise of a SynthesisVoicesResult.
  15708. */
  15709. async getVoicesAsync(locale = "") {
  15710. return this.getVoices(locale);
  15711. }
  15712. /**
  15713. * Dispose of associated resources.
  15714. * @member SpeechSynthesizer.prototype.close
  15715. * @function
  15716. * @public
  15717. */
  15718. close(cb, err) {
  15719. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);
  15720. (0, Exports_js_2.marshalPromiseToCallbacks)(this.dispose(true), cb, err);
  15721. }
  15722. /**
  15723. * @Internal
  15724. * Do not use externally, object returned will change without warning or notice.
  15725. */
  15726. get internalData() {
  15727. return this.privAdapter;
  15728. }
  15729. //
  15730. // ################################################################################################################
  15731. // IMPLEMENTATION.
  15732. // ################################################################################################################
  15733. //
  15734. // Creates the synthesis adapter
  15735. createSynthesisAdapter(authentication, connectionFactory, synthesizerConfig) {
  15736. return new Exports_js_1.SpeechSynthesisAdapter(authentication, connectionFactory, synthesizerConfig, this, this.audioConfig);
  15737. }
  15738. createRestSynthesisAdapter(authentication, synthesizerConfig) {
  15739. return new Exports_js_1.SynthesisRestAdapter(synthesizerConfig, authentication);
  15740. }
  15741. implCommonSynthesizeSetup() {
  15742. super.implCommonSynthesizeSetup();
  15743. this.privAdapter.audioOutputFormat = AudioOutputFormat_js_1.AudioOutputFormatImpl.fromSpeechSynthesisOutputFormat(Exports_js_3.SpeechSynthesisOutputFormat[this.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_SynthOutputFormat, undefined)]);
  15744. }
  15745. speakImpl(text, IsSsml, cb, err, dataStream) {
  15746. try {
  15747. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);
  15748. const requestId = (0, Exports_js_2.createNoDashGuid)();
  15749. let audioDestination;
  15750. if (dataStream instanceof Exports_js_3.PushAudioOutputStreamCallback) {
  15751. audioDestination = new AudioOutputStream_js_1.PushAudioOutputStreamImpl(dataStream);
  15752. }
  15753. else if (dataStream instanceof Exports_js_3.PullAudioOutputStream) {
  15754. audioDestination = dataStream;
  15755. }
  15756. else if (dataStream !== undefined) {
  15757. audioDestination = new AudioFileWriter_js_1.AudioFileWriter(dataStream);
  15758. }
  15759. else {
  15760. audioDestination = undefined;
  15761. }
  15762. this.synthesisRequestQueue.enqueue(new Synthesizer_js_1.SynthesisRequest(requestId, text, IsSsml, (e) => {
  15763. this.privSynthesizing = false;
  15764. if (!!cb) {
  15765. try {
  15766. cb(e);
  15767. }
  15768. catch (e) {
  15769. if (!!err) {
  15770. err(e);
  15771. }
  15772. }
  15773. }
  15774. cb = undefined;
  15775. /* eslint-disable no-empty */
  15776. this.adapterSpeak().catch(() => { });
  15777. }, (e) => {
  15778. if (!!err) {
  15779. err(e);
  15780. }
  15781. }, audioDestination));
  15782. /* eslint-disable no-empty-function */
  15783. this.adapterSpeak().catch(() => { });
  15784. }
  15785. catch (error) {
  15786. if (!!err) {
  15787. if (error instanceof Error) {
  15788. const typedError = error;
  15789. err(typedError.name + ": " + typedError.message);
  15790. }
  15791. else {
  15792. err(error);
  15793. }
  15794. }
  15795. // Destroy the synthesizer.
  15796. /* eslint-disable no-empty */
  15797. this.dispose(true).catch(() => { });
  15798. }
  15799. }
  15800. async getVoices(locale) {
  15801. const requestId = (0, Exports_js_2.createNoDashGuid)();
  15802. const response = await this.privRestAdapter.getVoicesList(requestId);
  15803. if (response.ok && Array.isArray(response.json)) {
  15804. let json = response.json;
  15805. if (!!locale && locale.length > 0) {
  15806. json = json.filter((item) => !!item.Locale && item.Locale.toLowerCase() === locale.toLowerCase());
  15807. }
  15808. return new Exports_js_3.SynthesisVoicesResult(requestId, json, undefined);
  15809. }
  15810. else {
  15811. return new Exports_js_3.SynthesisVoicesResult(requestId, undefined, `Error: ${response.status}: ${response.statusText}`);
  15812. }
  15813. }
  15814. }
  15815. exports.SpeechSynthesizer = SpeechSynthesizer;
  15816. /***/ }),
  15817. /* 177 */
  15818. /***/ ((__unused_webpack_module, exports) => {
  15819. "use strict";
  15820. // Copyright (c) Microsoft Corporation. All rights reserved.
  15821. // Licensed under the MIT license.
  15822. Object.defineProperty(exports, "__esModule", ({ value: true }));
  15823. exports.SynthesisResult = void 0;
  15824. /**
  15825. * Base class for synthesis results
  15826. * @class SynthesisResult
  15827. * Added in version 1.20.0
  15828. */
  15829. class SynthesisResult {
  15830. /**
  15831. * Creates and initializes an instance of this class.
  15832. * @constructor
  15833. * @param {string} resultId - The result id.
  15834. * @param {ResultReason} reason - The reason.
  15835. * @param {string} errorDetails - Error details, if provided.
  15836. * @param {PropertyCollection} properties - Additional properties, if provided.
  15837. */
  15838. constructor(resultId, reason, errorDetails, properties) {
  15839. this.privResultId = resultId;
  15840. this.privReason = reason;
  15841. this.privErrorDetails = errorDetails;
  15842. this.privProperties = properties;
  15843. }
  15844. /**
  15845. * Specifies the result identifier.
  15846. * @member SynthesisResult.prototype.resultId
  15847. * @function
  15848. * @public
  15849. * @returns {string} Specifies the result identifier.
  15850. */
  15851. get resultId() {
  15852. return this.privResultId;
  15853. }
  15854. /**
  15855. * Specifies status of the result.
  15856. * @member SynthesisResult.prototype.reason
  15857. * @function
  15858. * @public
  15859. * @returns {ResultReason} Specifies status of the result.
  15860. */
  15861. get reason() {
  15862. return this.privReason;
  15863. }
  15864. /**
  15865. * In case of an unsuccessful synthesis, provides details of the occurred error.
  15866. * @member SynthesisResult.prototype.errorDetails
  15867. * @function
  15868. * @public
  15869. * @returns {string} a brief description of an error.
  15870. */
  15871. get errorDetails() {
  15872. return this.privErrorDetails;
  15873. }
  15874. /**
  15875. * The set of properties exposed in the result.
  15876. * @member SynthesisResult.prototype.properties
  15877. * @function
  15878. * @public
  15879. * @returns {PropertyCollection} The set of properties exposed in the result.
  15880. */
  15881. get properties() {
  15882. return this.privProperties;
  15883. }
  15884. }
  15885. exports.SynthesisResult = SynthesisResult;
  15886. /***/ }),
  15887. /* 178 */
  15888. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  15889. "use strict";
  15890. // Copyright (c) Microsoft Corporation. All rights reserved.
  15891. // Licensed under the MIT license.
  15892. Object.defineProperty(exports, "__esModule", ({ value: true }));
  15893. exports.SpeechSynthesisResult = void 0;
  15894. const Exports_js_1 = __webpack_require__(79);
  15895. /**
  15896. * Defines result of speech synthesis.
  15897. * @class SpeechSynthesisResult
  15898. * Added in version 1.11.0
  15899. */
  15900. class SpeechSynthesisResult extends Exports_js_1.SynthesisResult {
  15901. /**
  15902. * Creates and initializes an instance of this class.
  15903. * @constructor
  15904. * @param {string} resultId - The result id.
  15905. * @param {ResultReason} reason - The reason.
  15906. * @param {ArrayBuffer} audioData - The synthesized audio binary.
  15907. * @param {string} errorDetails - Error details, if provided.
  15908. * @param {PropertyCollection} properties - Additional properties, if provided.
  15909. * @param {number} audioDuration - The audio duration.
  15910. */
  15911. constructor(resultId, reason, audioData, errorDetails, properties, audioDuration) {
  15912. super(resultId, reason, errorDetails, properties);
  15913. this.privAudioData = audioData;
  15914. this.privAudioDuration = audioDuration;
  15915. }
  15916. /**
  15917. * The synthesized audio data
  15918. * @member SpeechSynthesisResult.prototype.audioData
  15919. * @function
  15920. * @public
  15921. * @returns {ArrayBuffer} The synthesized audio data.
  15922. */
  15923. get audioData() {
  15924. return this.privAudioData;
  15925. }
  15926. /**
  15927. * The time duration of synthesized audio, in ticks (100 nanoseconds).
  15928. * @member SpeechSynthesisResult.prototype.audioDuration
  15929. * @function
  15930. * @public
  15931. * @returns {number} The time duration of synthesized audio.
  15932. */
  15933. get audioDuration() {
  15934. return this.privAudioDuration;
  15935. }
  15936. }
  15937. exports.SpeechSynthesisResult = SpeechSynthesisResult;
  15938. /***/ }),
  15939. /* 179 */
  15940. /***/ ((__unused_webpack_module, exports) => {
  15941. "use strict";
  15942. // Copyright (c) Microsoft Corporation. All rights reserved.
  15943. // Licensed under the MIT license.
  15944. Object.defineProperty(exports, "__esModule", ({ value: true }));
  15945. exports.SpeechSynthesisEventArgs = void 0;
  15946. /**
  15947. * Defines contents of speech synthesis events.
  15948. * @class SpeechSynthesisEventArgs
  15949. * Added in version 1.11.0
  15950. */
  15951. class SpeechSynthesisEventArgs {
  15952. /**
  15953. * Creates and initializes an instance of this class.
  15954. * @constructor
  15955. * @param {SpeechSynthesisResult} result - The speech synthesis result.
  15956. */
  15957. constructor(result) {
  15958. this.privResult = result;
  15959. }
  15960. /**
  15961. * Specifies the synthesis result.
  15962. * @member SpeechSynthesisEventArgs.prototype.result
  15963. * @function
  15964. * @public
  15965. * @returns {SpeechSynthesisResult} the synthesis result.
  15966. */
  15967. get result() {
  15968. return this.privResult;
  15969. }
  15970. }
  15971. exports.SpeechSynthesisEventArgs = SpeechSynthesisEventArgs;
  15972. /***/ }),
  15973. /* 180 */
  15974. /***/ ((__unused_webpack_module, exports) => {
  15975. "use strict";
  15976. // Copyright (c) Microsoft Corporation. All rights reserved.
  15977. // Licensed under the MIT license.
  15978. Object.defineProperty(exports, "__esModule", ({ value: true }));
  15979. exports.SpeechSynthesisWordBoundaryEventArgs = void 0;
  15980. /**
  15981. * Defines contents of speech synthesis word boundary event.
  15982. * @class SpeechSynthesisWordBoundaryEventArgs
  15983. * Added in version 1.11.0
  15984. */
  15985. class SpeechSynthesisWordBoundaryEventArgs {
  15986. /**
  15987. * Creates and initializes an instance of this class.
  15988. * @constructor
  15989. * @param {number} audioOffset - The audio offset.
  15990. * @param {number} duration - The audio duration.
  15991. * @param {string} text - The text.
  15992. * @param {number} wordLength - The length of the word.
  15993. * @param {number} textOffset - The text offset.
  15994. * @param {SpeechSynthesisBoundaryType} boundaryType - The boundary type
  15995. */
  15996. constructor(audioOffset, duration, text, wordLength, textOffset, boundaryType) {
  15997. this.privAudioOffset = audioOffset;
  15998. this.privDuration = duration;
  15999. this.privText = text;
  16000. this.privWordLength = wordLength;
  16001. this.privTextOffset = textOffset;
  16002. this.privBoundaryType = boundaryType;
  16003. }
  16004. /**
  16005. * Specifies the audio offset.
  16006. * @member SpeechSynthesisWordBoundaryEventArgs.prototype.audioOffset
  16007. * @function
  16008. * @public
  16009. * @returns {number} the audio offset.
  16010. */
  16011. get audioOffset() {
  16012. return this.privAudioOffset;
  16013. }
  16014. /**
  16015. * Specifies the duration, in ticks (100 nanoseconds).
  16016. * @member SpeechSynthesisWordBoundaryEventArgs.prototype.duration
  16017. * @function
  16018. * @public
  16019. * @returns {number} Duration in 100 nanosecond increments.
  16020. */
  16021. get duration() {
  16022. return this.privDuration;
  16023. }
  16024. /**
  16025. * Specifies the text of the word boundary event.
  16026. * @member SpeechSynthesisWordBoundaryEventArgs.prototype.text
  16027. * @function
  16028. * @public
  16029. * @returns {string} the text.
  16030. */
  16031. get text() {
  16032. return this.privText;
  16033. }
  16034. /**
  16035. * Specifies the word length
  16036. * @member SpeechSynthesisWordBoundaryEventArgs.prototype.wordLength
  16037. * @function
  16038. * @public
  16039. * @returns {number} the word length
  16040. */
  16041. get wordLength() {
  16042. return this.privWordLength;
  16043. }
  16044. /**
  16045. * Specifies the text offset.
  16046. * @member SpeechSynthesisWordBoundaryEventArgs.prototype.textOffset
  16047. * @function
  16048. * @public
  16049. * @returns {number} the text offset.
  16050. */
  16051. get textOffset() {
  16052. return this.privTextOffset;
  16053. }
  16054. /**
  16055. * Specifies the boundary type.
  16056. * @member SpeechSynthesisWordBoundaryEventArgs.prototype.boundaryType
  16057. * @function
  16058. * @public
  16059. * @returns {SpeechSynthesisBoundaryType} the boundary type.
  16060. */
  16061. get boundaryType() {
  16062. return this.privBoundaryType;
  16063. }
  16064. }
  16065. exports.SpeechSynthesisWordBoundaryEventArgs = SpeechSynthesisWordBoundaryEventArgs;
  16066. /***/ }),
  16067. /* 181 */
  16068. /***/ ((__unused_webpack_module, exports) => {
  16069. "use strict";
  16070. // Copyright (c) Microsoft Corporation. All rights reserved.
  16071. // Licensed under the MIT license.
  16072. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16073. exports.SpeechSynthesisBookmarkEventArgs = void 0;
  16074. /**
  16075. * Defines contents of speech synthesis bookmark event.
  16076. * @class SpeechSynthesisBookmarkEventArgs
  16077. * Added in version 1.16.0
  16078. */
  16079. class SpeechSynthesisBookmarkEventArgs {
  16080. /**
  16081. * Creates and initializes an instance of this class.
  16082. * @constructor
  16083. * @param {number} audioOffset - The audio offset.
  16084. * @param {string} text - The bookmark text.
  16085. */
  16086. constructor(audioOffset, text) {
  16087. this.privAudioOffset = audioOffset;
  16088. this.privText = text;
  16089. }
  16090. /**
  16091. * Specifies the audio offset.
  16092. * @member SpeechSynthesisBookmarkEventArgs.prototype.audioOffset
  16093. * @function
  16094. * @public
  16095. * @returns {number} the audio offset.
  16096. */
  16097. get audioOffset() {
  16098. return this.privAudioOffset;
  16099. }
  16100. /**
  16101. * Specifies the bookmark.
  16102. * @member SpeechSynthesisBookmarkEventArgs.prototype.text
  16103. * @function
  16104. * @public
  16105. * @returns {string} the bookmark text.
  16106. */
  16107. get text() {
  16108. return this.privText;
  16109. }
  16110. }
  16111. exports.SpeechSynthesisBookmarkEventArgs = SpeechSynthesisBookmarkEventArgs;
  16112. /***/ }),
  16113. /* 182 */
  16114. /***/ ((__unused_webpack_module, exports) => {
  16115. "use strict";
  16116. // Copyright (c) Microsoft Corporation. All rights reserved.
  16117. // Licensed under the MIT license.
  16118. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16119. exports.SpeechSynthesisVisemeEventArgs = void 0;
  16120. /**
  16121. * Defines contents of speech synthesis viseme event.
  16122. * @class SpeechSynthesisVisemeEventArgs
  16123. * Added in version 1.16.0
  16124. */
  16125. class SpeechSynthesisVisemeEventArgs {
  16126. /**
  16127. * Creates and initializes an instance of this class.
  16128. * @constructor
  16129. * @param {number} audioOffset - The audio offset.
  16130. * @param {number} visemeId - The viseme ID.
  16131. * @param {string} animation - The animation, could be in svg or other format.
  16132. */
  16133. constructor(audioOffset, visemeId, animation) {
  16134. this.privAudioOffset = audioOffset;
  16135. this.privVisemeId = visemeId;
  16136. this.privAnimation = animation;
  16137. }
  16138. /**
  16139. * Specifies the audio offset.
  16140. * @member SpeechSynthesisVisemeEventArgs.prototype.audioOffset
  16141. * @function
  16142. * @public
  16143. * @returns {number} the audio offset.
  16144. */
  16145. get audioOffset() {
  16146. return this.privAudioOffset;
  16147. }
  16148. /**
  16149. * Specifies the viseme ID.
  16150. * @member SpeechSynthesisVisemeEventArgs.prototype.visemeId
  16151. * @function
  16152. * @public
  16153. * @returns {number} the viseme ID.
  16154. */
  16155. get visemeId() {
  16156. return this.privVisemeId;
  16157. }
  16158. /**
  16159. * Specifies the animation.
  16160. * @member SpeechSynthesisVisemeEventArgs.prototype.animation
  16161. * @function
  16162. * @public
  16163. * @returns {string} the animation, could be in svg or other format.
  16164. */
  16165. get animation() {
  16166. return this.privAnimation;
  16167. }
  16168. }
  16169. exports.SpeechSynthesisVisemeEventArgs = SpeechSynthesisVisemeEventArgs;
  16170. /***/ }),
  16171. /* 183 */
  16172. /***/ ((__unused_webpack_module, exports) => {
  16173. "use strict";
  16174. // Copyright (c) Microsoft Corporation. All rights reserved.
  16175. // Licensed under the MIT license.
  16176. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16177. exports.SpeechSynthesisBoundaryType = void 0;
  16178. /**
  16179. * Defines the boundary type of speech synthesis boundary event.
  16180. * @class SpeechSynthesisBoundaryType
  16181. * Added in version 1.21.0
  16182. */
  16183. var SpeechSynthesisBoundaryType;
  16184. (function (SpeechSynthesisBoundaryType) {
  16185. /**
  16186. * Indicates the boundary text is a word.
  16187. * @member SpeechSynthesisBoundaryType.Word
  16188. */
  16189. SpeechSynthesisBoundaryType["Word"] = "WordBoundary";
  16190. /**
  16191. * Indicates the boundary text is a punctuation.
  16192. * @member SpeechSynthesisBoundaryType.Punctuation
  16193. */
  16194. SpeechSynthesisBoundaryType["Punctuation"] = "PunctuationBoundary";
  16195. /**
  16196. * Indicates the boundary text is a sentence.
  16197. * @member SpeechSynthesisBoundaryType.Sentence
  16198. */
  16199. SpeechSynthesisBoundaryType["Sentence"] = "SentenceBoundary";
  16200. })(SpeechSynthesisBoundaryType = exports.SpeechSynthesisBoundaryType || (exports.SpeechSynthesisBoundaryType = {}));
  16201. /***/ }),
  16202. /* 184 */
  16203. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  16204. "use strict";
  16205. // Copyright (c) Microsoft Corporation. All rights reserved.
  16206. // Licensed under the MIT license.
  16207. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16208. exports.SynthesisVoicesResult = void 0;
  16209. const Exports_js_1 = __webpack_require__(79);
  16210. /**
  16211. * Defines result of speech synthesis.
  16212. * @class SynthesisVoicesResult
  16213. * Added in version 1.20.0
  16214. */
  16215. class SynthesisVoicesResult extends Exports_js_1.SynthesisResult {
  16216. /**
  16217. * Creates and initializes an instance of this class.
  16218. * @constructor
  16219. * @param requestId - result id for request.
  16220. * @param json - json payload from endpoint.
  16221. */
  16222. constructor(requestId, json, errorDetails) {
  16223. if (Array.isArray(json)) {
  16224. super(requestId, Exports_js_1.ResultReason.VoicesListRetrieved, undefined, new Exports_js_1.PropertyCollection());
  16225. this.privVoices = [];
  16226. for (const item of json) {
  16227. this.privVoices.push(new Exports_js_1.VoiceInfo(item));
  16228. }
  16229. }
  16230. else {
  16231. super(requestId, Exports_js_1.ResultReason.Canceled, errorDetails ? errorDetails : "Error information unavailable", new Exports_js_1.PropertyCollection());
  16232. }
  16233. }
  16234. /**
  16235. * The list of voices
  16236. * @member SynthesisVoicesResult.prototype.voices
  16237. * @function
  16238. * @public
  16239. * @returns {VoiceInfo[]} List of synthesized voices.
  16240. */
  16241. get voices() {
  16242. return this.privVoices;
  16243. }
  16244. }
  16245. exports.SynthesisVoicesResult = SynthesisVoicesResult;
  16246. /***/ }),
  16247. /* 185 */
  16248. /***/ ((__unused_webpack_module, exports) => {
  16249. "use strict";
  16250. // Copyright (c) Microsoft Corporation. All rights reserved.
  16251. // Licensed under the MIT license.
  16252. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16253. exports.VoiceInfo = exports.SynthesisVoiceType = exports.SynthesisVoiceGender = void 0;
  16254. /**
  16255. * Defines the gender of synthesis voices.
  16256. * Added in version 1.20.0.
  16257. */
  16258. var SynthesisVoiceGender;
  16259. (function (SynthesisVoiceGender) {
  16260. /** Gender unknown */
  16261. SynthesisVoiceGender[SynthesisVoiceGender["Unknown"] = 0] = "Unknown";
  16262. /** Female voice */
  16263. SynthesisVoiceGender[SynthesisVoiceGender["Female"] = 1] = "Female";
  16264. /** Male voice */
  16265. SynthesisVoiceGender[SynthesisVoiceGender["Male"] = 2] = "Male";
  16266. /** Neutral voice */
  16267. SynthesisVoiceGender[SynthesisVoiceGender["Neutral"] = 3] = "Neutral";
  16268. })(SynthesisVoiceGender = exports.SynthesisVoiceGender || (exports.SynthesisVoiceGender = {}));
  16269. var SynthesisVoiceType;
  16270. (function (SynthesisVoiceType) {
  16271. /**
  16272. * Voice type is not known.
  16273. */
  16274. SynthesisVoiceType[SynthesisVoiceType["Unknown"] = 0] = "Unknown";
  16275. /**
  16276. * Online neural voices.
  16277. */
  16278. SynthesisVoiceType[SynthesisVoiceType["OnlineNeural"] = 1] = "OnlineNeural";
  16279. /**
  16280. * Online standard voices. These voices are deprecated.
  16281. */
  16282. SynthesisVoiceType[SynthesisVoiceType["OnlineStandard"] = 2] = "OnlineStandard";
  16283. /**
  16284. * Offline neural voices.
  16285. */
  16286. SynthesisVoiceType[SynthesisVoiceType["OfflineNeural"] = 3] = "OfflineNeural";
  16287. /**
  16288. * Offline standard voices.
  16289. */
  16290. SynthesisVoiceType[SynthesisVoiceType["OfflineStandard"] = 4] = "OfflineStandard";
  16291. /**
  16292. * High definition (HD) voices. Refer to https://learn.microsoft.com/azure/ai-services/speech-service/high-definition-voices
  16293. */
  16294. SynthesisVoiceType[SynthesisVoiceType["OnlineNeuralHD"] = 5] = "OnlineNeuralHD";
  16295. })(SynthesisVoiceType = exports.SynthesisVoiceType || (exports.SynthesisVoiceType = {}));
  16296. const GENDER_LOOKUP = {
  16297. [SynthesisVoiceGender[SynthesisVoiceGender.Neutral]]: SynthesisVoiceGender.Neutral,
  16298. [SynthesisVoiceGender[SynthesisVoiceGender.Male]]: SynthesisVoiceGender.Male,
  16299. [SynthesisVoiceGender[SynthesisVoiceGender.Female]]: SynthesisVoiceGender.Female,
  16300. };
  16301. const VOICE_TYPE_LOOKUP = {
  16302. Neural: SynthesisVoiceType.OnlineNeural,
  16303. NeuralHD: SynthesisVoiceType.OnlineNeuralHD,
  16304. };
  16305. /**
  16306. * Information about Speech Synthesis voice
  16307. * Added in version 1.20.0.
  16308. * @class VoiceInfo
  16309. */
  16310. class VoiceInfo {
  16311. constructor(json) {
  16312. this.privStyleList = [];
  16313. if (!!json) {
  16314. this.privName = json.Name;
  16315. this.privLocale = json.Locale;
  16316. this.privShortName = json.ShortName;
  16317. this.privLocaleName = json.LocaleName;
  16318. this.privDisplayName = json.DisplayName;
  16319. this.privLocalName = json.LocalName;
  16320. this.privVoiceType = VOICE_TYPE_LOOKUP[json.VoiceType] || SynthesisVoiceType.Unknown;
  16321. this.privGender = GENDER_LOOKUP[json.Gender] || SynthesisVoiceGender.Unknown;
  16322. if (!!json.StyleList && Array.isArray(json.StyleList)) {
  16323. for (const style of json.StyleList) {
  16324. this.privStyleList.push(style);
  16325. }
  16326. }
  16327. this.privSampleRateHertz = json.SampleRateHertz;
  16328. this.privStatus = json.Status;
  16329. if (json.ExtendedPropertyMap) {
  16330. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  16331. this.privExtendedPropertyMap = json.ExtendedPropertyMap;
  16332. }
  16333. this.privWordsPerMinute = json.WordsPerMinute;
  16334. if (Array.isArray(json.SecondaryLocaleList)) {
  16335. this.privSecondaryLocaleList = [...json.SecondaryLocaleList];
  16336. }
  16337. if (Array.isArray(json.RolePlayList)) {
  16338. this.privRolePlayList = [...json.RolePlayList];
  16339. }
  16340. if (json.VoiceTag) {
  16341. this.privVoiceTag = json.VoiceTag;
  16342. }
  16343. }
  16344. }
  16345. get name() {
  16346. return this.privName;
  16347. }
  16348. get locale() {
  16349. return this.privLocale;
  16350. }
  16351. get shortName() {
  16352. return this.privShortName;
  16353. }
  16354. get displayName() {
  16355. return this.privDisplayName;
  16356. }
  16357. get localName() {
  16358. return this.privLocalName;
  16359. }
  16360. get localeName() {
  16361. return this.privLocaleName;
  16362. }
  16363. get gender() {
  16364. return this.privGender;
  16365. }
  16366. get voiceType() {
  16367. return this.privVoiceType;
  16368. }
  16369. get styleList() {
  16370. return this.privStyleList;
  16371. }
  16372. get sampleRateHertz() {
  16373. return this.privSampleRateHertz;
  16374. }
  16375. get status() {
  16376. return this.privStatus;
  16377. }
  16378. get extendedPropertyMap() {
  16379. // eslint-disable-next-line @typescript-eslint/no-unsafe-return
  16380. return this.privExtendedPropertyMap;
  16381. }
  16382. get wordsPerMinute() {
  16383. return this.privWordsPerMinute;
  16384. }
  16385. get secondaryLocaleList() {
  16386. return this.privSecondaryLocaleList;
  16387. }
  16388. get rolePlayList() {
  16389. return this.privRolePlayList;
  16390. }
  16391. get voiceTag() {
  16392. return this.privVoiceTag;
  16393. }
  16394. }
  16395. exports.VoiceInfo = VoiceInfo;
  16396. /***/ }),
  16397. /* 186 */
  16398. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  16399. "use strict";
  16400. // Copyright (c) Microsoft Corporation. All rights reserved.
  16401. // Licensed under the MIT license.
  16402. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16403. exports.SpeakerAudioDestination = void 0;
  16404. const Exports_js_1 = __webpack_require__(4);
  16405. const AudioOutputStream_js_1 = __webpack_require__(84);
  16406. const AudioStreamFormat_js_1 = __webpack_require__(67);
  16407. const MediaDurationPlaceholderSeconds = 60 * 30;
  16408. const AudioFormatToMimeType = {
  16409. [AudioStreamFormat_js_1.AudioFormatTag.PCM]: "audio/wav",
  16410. [AudioStreamFormat_js_1.AudioFormatTag.MuLaw]: "audio/x-wav",
  16411. [AudioStreamFormat_js_1.AudioFormatTag.MP3]: "audio/mpeg",
  16412. [AudioStreamFormat_js_1.AudioFormatTag.OGG_OPUS]: "audio/ogg",
  16413. [AudioStreamFormat_js_1.AudioFormatTag.WEBM_OPUS]: "audio/webm; codecs=opus",
  16414. [AudioStreamFormat_js_1.AudioFormatTag.ALaw]: "audio/x-wav",
  16415. [AudioStreamFormat_js_1.AudioFormatTag.FLAC]: "audio/flac",
  16416. [AudioStreamFormat_js_1.AudioFormatTag.AMR_WB]: "audio/amr-wb",
  16417. [AudioStreamFormat_js_1.AudioFormatTag.G722]: "audio/G722",
  16418. };
  16419. /**
  16420. * Represents the speaker playback audio destination, which only works in browser.
  16421. * Note: the SDK will try to use <a href="https://www.w3.org/TR/media-source/">Media Source Extensions</a> to play audio.
  16422. * Mp3 format has better supports on Microsoft Edge, Chrome and Safari (desktop), so, it's better to specify mp3 format for playback.
  16423. * @class SpeakerAudioDestination
  16424. * Updated in version 1.17.0
  16425. */
  16426. class SpeakerAudioDestination {
  16427. constructor(audioDestinationId) {
  16428. this.privPlaybackStarted = false;
  16429. this.privAppendingToBuffer = false;
  16430. this.privMediaSourceOpened = false;
  16431. this.privBytesReceived = 0;
  16432. this.privId = audioDestinationId ? audioDestinationId : (0, Exports_js_1.createNoDashGuid)();
  16433. this.privIsPaused = false;
  16434. this.privIsClosed = false;
  16435. }
  16436. id() {
  16437. return this.privId;
  16438. }
  16439. write(buffer, cb, err) {
  16440. if (this.privAudioBuffer !== undefined) {
  16441. this.privAudioBuffer.push(buffer);
  16442. this.updateSourceBuffer().then(() => {
  16443. if (!!cb) {
  16444. cb();
  16445. }
  16446. }, (error) => {
  16447. if (!!err) {
  16448. err(error);
  16449. }
  16450. });
  16451. }
  16452. else if (this.privAudioOutputStream !== undefined) {
  16453. this.privAudioOutputStream.write(buffer);
  16454. this.privBytesReceived += buffer.byteLength;
  16455. }
  16456. }
  16457. close(cb, err) {
  16458. this.privIsClosed = true;
  16459. if (this.privSourceBuffer !== undefined) {
  16460. this.handleSourceBufferUpdateEnd().then(() => {
  16461. if (!!cb) {
  16462. cb();
  16463. }
  16464. }, (error) => {
  16465. if (!!err) {
  16466. err(error);
  16467. }
  16468. });
  16469. }
  16470. else if (this.privAudioOutputStream !== undefined && typeof window !== "undefined") {
  16471. if ((this.privFormat.formatTag === AudioStreamFormat_js_1.AudioFormatTag.PCM || this.privFormat.formatTag === AudioStreamFormat_js_1.AudioFormatTag.MuLaw
  16472. || this.privFormat.formatTag === AudioStreamFormat_js_1.AudioFormatTag.ALaw) && this.privFormat.hasHeader === false) {
  16473. // eslint-disable-next-line no-console
  16474. console.warn("Play back is not supported for raw PCM, mulaw or alaw format without header.");
  16475. if (!!this.onAudioEnd) {
  16476. this.onAudioEnd(this);
  16477. }
  16478. }
  16479. else {
  16480. let receivedAudio = new ArrayBuffer(this.privBytesReceived);
  16481. this.privAudioOutputStream.read(receivedAudio).then(() => {
  16482. receivedAudio = this.privFormat.addHeader(receivedAudio);
  16483. const audioBlob = new Blob([receivedAudio], { type: AudioFormatToMimeType[this.privFormat.formatTag] });
  16484. this.privAudio.src = window.URL.createObjectURL(audioBlob);
  16485. this.notifyPlayback().then(() => {
  16486. if (!!cb) {
  16487. cb();
  16488. }
  16489. }, (error) => {
  16490. if (!!err) {
  16491. err(error);
  16492. }
  16493. });
  16494. }, (error) => {
  16495. if (!!err) {
  16496. err(error);
  16497. }
  16498. });
  16499. }
  16500. }
  16501. else {
  16502. // unsupported format, call onAudioEnd directly.
  16503. if (!!this.onAudioEnd) {
  16504. this.onAudioEnd(this);
  16505. }
  16506. }
  16507. }
  16508. set format(format) {
  16509. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
  16510. if (typeof (AudioContext) !== "undefined" || (typeof (window) !== "undefined" && typeof (window.webkitAudioContext) !== "undefined")) {
  16511. this.privFormat = format;
  16512. const mimeType = AudioFormatToMimeType[this.privFormat.formatTag];
  16513. if (mimeType === undefined) {
  16514. // eslint-disable-next-line no-console
  16515. console.warn(`Unknown mimeType for format ${AudioStreamFormat_js_1.AudioFormatTag[this.privFormat.formatTag]}; playback is not supported.`);
  16516. }
  16517. else if (typeof (MediaSource) !== "undefined" && MediaSource.isTypeSupported(mimeType)) {
  16518. this.privAudio = new Audio();
  16519. this.privAudioBuffer = [];
  16520. this.privMediaSource = new MediaSource();
  16521. this.privAudio.src = URL.createObjectURL(this.privMediaSource);
  16522. this.privAudio.load();
  16523. this.privMediaSource.onsourceopen = () => {
  16524. this.privMediaSourceOpened = true;
  16525. this.privMediaSource.duration = MediaDurationPlaceholderSeconds;
  16526. this.privSourceBuffer = this.privMediaSource.addSourceBuffer(mimeType);
  16527. this.privSourceBuffer.onupdate = () => {
  16528. this.updateSourceBuffer().catch((reason) => {
  16529. Exports_js_1.Events.instance.onEvent(new Exports_js_1.BackgroundEvent(reason));
  16530. });
  16531. };
  16532. this.privSourceBuffer.onupdateend = () => {
  16533. this.handleSourceBufferUpdateEnd().catch((reason) => {
  16534. Exports_js_1.Events.instance.onEvent(new Exports_js_1.BackgroundEvent(reason));
  16535. });
  16536. };
  16537. this.privSourceBuffer.onupdatestart = () => {
  16538. this.privAppendingToBuffer = false;
  16539. };
  16540. };
  16541. this.updateSourceBuffer().catch((reason) => {
  16542. Exports_js_1.Events.instance.onEvent(new Exports_js_1.BackgroundEvent(reason));
  16543. });
  16544. }
  16545. else {
  16546. // eslint-disable-next-line no-console
  16547. console.warn(`Format ${AudioStreamFormat_js_1.AudioFormatTag[this.privFormat.formatTag]} could not be played by MSE, streaming playback is not enabled.`);
  16548. this.privAudioOutputStream = new AudioOutputStream_js_1.PullAudioOutputStreamImpl();
  16549. this.privAudioOutputStream.format = this.privFormat;
  16550. this.privAudio = new Audio();
  16551. }
  16552. }
  16553. }
  16554. get volume() {
  16555. return this.privAudio?.volume ?? -1;
  16556. }
  16557. set volume(volume) {
  16558. if (!!this.privAudio) {
  16559. this.privAudio.volume = volume;
  16560. }
  16561. }
  16562. mute() {
  16563. if (!!this.privAudio) {
  16564. this.privAudio.muted = true;
  16565. }
  16566. }
  16567. unmute() {
  16568. if (!!this.privAudio) {
  16569. this.privAudio.muted = false;
  16570. }
  16571. }
  16572. get isClosed() {
  16573. return this.privIsClosed;
  16574. }
  16575. get currentTime() {
  16576. if (this.privAudio !== undefined) {
  16577. return this.privAudio.currentTime;
  16578. }
  16579. return -1;
  16580. }
  16581. pause() {
  16582. if (!this.privIsPaused && this.privAudio !== undefined) {
  16583. this.privAudio.pause();
  16584. this.privIsPaused = true;
  16585. }
  16586. }
  16587. resume(cb, err) {
  16588. if (this.privIsPaused && this.privAudio !== undefined) {
  16589. this.privAudio.play().then(() => {
  16590. if (!!cb) {
  16591. cb();
  16592. }
  16593. }, (error) => {
  16594. if (!!err) {
  16595. err(error);
  16596. }
  16597. });
  16598. this.privIsPaused = false;
  16599. }
  16600. }
  16601. get internalAudio() {
  16602. return this.privAudio;
  16603. }
  16604. async updateSourceBuffer() {
  16605. if (this.privAudioBuffer !== undefined && (this.privAudioBuffer.length > 0) && this.sourceBufferAvailable()) {
  16606. this.privAppendingToBuffer = true;
  16607. const binary = this.privAudioBuffer.shift();
  16608. try {
  16609. this.privSourceBuffer.appendBuffer(binary);
  16610. }
  16611. catch (error) {
  16612. this.privAudioBuffer.unshift(binary);
  16613. // eslint-disable-next-line no-console
  16614. console.log("buffer filled, pausing addition of binaries until space is made");
  16615. return;
  16616. }
  16617. await this.notifyPlayback();
  16618. }
  16619. else if (this.canEndStream()) {
  16620. await this.handleSourceBufferUpdateEnd();
  16621. }
  16622. }
  16623. async handleSourceBufferUpdateEnd() {
  16624. if (this.canEndStream() && this.sourceBufferAvailable()) {
  16625. this.privMediaSource.endOfStream();
  16626. await this.notifyPlayback();
  16627. }
  16628. }
  16629. async notifyPlayback() {
  16630. if (!this.privPlaybackStarted && this.privAudio !== undefined) {
  16631. this.privPlaybackStarted = true;
  16632. if (!!this.onAudioStart) {
  16633. this.onAudioStart(this);
  16634. }
  16635. this.privAudio.onended = () => {
  16636. if (!!this.onAudioEnd) {
  16637. this.onAudioEnd(this);
  16638. }
  16639. };
  16640. if (!this.privIsPaused) {
  16641. await this.privAudio.play();
  16642. }
  16643. }
  16644. }
  16645. canEndStream() {
  16646. return (this.isClosed && this.privSourceBuffer !== undefined && (this.privAudioBuffer.length === 0)
  16647. && this.privMediaSourceOpened && !this.privAppendingToBuffer && this.privMediaSource.readyState === "open");
  16648. }
  16649. sourceBufferAvailable() {
  16650. return (this.privSourceBuffer !== undefined && !this.privSourceBuffer.updating);
  16651. }
  16652. }
  16653. exports.SpeakerAudioDestination = SpeakerAudioDestination;
  16654. /***/ }),
  16655. /* 187 */
  16656. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  16657. "use strict";
  16658. // Copyright (c) Microsoft Corporation. All rights reserved.
  16659. // Licensed under the MIT license.
  16660. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16661. exports.ConversationTranscriptionCanceledEventArgs = void 0;
  16662. const CancellationEventArgsBase_js_1 = __webpack_require__(101);
  16663. /**
  16664. * Defines content of a RecognitionErrorEvent.
  16665. * @class ConversationTranscriptionCanceledEventArgs
  16666. */
  16667. class ConversationTranscriptionCanceledEventArgs extends CancellationEventArgsBase_js_1.CancellationEventArgsBase {
  16668. }
  16669. exports.ConversationTranscriptionCanceledEventArgs = ConversationTranscriptionCanceledEventArgs;
  16670. /***/ }),
  16671. /* 188 */
  16672. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  16673. "use strict";
  16674. // Copyright (c) Microsoft Corporation. All rights reserved.
  16675. // Licensed under the MIT license.
  16676. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16677. exports.MeetingTranscriptionCanceledEventArgs = void 0;
  16678. const CancellationEventArgsBase_js_1 = __webpack_require__(101);
  16679. /**
  16680. * Defines content of a MeetingTranscriptionCanceledEvent.
  16681. * @class MeetingTranscriptionCanceledEventArgs
  16682. */
  16683. class MeetingTranscriptionCanceledEventArgs extends CancellationEventArgsBase_js_1.CancellationEventArgsBase {
  16684. }
  16685. exports.MeetingTranscriptionCanceledEventArgs = MeetingTranscriptionCanceledEventArgs;
  16686. /***/ }),
  16687. /* 189 */
  16688. /***/ ((__unused_webpack_module, exports) => {
  16689. "use strict";
  16690. // Copyright (c) Microsoft Corporation. All rights reserved.
  16691. // Licensed under the MIT license.
  16692. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16693. exports.PronunciationAssessmentGradingSystem = void 0;
  16694. /**
  16695. * Defines the point system for pronunciation score calibration; default value is FivePoint.
  16696. * Added in version 1.15.0
  16697. * @class PronunciationAssessmentGradingSystem
  16698. */
  16699. var PronunciationAssessmentGradingSystem;
  16700. (function (PronunciationAssessmentGradingSystem) {
  16701. /**
  16702. * Five point calibration
  16703. * @member PronunciationAssessmentGradingSystem.FivePoint
  16704. */
  16705. PronunciationAssessmentGradingSystem[PronunciationAssessmentGradingSystem["FivePoint"] = 1] = "FivePoint";
  16706. /**
  16707. * Hundred mark
  16708. * @member PronunciationAssessmentGradingSystem.HundredMark
  16709. */
  16710. PronunciationAssessmentGradingSystem[PronunciationAssessmentGradingSystem["HundredMark"] = 2] = "HundredMark";
  16711. })(PronunciationAssessmentGradingSystem = exports.PronunciationAssessmentGradingSystem || (exports.PronunciationAssessmentGradingSystem = {}));
  16712. /***/ }),
  16713. /* 190 */
  16714. /***/ ((__unused_webpack_module, exports) => {
  16715. "use strict";
  16716. // Copyright (c) Microsoft Corporation. All rights reserved.
  16717. // Licensed under the MIT license.
  16718. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16719. exports.PronunciationAssessmentGranularity = void 0;
  16720. /**
  16721. * Defines the pronunciation evaluation granularity; default value is Phoneme.
  16722. * Added in version 1.15.0
  16723. * @class PronunciationAssessmentGranularity
  16724. */
  16725. var PronunciationAssessmentGranularity;
  16726. (function (PronunciationAssessmentGranularity) {
  16727. /**
  16728. * Shows the score on the full text, word and phoneme level
  16729. * @member PronunciationAssessmentGranularity.Phoneme
  16730. */
  16731. PronunciationAssessmentGranularity[PronunciationAssessmentGranularity["Phoneme"] = 1] = "Phoneme";
  16732. /**
  16733. * Shows the score on the full text and word level
  16734. * @member PronunciationAssessmentGranularity.Word
  16735. */
  16736. PronunciationAssessmentGranularity[PronunciationAssessmentGranularity["Word"] = 2] = "Word";
  16737. /**
  16738. * Shows the score on the full text level only
  16739. * @member PronunciationAssessmentGranularity.FullText
  16740. */
  16741. PronunciationAssessmentGranularity[PronunciationAssessmentGranularity["FullText"] = 3] = "FullText";
  16742. })(PronunciationAssessmentGranularity = exports.PronunciationAssessmentGranularity || (exports.PronunciationAssessmentGranularity = {}));
  16743. /***/ }),
  16744. /* 191 */
  16745. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  16746. "use strict";
  16747. // Copyright (c) Microsoft Corporation. All rights reserved.
  16748. // Licensed under the MIT license.
  16749. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16750. exports.PronunciationAssessmentConfig = void 0;
  16751. const Contracts_js_1 = __webpack_require__(64);
  16752. const Exports_js_1 = __webpack_require__(79);
  16753. /**
  16754. * Pronunciation assessment configuration.
  16755. * @class PronunciationAssessmentConfig
  16756. * Added in version 1.15.0.
  16757. */
  16758. class PronunciationAssessmentConfig {
  16759. /**
  16760. * PronunciationAssessmentConfig constructor.
  16761. * @constructor
  16762. * @param {string} referenceText
  16763. * @param gradingSystem
  16764. * @param granularity
  16765. * @param enableMiscue
  16766. */
  16767. constructor(referenceText, gradingSystem = Exports_js_1.PronunciationAssessmentGradingSystem.FivePoint, granularity = Exports_js_1.PronunciationAssessmentGranularity.Phoneme, enableMiscue = false) {
  16768. Contracts_js_1.Contracts.throwIfNullOrUndefined(referenceText, "referenceText");
  16769. this.privProperties = new Exports_js_1.PropertyCollection();
  16770. this.privProperties.setProperty(Exports_js_1.PropertyId.PronunciationAssessment_ReferenceText, referenceText);
  16771. this.privProperties.setProperty(Exports_js_1.PropertyId.PronunciationAssessment_GradingSystem, Exports_js_1.PronunciationAssessmentGradingSystem[gradingSystem]);
  16772. this.privProperties.setProperty(Exports_js_1.PropertyId.PronunciationAssessment_Granularity, Exports_js_1.PronunciationAssessmentGranularity[granularity]);
  16773. this.privProperties.setProperty(Exports_js_1.PropertyId.PronunciationAssessment_EnableMiscue, String(enableMiscue));
  16774. }
  16775. /**
  16776. * @member PronunciationAssessmentConfig.fromJSON
  16777. * @function
  16778. * @public
  16779. * @param {string} json The json string containing the pronunciation assessment parameters.
  16780. * @return {PronunciationAssessmentConfig} Instance of PronunciationAssessmentConfig
  16781. * @summary Creates an instance of the PronunciationAssessmentConfig from json.
  16782. * This method is designed to support the pronunciation assessment parameters still in preview.
  16783. * Under normal circumstances, use the constructor instead.
  16784. */
  16785. static fromJSON(json) {
  16786. Contracts_js_1.Contracts.throwIfNullOrUndefined(json, "json");
  16787. const config = new PronunciationAssessmentConfig("");
  16788. config.privProperties = new Exports_js_1.PropertyCollection();
  16789. config.properties.setProperty(Exports_js_1.PropertyId.PronunciationAssessment_Json, json);
  16790. return config;
  16791. }
  16792. toJSON() {
  16793. this.updateJson();
  16794. return this.privProperties.getProperty(Exports_js_1.PropertyId.PronunciationAssessment_Params);
  16795. }
  16796. applyTo(recognizer) {
  16797. this.updateJson();
  16798. const recoBase = recognizer.internalData;
  16799. recoBase.expectContentAssessmentResponse = !!this.privContentAssessmentTopic;
  16800. recoBase.speechContext.setPronunciationAssessmentParams(this.properties.getProperty(Exports_js_1.PropertyId.PronunciationAssessment_Params), this.privContentAssessmentTopic, recoBase.isSpeakerDiarizationEnabled);
  16801. }
  16802. /**
  16803. * Gets the reference text.
  16804. * @member PronunciationAssessmentConfig.prototype.referenceText
  16805. * @function
  16806. * @public
  16807. * @returns {string} Reference text.
  16808. */
  16809. get referenceText() {
  16810. return this.properties.getProperty(Exports_js_1.PropertyId.PronunciationAssessment_ReferenceText);
  16811. }
  16812. /**
  16813. * Gets/Sets the reference text.
  16814. * @member PronunciationAssessmentConfig.prototype.referenceText
  16815. * @function
  16816. * @public
  16817. * @param {string} referenceText - Reference text.
  16818. */
  16819. set referenceText(referenceText) {
  16820. Contracts_js_1.Contracts.throwIfNullOrWhitespace(referenceText, "referenceText");
  16821. this.properties.setProperty(Exports_js_1.PropertyId.PronunciationAssessment_ReferenceText, referenceText);
  16822. }
  16823. /**
  16824. * Sets the phoneme alphabet.
  16825. * The valid values are "SAPI" (default) and "IPA".
  16826. * Added in version 1.20.0
  16827. * @member PronunciationAssessmentConfig.prototype.phonemeAlphabet
  16828. * @function
  16829. * @public
  16830. * @param {string} phonemeAlphabet - Phoneme alphabet.
  16831. */
  16832. set phonemeAlphabet(phonemeAlphabet) {
  16833. Contracts_js_1.Contracts.throwIfNullOrWhitespace(phonemeAlphabet, "phonemeAlphabet");
  16834. this.privPhonemeAlphabet = phonemeAlphabet;
  16835. }
  16836. /**
  16837. * Sets the boolean enableMiscue property.
  16838. * Added in version 1.26.0
  16839. * @member PronunciationAssessmentConfig.prototype.enableMiscue
  16840. * @function
  16841. * @public
  16842. * @param {boolean} enableMiscue - enable miscue.
  16843. */
  16844. set enableMiscue(enableMiscue) {
  16845. const enableMiscueString = enableMiscue ? "true" : "false";
  16846. this.properties.setProperty(Exports_js_1.PropertyId.PronunciationAssessment_EnableMiscue, enableMiscueString);
  16847. }
  16848. /**
  16849. * Gets the boolean enableMiscue property.
  16850. * Added in version 1.26.0
  16851. * @member PronunciationAssessmentConfig.prototype.enableMiscue
  16852. * @function
  16853. * @public
  16854. * @return {boolean} enableMiscue - enable miscue.
  16855. */
  16856. get enableMiscue() {
  16857. const enableMiscueString = this.properties.getProperty(Exports_js_1.PropertyId.PronunciationAssessment_EnableMiscue, "false");
  16858. return (enableMiscueString.toLowerCase() === "true");
  16859. }
  16860. /**
  16861. * Sets the nbest phoneme count
  16862. * Added in version 1.20.0
  16863. * @member PronunciationAssessmentConfig.prototype.nbestPhonemeCount
  16864. * @function
  16865. * @public
  16866. * @param {number} nbestPhonemeCount - NBest phoneme count.
  16867. */
  16868. set nbestPhonemeCount(nbestPhonemeCount) {
  16869. this.privNBestPhonemeCount = nbestPhonemeCount;
  16870. }
  16871. /**
  16872. * Enables the prosody assessment.
  16873. * Added in version 1.34.0
  16874. * @member PronunciationAssessmentConfig.prototype.enableProsodyAssessment
  16875. * @function
  16876. * @public
  16877. * @param {boolean} enableProsodyAssessment - enable prosody assessment.
  16878. */
  16879. set enableProsodyAssessment(enableProsodyAssessment) {
  16880. this.privEnableProsodyAssessment = enableProsodyAssessment;
  16881. }
  16882. /**
  16883. * Enables content assessment and sets the topic.
  16884. * Added in version 1.34.0
  16885. * @member PronunciationAssessmentConfig.prototype.enableContentAssessmentWithTopic
  16886. * @function
  16887. * @public
  16888. * @param {string} topic - Topic for content assessment.
  16889. */
  16890. enableContentAssessmentWithTopic(topic) {
  16891. this.privContentAssessmentTopic = topic;
  16892. }
  16893. /**
  16894. * @member PronunciationAssessmentConfig.prototype.properties
  16895. * @function
  16896. * @public
  16897. * @return {PropertyCollection} Properties of the config.
  16898. * @summary Gets a pronunciation assessment config properties
  16899. */
  16900. get properties() {
  16901. return this.privProperties;
  16902. }
  16903. updateJson() {
  16904. const jsonString = this.privProperties.getProperty(Exports_js_1.PropertyId.PronunciationAssessment_Json, "{}");
  16905. const paramsJson = JSON.parse(jsonString);
  16906. const referenceText = this.privProperties.getProperty(Exports_js_1.PropertyId.PronunciationAssessment_ReferenceText);
  16907. if (referenceText) {
  16908. paramsJson.referenceText = referenceText;
  16909. }
  16910. const gradingSystem = this.privProperties.getProperty(Exports_js_1.PropertyId.PronunciationAssessment_GradingSystem);
  16911. if (gradingSystem) {
  16912. paramsJson.gradingSystem = gradingSystem;
  16913. }
  16914. const granularity = this.privProperties.getProperty(Exports_js_1.PropertyId.PronunciationAssessment_Granularity);
  16915. if (granularity) {
  16916. paramsJson.granularity = granularity;
  16917. }
  16918. if (this.privPhonemeAlphabet) {
  16919. paramsJson.phonemeAlphabet = this.privPhonemeAlphabet;
  16920. }
  16921. if (this.privNBestPhonemeCount) {
  16922. paramsJson.nbestPhonemeCount = this.privNBestPhonemeCount;
  16923. }
  16924. paramsJson.enableProsodyAssessment = this.privEnableProsodyAssessment;
  16925. // always set dimension to Comprehensive
  16926. paramsJson.dimension = "Comprehensive";
  16927. const enableMiscueString = this.privProperties.getProperty(Exports_js_1.PropertyId.PronunciationAssessment_EnableMiscue);
  16928. if (enableMiscueString) {
  16929. paramsJson.enableMiscue = this.enableMiscue;
  16930. }
  16931. this.privProperties.setProperty(Exports_js_1.PropertyId.PronunciationAssessment_Params, JSON.stringify(paramsJson));
  16932. }
  16933. }
  16934. exports.PronunciationAssessmentConfig = PronunciationAssessmentConfig;
  16935. /***/ }),
  16936. /* 192 */
  16937. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  16938. "use strict";
  16939. // Copyright (c) Microsoft Corporation. All rights reserved.
  16940. // Licensed under the MIT license.
  16941. Object.defineProperty(exports, "__esModule", ({ value: true }));
  16942. exports.PronunciationAssessmentResult = exports.ContentAssessmentResult = void 0;
  16943. /* eslint-disable max-classes-per-file */
  16944. const Contracts_js_1 = __webpack_require__(64);
  16945. const Exports_js_1 = __webpack_require__(79);
  16946. class ContentAssessmentResult {
  16947. /**
  16948. * @Internal
  16949. * Do not use externally.
  16950. */
  16951. constructor(detailResult) {
  16952. this.privPronJson = detailResult;
  16953. }
  16954. /**
  16955. * Correctness in using grammar and variety of sentence patterns.
  16956. * Grammatical errors are jointly evaluated by lexical accuracy,
  16957. * grammatical accuracy and diversity of sentence structures.
  16958. * @member ContentAssessmentResult.prototype.grammarScore
  16959. * @function
  16960. * @public
  16961. * @returns {number} Grammar score.
  16962. */
  16963. get grammarScore() {
  16964. return this.privPronJson.ContentAssessment.GrammarScore;
  16965. }
  16966. /**
  16967. * Proficiency in lexical usage. It evaluates the speaker's effective usage
  16968. * of words and their appropriateness within the given context to express
  16969. * ideas accurately, as well as level of lexical complexity.
  16970. * @member ContentAssessmentResult.prototype.vocabularyScore
  16971. * @function
  16972. * @public
  16973. * @returns {number} Vocabulary score.
  16974. */
  16975. get vocabularyScore() {
  16976. return this.privPronJson.ContentAssessment.VocabularyScore;
  16977. }
  16978. /**
  16979. * Level of understanding and engagement with the topic, which provides
  16980. * insights into the speaker’s ability to express their thoughts and ideas
  16981. * effectively and the ability to engage with the topic.
  16982. * @member ContentAssessmentResult.prototype.topicScore
  16983. * @function
  16984. * @public
  16985. * @returns {number} Topic score.
  16986. */
  16987. get topicScore() {
  16988. return this.privPronJson.ContentAssessment.TopicScore;
  16989. }
  16990. }
  16991. exports.ContentAssessmentResult = ContentAssessmentResult;
  16992. /**
  16993. * Pronunciation assessment results.
  16994. * @class PronunciationAssessmentResult
  16995. * Added in version 1.15.0.
  16996. */
  16997. class PronunciationAssessmentResult {
  16998. constructor(jsonString) {
  16999. const j = JSON.parse(jsonString);
  17000. Contracts_js_1.Contracts.throwIfNullOrUndefined(j.NBest[0], "NBest");
  17001. this.privPronJson = j.NBest[0];
  17002. }
  17003. /**
  17004. * @member PronunciationAssessmentResult.fromResult
  17005. * @function
  17006. * @public
  17007. * @param {RecognitionResult} result The recognition result.
  17008. * @return {PronunciationAssessmentConfig} Instance of PronunciationAssessmentConfig
  17009. * @summary Creates an instance of the PronunciationAssessmentResult from recognition result.
  17010. */
  17011. static fromResult(result) {
  17012. Contracts_js_1.Contracts.throwIfNullOrUndefined(result, "result");
  17013. const json = result.properties.getProperty(Exports_js_1.PropertyId.SpeechServiceResponse_JsonResult);
  17014. Contracts_js_1.Contracts.throwIfNullOrUndefined(json, "json");
  17015. return new PronunciationAssessmentResult(json);
  17016. }
  17017. /**
  17018. * Gets the detail result of pronunciation assessment.
  17019. * @member PronunciationAssessmentConfig.prototype.detailResult
  17020. * @function
  17021. * @public
  17022. * @returns {DetailResult} detail result.
  17023. */
  17024. get detailResult() {
  17025. return this.privPronJson;
  17026. }
  17027. /**
  17028. * The score indicating the pronunciation accuracy of the given speech, which indicates
  17029. * how closely the phonemes match a native speaker's pronunciation.
  17030. * @member PronunciationAssessmentResult.prototype.accuracyScore
  17031. * @function
  17032. * @public
  17033. * @returns {number} Accuracy score.
  17034. */
  17035. get accuracyScore() {
  17036. return this.detailResult.PronunciationAssessment?.AccuracyScore;
  17037. }
  17038. /**
  17039. * The overall score indicating the pronunciation quality of the given speech.
  17040. * This is calculated from AccuracyScore, FluencyScore and CompletenessScore with weight.
  17041. * @member PronunciationAssessmentResult.prototype.pronunciationScore
  17042. * @function
  17043. * @public
  17044. * @returns {number} Pronunciation score.
  17045. */
  17046. get pronunciationScore() {
  17047. return this.detailResult.PronunciationAssessment?.PronScore;
  17048. }
  17049. /**
  17050. * The score indicating the completeness of the given speech by calculating the ratio of pronounced words towards entire input.
  17051. * @member PronunciationAssessmentResult.prototype.completenessScore
  17052. * @function
  17053. * @public
  17054. * @returns {number} Completeness score.
  17055. */
  17056. get completenessScore() {
  17057. return this.detailResult.PronunciationAssessment?.CompletenessScore;
  17058. }
  17059. /**
  17060. * The score indicating the fluency of the given speech.
  17061. * @member PronunciationAssessmentResult.prototype.fluencyScore
  17062. * @function
  17063. * @public
  17064. * @returns {number} Fluency score.
  17065. */
  17066. get fluencyScore() {
  17067. return this.detailResult.PronunciationAssessment?.FluencyScore;
  17068. }
  17069. /**
  17070. * The prosody score, which indicates how nature of the given speech, including stress, intonation, speaking speed and rhythm.
  17071. * @member PronunciationAssessmentResult.prototype.prosodyScore
  17072. * @function
  17073. * @public
  17074. * @returns {number} Prosody score.
  17075. */
  17076. get prosodyScore() {
  17077. return this.detailResult.PronunciationAssessment?.ProsodyScore;
  17078. }
  17079. /**
  17080. * The concent assessment result.
  17081. * Only available when content assessment is enabled.
  17082. * @member PronunciationAssessmentResult.prototype.contentAssessmentResult
  17083. * @function
  17084. * @public
  17085. * @returns {ContentAssessmentResult} Content assessment result.
  17086. */
  17087. get contentAssessmentResult() {
  17088. if (this.detailResult.ContentAssessment === undefined) {
  17089. return undefined;
  17090. }
  17091. return new ContentAssessmentResult(this.detailResult);
  17092. }
  17093. }
  17094. exports.PronunciationAssessmentResult = PronunciationAssessmentResult;
  17095. /***/ }),
  17096. /* 193 */
  17097. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  17098. "use strict";
  17099. // Copyright (c) Microsoft Corporation. All rights reserved.
  17100. // Licensed under the MIT license.
  17101. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17102. exports.AvatarConfig = void 0;
  17103. const Contracts_js_1 = __webpack_require__(64);
  17104. const Exports_js_1 = __webpack_require__(79);
  17105. /**
  17106. * Defines the talking avatar configuration.
  17107. * @class AvatarConfig
  17108. * Added in version 1.33.0
  17109. *
  17110. * @experimental This feature is experimental and might change or have limited support.
  17111. */
  17112. class AvatarConfig {
  17113. /**
  17114. * Creates and initializes an instance of this class.
  17115. * @constructor
  17116. * @param {string} character - The avatar character.
  17117. * @param {string} style - The avatar style.
  17118. * @param {AvatarVideoFormat} videoFormat - The talking avatar output video format.
  17119. */
  17120. constructor(character, style, videoFormat) {
  17121. this.privCustomized = false;
  17122. this.privUseBuiltInVoice = false;
  17123. Contracts_js_1.Contracts.throwIfNullOrWhitespace(character, "character");
  17124. this.character = character;
  17125. this.style = style;
  17126. if (videoFormat === undefined) {
  17127. videoFormat = new Exports_js_1.AvatarVideoFormat();
  17128. }
  17129. this.videoFormat = videoFormat;
  17130. }
  17131. /**
  17132. * Indicates if the talking avatar is customized.
  17133. */
  17134. get customized() {
  17135. return this.privCustomized;
  17136. }
  17137. /**
  17138. * Sets if the talking avatar is customized.
  17139. */
  17140. set customized(value) {
  17141. this.privCustomized = value;
  17142. }
  17143. /**
  17144. * Indicates whether to use built-in voice for custom avatar.
  17145. */
  17146. get useBuiltInVoice() {
  17147. return this.privUseBuiltInVoice;
  17148. }
  17149. /**
  17150. * Sets whether to use built-in voice for custom avatar.
  17151. */
  17152. set useBuiltInVoice(value) {
  17153. this.privUseBuiltInVoice = value;
  17154. }
  17155. /**
  17156. * Gets the background color.
  17157. */
  17158. get backgroundColor() {
  17159. return this.privBackgroundColor;
  17160. }
  17161. /**
  17162. * Sets the background color.
  17163. */
  17164. set backgroundColor(value) {
  17165. this.privBackgroundColor = value;
  17166. }
  17167. /**
  17168. * Gets the background image.
  17169. */
  17170. get backgroundImage() {
  17171. return this.privBackgroundImage;
  17172. }
  17173. /**
  17174. * Sets the background image.
  17175. * @param {URL} value - The background image.
  17176. */
  17177. set backgroundImage(value) {
  17178. this.privBackgroundImage = value;
  17179. }
  17180. /**
  17181. * Gets the remote ICE servers.
  17182. * @remarks This method is designed to be used internally in the SDK.
  17183. * @returns {RTCIceServer[]} The remote ICE servers.
  17184. */
  17185. get remoteIceServers() {
  17186. return this.privRemoteIceServers;
  17187. }
  17188. /**
  17189. * Sets the remote ICE servers.
  17190. * @remarks Normally, the ICE servers are gathered from the PeerConnection,
  17191. * set this property to override the ICE servers. E.g., the ICE servers are
  17192. * different in client and server side.
  17193. * @param {RTCIceServer[]} value - The remote ICE servers.
  17194. */
  17195. set remoteIceServers(value) {
  17196. this.privRemoteIceServers = value;
  17197. }
  17198. }
  17199. exports.AvatarConfig = AvatarConfig;
  17200. /***/ }),
  17201. /* 194 */
  17202. /***/ ((__unused_webpack_module, exports) => {
  17203. "use strict";
  17204. // Copyright (c) Microsoft Corporation. All rights reserved.
  17205. // Licensed under the MIT license.
  17206. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17207. exports.AvatarEventArgs = exports.AvatarEventTypes = void 0;
  17208. var AvatarEventTypes;
  17209. (function (AvatarEventTypes) {
  17210. AvatarEventTypes["SwitchedToSpeaking"] = "SwitchedToSpeaking";
  17211. AvatarEventTypes["SwitchedToIdle"] = "SwitchedToIdle";
  17212. AvatarEventTypes["SessionClosed"] = "SessionClosed";
  17213. })(AvatarEventTypes = exports.AvatarEventTypes || (exports.AvatarEventTypes = {}));
  17214. /**
  17215. * Defines content for talking avatar events.
  17216. * @class AvatarEventArgs
  17217. * Added in version 1.33.0
  17218. *
  17219. * @experimental This feature is experimental and might change or have limited support.
  17220. */
  17221. class AvatarEventArgs {
  17222. /**
  17223. * Creates and initializes an instance of this class.
  17224. * @constructor
  17225. * @param {number} audioOffset - The audio offset.
  17226. * @param {string} description - The description of the event.
  17227. */
  17228. constructor(audioOffset, description) {
  17229. this.privOffset = audioOffset;
  17230. this.privDescription = description;
  17231. }
  17232. /**
  17233. * The type of the event.
  17234. * @public
  17235. * @returns {AvatarEventTypes} The type of the event.
  17236. */
  17237. get type() {
  17238. return this.privType;
  17239. }
  17240. /**
  17241. * The time offset associated with this event.
  17242. * @public
  17243. * @returns {number} The time offset associated with this event.
  17244. */
  17245. get offset() {
  17246. return this.privOffset;
  17247. }
  17248. /**
  17249. * The description of the event.
  17250. * @public
  17251. * @returns {string} The description of the event.
  17252. */
  17253. get description() {
  17254. return this.privDescription;
  17255. }
  17256. }
  17257. exports.AvatarEventArgs = AvatarEventArgs;
  17258. /***/ }),
  17259. /* 195 */
  17260. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  17261. "use strict";
  17262. // Copyright (c) Microsoft Corporation. All rights reserved.
  17263. // Licensed under the MIT license.
  17264. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17265. exports.AvatarSynthesizer = void 0;
  17266. const SpeechSynthesisConnectionFactory_js_1 = __webpack_require__(196);
  17267. const Exports_js_1 = __webpack_require__(2);
  17268. const Exports_js_2 = __webpack_require__(4);
  17269. const AudioOutputFormat_js_1 = __webpack_require__(85);
  17270. const Exports_js_3 = __webpack_require__(79);
  17271. const Contracts_js_1 = __webpack_require__(64);
  17272. const Synthesizer_js_1 = __webpack_require__(175);
  17273. /**
  17274. * Defines the avatar synthesizer.
  17275. * @class AvatarSynthesizer
  17276. * Added in version 1.33.0
  17277. *
  17278. * @experimental This feature is experimental and might change or have limited support.
  17279. */
  17280. class AvatarSynthesizer extends Exports_js_3.Synthesizer {
  17281. /**
  17282. * Creates and initializes an instance of this class.
  17283. * @constructor
  17284. * @param {SpeechConfig} speechConfig - The speech config.
  17285. * @param {AvatarConfig} avatarConfig - The talking avatar config.
  17286. */
  17287. constructor(speechConfig, avatarConfig) {
  17288. super(speechConfig);
  17289. Contracts_js_1.Contracts.throwIfNullOrUndefined(avatarConfig, "avatarConfig");
  17290. this.privConnectionFactory = new SpeechSynthesisConnectionFactory_js_1.SpeechSynthesisConnectionFactory();
  17291. this.privAvatarConfig = avatarConfig;
  17292. this.implCommonSynthesizeSetup();
  17293. }
  17294. implCommonSynthesizeSetup() {
  17295. super.implCommonSynthesizeSetup();
  17296. // The service checks the audio format setting while it ignores it in avatar synthesis.
  17297. this.privAdapter.audioOutputFormat = AudioOutputFormat_js_1.AudioOutputFormatImpl.fromSpeechSynthesisOutputFormat(Exports_js_3.SpeechSynthesisOutputFormat.Riff24Khz16BitMonoPcm);
  17298. }
  17299. /**
  17300. * Starts the talking avatar session and establishes the WebRTC connection.
  17301. * @member AvatarSynthesizer.prototype.startAvatarAsync
  17302. * @function
  17303. * @public
  17304. * @param {AvatarWebRTCConnectionInfo} peerConnection - The peer connection.
  17305. * @returns {Promise<SynthesisResult>} The promise of the connection result.
  17306. */
  17307. async startAvatarAsync(peerConnection) {
  17308. Contracts_js_1.Contracts.throwIfNullOrUndefined(peerConnection, "peerConnection");
  17309. this.privIceServers = peerConnection.getConfiguration().iceServers;
  17310. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privIceServers, "Ice servers must be set.");
  17311. const iceGatheringDone = new Exports_js_2.Deferred();
  17312. // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/icegatheringstatechange_event
  17313. peerConnection.onicegatheringstatechange = () => {
  17314. Exports_js_2.Events.instance.onEvent(new Exports_js_2.PlatformEvent("peer connection: ice gathering state: " + peerConnection.iceGatheringState, Exports_js_2.EventType.Debug));
  17315. if (peerConnection.iceGatheringState === "complete") {
  17316. Exports_js_2.Events.instance.onEvent(new Exports_js_2.PlatformEvent("peer connection: ice gathering complete.", Exports_js_2.EventType.Info));
  17317. iceGatheringDone.resolve();
  17318. }
  17319. };
  17320. peerConnection.onicecandidate = (event) => {
  17321. if (event.candidate) {
  17322. Exports_js_2.Events.instance.onEvent(new Exports_js_2.PlatformEvent("peer connection: ice candidate: " + event.candidate.candidate, Exports_js_2.EventType.Debug));
  17323. }
  17324. else {
  17325. Exports_js_2.Events.instance.onEvent(new Exports_js_2.PlatformEvent("peer connection: ice candidate: complete", Exports_js_2.EventType.Debug));
  17326. iceGatheringDone.resolve();
  17327. }
  17328. };
  17329. // Set a timeout for ice gathering, currently 2 seconds.
  17330. setTimeout(() => {
  17331. if (peerConnection.iceGatheringState !== "complete") {
  17332. Exports_js_2.Events.instance.onEvent(new Exports_js_2.PlatformEvent("peer connection: ice gathering timeout.", Exports_js_2.EventType.Warning));
  17333. iceGatheringDone.resolve();
  17334. }
  17335. }, 2000);
  17336. const sdp = await peerConnection.createOffer();
  17337. await peerConnection.setLocalDescription(sdp);
  17338. await iceGatheringDone.promise;
  17339. Exports_js_2.Events.instance.onEvent(new Exports_js_2.PlatformEvent("peer connection: got local SDP.", Exports_js_2.EventType.Info));
  17340. this.privProperties.setProperty(Exports_js_3.PropertyId.TalkingAvatarService_WebRTC_SDP, JSON.stringify(peerConnection.localDescription));
  17341. const result = await this.speak("", false);
  17342. if (result.reason !== Exports_js_3.ResultReason.SynthesizingAudioCompleted) {
  17343. return new Exports_js_3.SynthesisResult(result.resultId, result.reason, result.errorDetails, result.properties);
  17344. }
  17345. const sdpAnswerString = atob(result.properties.getProperty(Exports_js_3.PropertyId.TalkingAvatarService_WebRTC_SDP));
  17346. const sdpAnswer = new RTCSessionDescription(JSON.parse(sdpAnswerString));
  17347. await peerConnection.setRemoteDescription(sdpAnswer);
  17348. return new Exports_js_3.SynthesisResult(result.resultId, result.reason, undefined, result.properties);
  17349. }
  17350. /**
  17351. * Speaks plain text asynchronously. The rendered audio and video will be sent via the WebRTC connection.
  17352. * @member AvatarSynthesizer.prototype.speakTextAsync
  17353. * @function
  17354. * @public
  17355. * @param {string} text - The plain text to speak.
  17356. * @returns {Promise<SynthesisResult>} The promise of the synthesis result.
  17357. */
  17358. async speakTextAsync(text) {
  17359. const r = await this.speak(text, false);
  17360. return new Exports_js_3.SynthesisResult(r.resultId, r.reason, r.errorDetails, r.properties);
  17361. }
  17362. /**
  17363. * Speaks SSML asynchronously. The rendered audio and video will be sent via the WebRTC connection.
  17364. * @member AvatarSynthesizer.prototype.speakSsmlAsync
  17365. * @function
  17366. * @public
  17367. * @param {string} ssml - The SSML text to speak.
  17368. * @returns {Promise<SynthesisResult>} The promise of the synthesis result.
  17369. */
  17370. async speakSsmlAsync(ssml) {
  17371. const r = await this.speak(ssml, true);
  17372. return new Exports_js_3.SynthesisResult(r.resultId, r.reason, r.errorDetails, r.properties);
  17373. }
  17374. /**
  17375. * Speaks text asynchronously. The avatar will switch to idle state.
  17376. * @member AvatarSynthesizer.prototype.stopSpeakingAsync
  17377. * @function
  17378. * @public
  17379. * @returns {Promise<void>} The promise of the void result.
  17380. */
  17381. async stopSpeakingAsync() {
  17382. while (this.synthesisRequestQueue.length() > 0) {
  17383. const request = await this.synthesisRequestQueue.dequeue();
  17384. request.err("Synthesis is canceled by user.");
  17385. }
  17386. return this.privAdapter.stopSpeaking();
  17387. }
  17388. /**
  17389. * Stops the talking avatar session and closes the WebRTC connection.
  17390. * For now, this is the same as close().
  17391. * You need to create a new AvatarSynthesizer instance to start a new session.
  17392. * @member AvatarSynthesizer.prototype.stopAvatarAsync
  17393. * @function
  17394. * @public
  17395. * @returns {Promise<void>} The promise of the void result.
  17396. */
  17397. async stopAvatarAsync() {
  17398. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);
  17399. return this.dispose(true);
  17400. }
  17401. /**
  17402. * Dispose of associated resources.
  17403. * @member AvatarSynthesizer.prototype.close
  17404. * @function
  17405. * @public
  17406. */
  17407. async close() {
  17408. if (this.privDisposed) {
  17409. return;
  17410. }
  17411. return this.dispose(true);
  17412. }
  17413. /**
  17414. * Gets the ICE servers. Internal use only.
  17415. */
  17416. get iceServers() {
  17417. return this.privIceServers;
  17418. }
  17419. // Creates the synthesis adapter
  17420. createSynthesisAdapter(authentication, connectionFactory, synthesizerConfig) {
  17421. return new Exports_js_1.AvatarSynthesisAdapter(authentication, connectionFactory, synthesizerConfig, this, this.privAvatarConfig);
  17422. }
  17423. createRestSynthesisAdapter(_authentication, _synthesizerConfig) {
  17424. return undefined;
  17425. }
  17426. createSynthesizerConfig(speechConfig) {
  17427. const config = super.createSynthesizerConfig(speechConfig);
  17428. config.avatarEnabled = true;
  17429. return config;
  17430. }
  17431. async speak(text, isSSML) {
  17432. const requestId = (0, Exports_js_2.createNoDashGuid)();
  17433. const deferredResult = new Exports_js_2.Deferred();
  17434. this.synthesisRequestQueue.enqueue(new Synthesizer_js_1.SynthesisRequest(requestId, text, isSSML, (e) => {
  17435. deferredResult.resolve(e);
  17436. this.privSynthesizing = false;
  17437. void this.adapterSpeak();
  17438. }, (e) => {
  17439. deferredResult.reject(e);
  17440. this.privSynthesizing = false;
  17441. }));
  17442. void this.adapterSpeak();
  17443. return deferredResult.promise;
  17444. }
  17445. }
  17446. exports.AvatarSynthesizer = AvatarSynthesizer;
  17447. /***/ }),
  17448. /* 196 */
  17449. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  17450. "use strict";
  17451. // Copyright (c) Microsoft Corporation. All rights reserved.
  17452. // Licensed under the MIT license.
  17453. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17454. exports.SpeechSynthesisConnectionFactory = void 0;
  17455. const Exports_js_1 = __webpack_require__(60);
  17456. const Exports_js_2 = __webpack_require__(79);
  17457. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  17458. const Exports_js_3 = __webpack_require__(2);
  17459. const HeaderNames_js_1 = __webpack_require__(54);
  17460. const QueryParameterNames_js_1 = __webpack_require__(136);
  17461. class SpeechSynthesisConnectionFactory {
  17462. constructor() {
  17463. this.synthesisUri = "/tts/cognitiveservices/websocket/v1";
  17464. }
  17465. async create(config, authInfo, connectionId) {
  17466. let endpoint = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint, undefined);
  17467. const region = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region, undefined);
  17468. const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);
  17469. const endpointId = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_EndpointId, undefined);
  17470. const hostPrefix = (endpointId === undefined) ? "tts" : "voice";
  17471. const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, "wss://" + region + "." + hostPrefix + ".speech" + hostSuffix);
  17472. const queryParams = {};
  17473. const headers = {};
  17474. if (authInfo.token !== undefined && authInfo.token !== "") {
  17475. headers[authInfo.headerName] = authInfo.token;
  17476. }
  17477. headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;
  17478. if (endpointId !== undefined && endpointId !== "") {
  17479. if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.CustomVoiceDeploymentId) === -1) {
  17480. queryParams[QueryParameterNames_js_1.QueryParameterNames.CustomVoiceDeploymentId] = endpointId;
  17481. }
  17482. }
  17483. if (config.avatarEnabled) {
  17484. if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.EnableAvatar) === -1) {
  17485. queryParams[QueryParameterNames_js_1.QueryParameterNames.EnableAvatar] = "true";
  17486. }
  17487. }
  17488. if (!!endpoint) {
  17489. const endpointUrl = new URL(endpoint);
  17490. const pathName = endpointUrl.pathname;
  17491. if (pathName === "" || pathName === "/") {
  17492. // We need to generate the path, and we need to check for a redirect.
  17493. endpointUrl.pathname = this.synthesisUri;
  17494. endpoint = await ConnectionFactoryBase_js_1.ConnectionFactoryBase.getRedirectUrlFromEndpoint(endpointUrl.toString());
  17495. }
  17496. }
  17497. if (!endpoint) {
  17498. endpoint = host + this.synthesisUri;
  17499. }
  17500. config.parameters.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Url, endpoint);
  17501. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "false") === "true";
  17502. return new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_3.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromParameters(config.parameters), enableCompression, connectionId);
  17503. }
  17504. }
  17505. exports.SpeechSynthesisConnectionFactory = SpeechSynthesisConnectionFactory;
  17506. /***/ }),
  17507. /* 197 */
  17508. /***/ ((__unused_webpack_module, exports) => {
  17509. "use strict";
  17510. // Copyright (c) Microsoft Corporation. All rights reserved.
  17511. // Licensed under the MIT license.
  17512. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17513. exports.AvatarVideoFormat = exports.Coordinate = void 0;
  17514. /* eslint-disable max-classes-per-file */
  17515. /**
  17516. * Defines a coordinate in 2D space.
  17517. * @class Coordinate
  17518. * Added in version 1.33.0
  17519. */
  17520. class Coordinate {
  17521. constructor(x, y) {
  17522. this.x = x;
  17523. this.y = y;
  17524. }
  17525. }
  17526. exports.Coordinate = Coordinate;
  17527. /**
  17528. * Defines the avatar output video format.
  17529. * @class AvatarVideoFormat
  17530. * Added in version 1.33.0
  17531. *
  17532. * @experimental This feature is experimental and might change in the future.
  17533. */
  17534. class AvatarVideoFormat {
  17535. /**
  17536. * Creates and initializes an instance of this class.
  17537. * @constructor
  17538. * @param {string} codec - The video codec.
  17539. * @param {number} bitrate - The video bitrate.
  17540. * @param {number} width - The video width.
  17541. * @param {number} height - The video height.
  17542. */
  17543. constructor(codec = "H264", bitrate = 2000000, width = 1920, height = 1080) {
  17544. this.codec = codec;
  17545. this.bitrate = bitrate;
  17546. this.width = width;
  17547. this.height = height;
  17548. }
  17549. /**
  17550. * Sets the video crop range.
  17551. */
  17552. setCropRange(topLeft, bottomRight) {
  17553. this.cropRange = {
  17554. bottomRight,
  17555. topLeft,
  17556. };
  17557. }
  17558. }
  17559. exports.AvatarVideoFormat = AvatarVideoFormat;
  17560. /***/ }),
  17561. /* 198 */
  17562. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  17563. "use strict";
  17564. // Copyright (c) Microsoft Corporation. All rights reserved.
  17565. // Licensed under the MIT license.
  17566. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17567. exports.AvatarWebRTCConnectionResult = void 0;
  17568. const Exports_js_1 = __webpack_require__(79);
  17569. /**
  17570. * Defines the avatar WebRTC connection result.
  17571. * @class AvatarWebRTCConnectionResult
  17572. * Added in version 1.33.0
  17573. *
  17574. * @experimental This feature is experimental and might change in the future.
  17575. */
  17576. class AvatarWebRTCConnectionResult extends Exports_js_1.SynthesisResult {
  17577. /**
  17578. * Creates and initializes an instance of this class.
  17579. * @constructor
  17580. * @param {RTCSessionDescriptionInit} SDPAnswer - The SDP answer of WebRTC connection.
  17581. * @param {string} resultId - The result id.
  17582. * @param {ResultReason} reason - The reason.
  17583. * @param {string} errorDetails - Error details, if provided.
  17584. * @param {PropertyCollection} properties - Additional properties, if provided.
  17585. */
  17586. constructor(SDPAnswer, resultId, reason, errorDetails, properties) {
  17587. super(resultId, reason, errorDetails, properties);
  17588. this.privSDPAnswer = SDPAnswer;
  17589. }
  17590. /**
  17591. * Specifies SDP (Session Description Protocol) answer of WebRTC connection.
  17592. * @member AvatarWebRTCConnectionResult.prototype.SDPAnswer
  17593. * @function
  17594. * @public
  17595. * @returns {RTCSessionDescriptionInit} Specifies the SDP answer of WebRTC connection.
  17596. */
  17597. get SDPAnswer() {
  17598. return this.privSDPAnswer;
  17599. }
  17600. }
  17601. exports.AvatarWebRTCConnectionResult = AvatarWebRTCConnectionResult;
  17602. /***/ }),
  17603. /* 199 */
  17604. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  17605. "use strict";
  17606. //
  17607. // Copyright (c) Microsoft. All rights reserved.
  17608. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  17609. //
  17610. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17611. exports.Diagnostics = void 0;
  17612. const Exports_js_1 = __webpack_require__(60);
  17613. const Exports_js_2 = __webpack_require__(4);
  17614. /**
  17615. * Defines diagnostics API for managing console output
  17616. * Added in version 1.21.0
  17617. */
  17618. class Diagnostics {
  17619. static SetLoggingLevel(logLevel) {
  17620. this.privListener = new Exports_js_1.ConsoleLoggingListener(logLevel);
  17621. Exports_js_2.Events.instance.attachConsoleListener(this.privListener);
  17622. }
  17623. static StartConsoleOutput() {
  17624. if (!!this.privListener) {
  17625. this.privListener.enableConsoleOutput = true;
  17626. }
  17627. }
  17628. static StopConsoleOutput() {
  17629. if (!!this.privListener) {
  17630. this.privListener.enableConsoleOutput = false;
  17631. }
  17632. }
  17633. static SetLogOutputPath(path) {
  17634. if (typeof window === "undefined") {
  17635. if (!!this.privListener) {
  17636. this.privListener.logPath = path;
  17637. }
  17638. }
  17639. else {
  17640. throw new Error("File system logging not available in browser.");
  17641. }
  17642. }
  17643. static set onLogOutput(callback) {
  17644. if (!!this.privListener) {
  17645. this.privListener.logCallback = callback;
  17646. }
  17647. }
  17648. }
  17649. exports.Diagnostics = Diagnostics;
  17650. Diagnostics.privListener = undefined;
  17651. /***/ }),
  17652. /* 200 */
  17653. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  17654. "use strict";
  17655. // Copyright (c) Microsoft Corporation. All rights reserved.
  17656. // Licensed under the MIT license.
  17657. var __importDefault = (this && this.__importDefault) || function (mod) {
  17658. return (mod && mod.__esModule) ? mod : { "default": mod };
  17659. };
  17660. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17661. exports.RestMessageAdapter = exports.RestRequestType = void 0;
  17662. const bent_1 = __importDefault(__webpack_require__(201));
  17663. const Exports_js_1 = __webpack_require__(4);
  17664. var RestRequestType;
  17665. (function (RestRequestType) {
  17666. RestRequestType["Get"] = "GET";
  17667. RestRequestType["Post"] = "POST";
  17668. RestRequestType["Delete"] = "DELETE";
  17669. RestRequestType["File"] = "file";
  17670. })(RestRequestType = exports.RestRequestType || (exports.RestRequestType = {}));
  17671. // accept rest operations via request method and return abstracted objects from server response
  17672. class RestMessageAdapter {
  17673. constructor(configParams) {
  17674. if (!configParams) {
  17675. throw new Exports_js_1.ArgumentNullError("configParams");
  17676. }
  17677. this.privHeaders = configParams.headers;
  17678. this.privIgnoreCache = configParams.ignoreCache;
  17679. }
  17680. static extractHeaderValue(headerKey, headers) {
  17681. let headerValue = "";
  17682. try {
  17683. const arr = headers.trim().split(/[\r\n]+/);
  17684. const headerMap = {};
  17685. arr.forEach((line) => {
  17686. const parts = line.split(": ");
  17687. const header = parts.shift().toLowerCase();
  17688. const value = parts.join(": ");
  17689. headerMap[header] = value;
  17690. });
  17691. headerValue = headerMap[headerKey.toLowerCase()];
  17692. }
  17693. catch (e) {
  17694. // ignore the error
  17695. }
  17696. return headerValue;
  17697. }
  17698. set options(configParams) {
  17699. this.privHeaders = configParams.headers;
  17700. this.privIgnoreCache = configParams.ignoreCache;
  17701. }
  17702. setHeaders(key, value) {
  17703. this.privHeaders[key] = value;
  17704. }
  17705. request(method, uri, queryParams = {}, body = null) {
  17706. const responseReceivedDeferral = new Exports_js_1.Deferred();
  17707. const requestCommand = method === RestRequestType.File ? "POST" : method;
  17708. const handleRestResponse = (data, j = {}) => {
  17709. const d = data;
  17710. return {
  17711. data: JSON.stringify(j),
  17712. headers: JSON.stringify(data.headers),
  17713. json: j,
  17714. ok: data.statusCode >= 200 && data.statusCode < 300,
  17715. status: data.statusCode,
  17716. statusText: j.error ? j.error.message : d.statusText ? d.statusText : d.statusMessage
  17717. };
  17718. };
  17719. const send = (postData) => {
  17720. const sendRequest = (0, bent_1.default)(uri, requestCommand, this.privHeaders, 200, 201, 202, 204, 400, 401, 402, 403, 404);
  17721. const params = this.queryParams(queryParams) === "" ? "" : `?${this.queryParams(queryParams)}`;
  17722. sendRequest(params, postData).then(async (data) => {
  17723. if (method === RestRequestType.Delete || data.statusCode === 204) {
  17724. // No JSON from Delete and reset (204) operations
  17725. responseReceivedDeferral.resolve(handleRestResponse(data));
  17726. }
  17727. else {
  17728. try {
  17729. const j = await data.json();
  17730. responseReceivedDeferral.resolve(handleRestResponse(data, j));
  17731. }
  17732. catch {
  17733. responseReceivedDeferral.resolve(handleRestResponse(data));
  17734. }
  17735. }
  17736. }).catch((error) => {
  17737. responseReceivedDeferral.reject(error);
  17738. });
  17739. };
  17740. if (this.privIgnoreCache) {
  17741. this.privHeaders["Cache-Control"] = "no-cache";
  17742. }
  17743. if (method === RestRequestType.Post && body) {
  17744. this.privHeaders["content-type"] = "application/json";
  17745. this.privHeaders["Content-Type"] = "application/json";
  17746. }
  17747. send(body);
  17748. return responseReceivedDeferral.promise;
  17749. }
  17750. queryParams(params = {}) {
  17751. return Object.keys(params)
  17752. .map((k) => encodeURIComponent(k) + "=" + encodeURIComponent(params[k]))
  17753. .join("&");
  17754. }
  17755. }
  17756. exports.RestMessageAdapter = RestMessageAdapter;
  17757. /***/ }),
  17758. /* 201 */
  17759. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  17760. "use strict";
  17761. /* global fetch, btoa, Headers */
  17762. const core = __webpack_require__(202)
  17763. class StatusError extends Error {
  17764. constructor (res, ...params) {
  17765. super(...params)
  17766. if (Error.captureStackTrace) {
  17767. Error.captureStackTrace(this, StatusError)
  17768. }
  17769. this.name = 'StatusError'
  17770. this.message = res.statusMessage
  17771. this.statusCode = res.status
  17772. this.res = res
  17773. this.json = res.json.bind(res)
  17774. this.text = res.text.bind(res)
  17775. this.arrayBuffer = res.arrayBuffer.bind(res)
  17776. let buffer
  17777. const get = () => {
  17778. if (!buffer) buffer = this.arrayBuffer()
  17779. return buffer
  17780. }
  17781. Object.defineProperty(this, 'responseBody', { get })
  17782. // match Node.js headers object
  17783. this.headers = {}
  17784. for (const [key, value] of res.headers.entries()) {
  17785. this.headers[key.toLowerCase()] = value
  17786. }
  17787. }
  17788. }
  17789. const mkrequest = (statusCodes, method, encoding, headers, baseurl) => async (_url, body, _headers = {}) => {
  17790. _url = baseurl + (_url || '')
  17791. let parsed = new URL(_url)
  17792. if (!headers) headers = {}
  17793. if (parsed.username) {
  17794. headers.Authorization = 'Basic ' + btoa(parsed.username + ':' + parsed.password)
  17795. parsed = new URL(parsed.protocol + '//' + parsed.host + parsed.pathname + parsed.search)
  17796. }
  17797. if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
  17798. throw new Error(`Unknown protocol, ${parsed.protocol}`)
  17799. }
  17800. if (body) {
  17801. if (body instanceof ArrayBuffer ||
  17802. ArrayBuffer.isView(body) ||
  17803. typeof body === 'string'
  17804. ) {
  17805. // noop
  17806. } else if (typeof body === 'object') {
  17807. body = JSON.stringify(body)
  17808. headers['Content-Type'] = 'application/json'
  17809. } else {
  17810. throw new Error('Unknown body type.')
  17811. }
  17812. }
  17813. _headers = new Headers({ ...(headers || {}), ..._headers })
  17814. const resp = await fetch(parsed, { method, headers: _headers, body })
  17815. resp.statusCode = resp.status
  17816. if (!statusCodes.has(resp.status)) {
  17817. throw new StatusError(resp)
  17818. }
  17819. if (encoding === 'json') return resp.json()
  17820. else if (encoding === 'buffer') return resp.arrayBuffer()
  17821. else if (encoding === 'string') return resp.text()
  17822. else return resp
  17823. }
  17824. module.exports = core(mkrequest)
  17825. /***/ }),
  17826. /* 202 */
  17827. /***/ ((module) => {
  17828. "use strict";
  17829. const encodings = new Set(['json', 'buffer', 'string'])
  17830. module.exports = mkrequest => (...args) => {
  17831. const statusCodes = new Set()
  17832. let method
  17833. let encoding
  17834. let headers
  17835. let baseurl = ''
  17836. args.forEach(arg => {
  17837. if (typeof arg === 'string') {
  17838. if (arg.toUpperCase() === arg) {
  17839. if (method) {
  17840. const msg = `Can't set method to ${arg}, already set to ${method}.`
  17841. throw new Error(msg)
  17842. } else {
  17843. method = arg
  17844. }
  17845. } else if (arg.startsWith('http:') || arg.startsWith('https:')) {
  17846. baseurl = arg
  17847. } else {
  17848. if (encodings.has(arg)) {
  17849. encoding = arg
  17850. } else {
  17851. throw new Error(`Unknown encoding, ${arg}`)
  17852. }
  17853. }
  17854. } else if (typeof arg === 'number') {
  17855. statusCodes.add(arg)
  17856. } else if (typeof arg === 'object') {
  17857. if (Array.isArray(arg) || arg instanceof Set) {
  17858. arg.forEach(code => statusCodes.add(code))
  17859. } else {
  17860. if (headers) {
  17861. throw new Error('Cannot set headers twice.')
  17862. }
  17863. headers = arg
  17864. }
  17865. } else {
  17866. throw new Error(`Unknown type: ${typeof arg}`)
  17867. }
  17868. })
  17869. if (!method) method = 'GET'
  17870. if (statusCodes.size === 0) {
  17871. statusCodes.add(200)
  17872. }
  17873. return mkrequest(statusCodes, method, encoding, headers, baseurl)
  17874. }
  17875. /***/ }),
  17876. /* 203 */
  17877. /***/ ((__unused_webpack_module, exports) => {
  17878. "use strict";
  17879. // Copyright (c) Microsoft Corporation. All rights reserved.
  17880. // Licensed under the MIT license.
  17881. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17882. exports.RestConfigBase = void 0;
  17883. class RestConfigBase {
  17884. static get requestOptions() {
  17885. return RestConfigBase.privDefaultRequestOptions;
  17886. }
  17887. static get configParams() {
  17888. return RestConfigBase.privDefaultParams;
  17889. }
  17890. static get restErrors() {
  17891. return RestConfigBase.privRestErrors;
  17892. }
  17893. }
  17894. exports.RestConfigBase = RestConfigBase;
  17895. RestConfigBase.privDefaultRequestOptions = {
  17896. headers: {
  17897. Accept: "application/json",
  17898. },
  17899. ignoreCache: false,
  17900. timeout: 10000,
  17901. };
  17902. RestConfigBase.privRestErrors = {
  17903. authInvalidSubscriptionKey: "You must specify either an authentication token to use, or a Cognitive Speech subscription key.",
  17904. authInvalidSubscriptionRegion: "You must specify the Cognitive Speech region to use.",
  17905. invalidArgs: "Required input not found: {arg}.",
  17906. invalidCreateJoinConversationResponse: "Creating/Joining conversation failed with HTTP {status}.",
  17907. invalidParticipantRequest: "The requested participant was not found.",
  17908. permissionDeniedConnect: "Required credentials not found.",
  17909. permissionDeniedConversation: "Invalid operation: only the host can {command} the conversation.",
  17910. permissionDeniedParticipant: "Invalid operation: only the host can {command} a participant.",
  17911. permissionDeniedSend: "Invalid operation: the conversation is not in a connected state.",
  17912. permissionDeniedStart: "Invalid operation: there is already an active conversation.",
  17913. };
  17914. RestConfigBase.privDefaultParams = {
  17915. apiVersion: "api-version",
  17916. authorization: "Authorization",
  17917. clientAppId: "X-ClientAppId",
  17918. contentTypeKey: "Content-Type",
  17919. correlationId: "X-CorrelationId",
  17920. languageCode: "language",
  17921. nickname: "nickname",
  17922. profanity: "profanity",
  17923. requestId: "X-RequestId",
  17924. roomId: "roomid",
  17925. sessionToken: "token",
  17926. subscriptionKey: "Ocp-Apim-Subscription-Key",
  17927. subscriptionRegion: "Ocp-Apim-Subscription-Region",
  17928. token: "X-CapitoToken",
  17929. };
  17930. /***/ }),
  17931. /* 204 */
  17932. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  17933. "use strict";
  17934. // Copyright (c) Microsoft Corporation. All rights reserved.
  17935. // Licensed under the MIT license.
  17936. Object.defineProperty(exports, "__esModule", ({ value: true }));
  17937. exports.VoiceProfileConnectionFactory = exports.SpeakerRecognitionConnectionFactory = void 0;
  17938. /* eslint-disable max-classes-per-file */
  17939. const Exports_js_1 = __webpack_require__(60);
  17940. const Exports_js_2 = __webpack_require__(79);
  17941. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  17942. const Exports_js_3 = __webpack_require__(2);
  17943. const HeaderNames_js_1 = __webpack_require__(54);
  17944. class SpeakerRecognitionConnectionFactoryBase extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {
  17945. create(config, authInfo, endpointPath, connectionId) {
  17946. let endpoint = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint);
  17947. if (!endpoint) {
  17948. const region = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region);
  17949. const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);
  17950. const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, `wss://${region}.spr-frontend.speech${hostSuffix}`);
  17951. const scenario = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_SpeakerIdMode, "TextIndependentIdentification");
  17952. endpoint = `${host}/speaker/ws/${this.scenarioToPath(scenario)}/${endpointPath}`;
  17953. }
  17954. const queryParams = {
  17955. format: "simple",
  17956. language: config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage),
  17957. };
  17958. this.setCommonUrlParams(config, queryParams, endpoint);
  17959. const headers = {};
  17960. if (authInfo.token !== undefined && authInfo.token !== "") {
  17961. headers[authInfo.headerName] = authInfo.token;
  17962. }
  17963. headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;
  17964. headers[HeaderNames_js_1.HeaderNames.SpIDAuthKey] = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Key);
  17965. config.parameters.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Url, endpoint);
  17966. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "false") === "true";
  17967. return Promise.resolve(new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_3.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId));
  17968. }
  17969. scenarioToPath(mode) {
  17970. switch (mode) {
  17971. case "TextIndependentVerification":
  17972. case "2":
  17973. return "verification/text-independent";
  17974. case "TextDependentVerification":
  17975. case "1":
  17976. return "verification/text-dependent";
  17977. default:
  17978. return "identification/text-independent";
  17979. }
  17980. }
  17981. }
  17982. class SpeakerRecognitionConnectionFactory extends SpeakerRecognitionConnectionFactoryBase {
  17983. create(config, authInfo, connectionId) {
  17984. return super.create(config, authInfo, "recognition", connectionId);
  17985. }
  17986. }
  17987. exports.SpeakerRecognitionConnectionFactory = SpeakerRecognitionConnectionFactory;
  17988. class VoiceProfileConnectionFactory extends SpeakerRecognitionConnectionFactoryBase {
  17989. create(config, authInfo, connectionId) {
  17990. return super.create(config, authInfo, "profile", connectionId);
  17991. }
  17992. }
  17993. exports.VoiceProfileConnectionFactory = VoiceProfileConnectionFactory;
  17994. /***/ }),
  17995. /* 205 */
  17996. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  17997. "use strict";
  17998. // Copyright (c) Microsoft Corporation. All rights reserved.
  17999. // Licensed under the MIT license.
  18000. /* eslint-disable max-classes-per-file */
  18001. Object.defineProperty(exports, "__esModule", ({ value: true }));
  18002. exports.RecognitionEndedEvent = exports.RecognitionCompletionStatus = exports.RecognitionStartedEvent = exports.ConnectingToServiceEvent = exports.ListeningStartedEvent = exports.RecognitionTriggeredEvent = exports.SpeechRecognitionEvent = void 0;
  18003. const Exports_js_1 = __webpack_require__(4);
  18004. class SpeechRecognitionEvent extends Exports_js_1.PlatformEvent {
  18005. constructor(eventName, requestId, sessionId, eventType = Exports_js_1.EventType.Info) {
  18006. super(eventName, eventType);
  18007. this.privRequestId = requestId;
  18008. this.privSessionId = sessionId;
  18009. }
  18010. get requestId() {
  18011. return this.privRequestId;
  18012. }
  18013. get sessionId() {
  18014. return this.privSessionId;
  18015. }
  18016. }
  18017. exports.SpeechRecognitionEvent = SpeechRecognitionEvent;
  18018. class RecognitionTriggeredEvent extends SpeechRecognitionEvent {
  18019. constructor(requestId, sessionId, audioSourceId, audioNodeId) {
  18020. super("RecognitionTriggeredEvent", requestId, sessionId);
  18021. this.privAudioSourceId = audioSourceId;
  18022. this.privAudioNodeId = audioNodeId;
  18023. }
  18024. get audioSourceId() {
  18025. return this.privAudioSourceId;
  18026. }
  18027. get audioNodeId() {
  18028. return this.privAudioNodeId;
  18029. }
  18030. }
  18031. exports.RecognitionTriggeredEvent = RecognitionTriggeredEvent;
  18032. class ListeningStartedEvent extends SpeechRecognitionEvent {
  18033. constructor(requestId, sessionId, audioSourceId, audioNodeId) {
  18034. super("ListeningStartedEvent", requestId, sessionId);
  18035. this.privAudioSourceId = audioSourceId;
  18036. this.privAudioNodeId = audioNodeId;
  18037. }
  18038. get audioSourceId() {
  18039. return this.privAudioSourceId;
  18040. }
  18041. get audioNodeId() {
  18042. return this.privAudioNodeId;
  18043. }
  18044. }
  18045. exports.ListeningStartedEvent = ListeningStartedEvent;
  18046. class ConnectingToServiceEvent extends SpeechRecognitionEvent {
  18047. constructor(requestId, authFetchEventid, sessionId) {
  18048. super("ConnectingToServiceEvent", requestId, sessionId);
  18049. this.privAuthFetchEventid = authFetchEventid;
  18050. }
  18051. get authFetchEventid() {
  18052. return this.privAuthFetchEventid;
  18053. }
  18054. }
  18055. exports.ConnectingToServiceEvent = ConnectingToServiceEvent;
  18056. class RecognitionStartedEvent extends SpeechRecognitionEvent {
  18057. constructor(requestId, audioSourceId, audioNodeId, authFetchEventId, sessionId) {
  18058. super("RecognitionStartedEvent", requestId, sessionId);
  18059. this.privAudioSourceId = audioSourceId;
  18060. this.privAudioNodeId = audioNodeId;
  18061. this.privAuthFetchEventId = authFetchEventId;
  18062. }
  18063. get audioSourceId() {
  18064. return this.privAudioSourceId;
  18065. }
  18066. get audioNodeId() {
  18067. return this.privAudioNodeId;
  18068. }
  18069. get authFetchEventId() {
  18070. return this.privAuthFetchEventId;
  18071. }
  18072. }
  18073. exports.RecognitionStartedEvent = RecognitionStartedEvent;
  18074. var RecognitionCompletionStatus;
  18075. (function (RecognitionCompletionStatus) {
  18076. RecognitionCompletionStatus[RecognitionCompletionStatus["Success"] = 0] = "Success";
  18077. RecognitionCompletionStatus[RecognitionCompletionStatus["AudioSourceError"] = 1] = "AudioSourceError";
  18078. RecognitionCompletionStatus[RecognitionCompletionStatus["AudioSourceTimeout"] = 2] = "AudioSourceTimeout";
  18079. RecognitionCompletionStatus[RecognitionCompletionStatus["AuthTokenFetchError"] = 3] = "AuthTokenFetchError";
  18080. RecognitionCompletionStatus[RecognitionCompletionStatus["AuthTokenFetchTimeout"] = 4] = "AuthTokenFetchTimeout";
  18081. RecognitionCompletionStatus[RecognitionCompletionStatus["UnAuthorized"] = 5] = "UnAuthorized";
  18082. RecognitionCompletionStatus[RecognitionCompletionStatus["ConnectTimeout"] = 6] = "ConnectTimeout";
  18083. RecognitionCompletionStatus[RecognitionCompletionStatus["ConnectError"] = 7] = "ConnectError";
  18084. RecognitionCompletionStatus[RecognitionCompletionStatus["ClientRecognitionActivityTimeout"] = 8] = "ClientRecognitionActivityTimeout";
  18085. RecognitionCompletionStatus[RecognitionCompletionStatus["UnknownError"] = 9] = "UnknownError";
  18086. })(RecognitionCompletionStatus = exports.RecognitionCompletionStatus || (exports.RecognitionCompletionStatus = {}));
  18087. class RecognitionEndedEvent extends SpeechRecognitionEvent {
  18088. constructor(requestId, audioSourceId, audioNodeId, authFetchEventId, sessionId, serviceTag, status, error) {
  18089. super("RecognitionEndedEvent", requestId, sessionId, status === RecognitionCompletionStatus.Success ? Exports_js_1.EventType.Info : Exports_js_1.EventType.Error);
  18090. this.privAudioSourceId = audioSourceId;
  18091. this.privAudioNodeId = audioNodeId;
  18092. this.privAuthFetchEventId = authFetchEventId;
  18093. this.privStatus = status;
  18094. this.privError = error;
  18095. this.privServiceTag = serviceTag;
  18096. }
  18097. get audioSourceId() {
  18098. return this.privAudioSourceId;
  18099. }
  18100. get audioNodeId() {
  18101. return this.privAudioNodeId;
  18102. }
  18103. get authFetchEventId() {
  18104. return this.privAuthFetchEventId;
  18105. }
  18106. get serviceTag() {
  18107. return this.privServiceTag;
  18108. }
  18109. get status() {
  18110. return this.privStatus;
  18111. }
  18112. get error() {
  18113. return this.privError;
  18114. }
  18115. }
  18116. exports.RecognitionEndedEvent = RecognitionEndedEvent;
  18117. /***/ }),
  18118. /* 206 */
  18119. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  18120. "use strict";
  18121. // Copyright (c) Microsoft Corporation. All rights reserved.
  18122. // Licensed under the MIT license.
  18123. Object.defineProperty(exports, "__esModule", ({ value: true }));
  18124. exports.ServiceRecognizerBase = void 0;
  18125. const Exports_js_1 = __webpack_require__(60);
  18126. const Exports_js_2 = __webpack_require__(4);
  18127. const Exports_js_3 = __webpack_require__(79);
  18128. const Exports_js_4 = __webpack_require__(2);
  18129. const SpeechConnectionMessage_Internal_js_1 = __webpack_require__(207);
  18130. const Segmentation_js_1 = __webpack_require__(208);
  18131. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  18132. const OnSuccess_js_1 = __webpack_require__(209);
  18133. const InterimResults_js_1 = __webpack_require__(210);
  18134. const LanguageIdContext_js_1 = __webpack_require__(211);
  18135. const OnSuccess_js_2 = __webpack_require__(212);
  18136. const OnUnknown_js_1 = __webpack_require__(213);
  18137. const InterimResults_js_2 = __webpack_require__(214);
  18138. const PhraseResults_js_1 = __webpack_require__(215);
  18139. const OnSuccess_js_3 = __webpack_require__(216);
  18140. class ServiceRecognizerBase {
  18141. constructor(authentication, connectionFactory, audioSource, recognizerConfig, recognizer) {
  18142. // A promise for a configured connection.
  18143. // Do not consume directly, call fetchConnection instead.
  18144. this.privConnectionConfigurationPromise = undefined;
  18145. // A promise for a connection, but one that has not had the speech context sent yet.
  18146. // Do not consume directly, call fetchConnection instead.
  18147. this.privConnectionPromise = undefined;
  18148. this.privSetTimeout = setTimeout;
  18149. this.privIsLiveAudio = false;
  18150. this.privAverageBytesPerMs = 0;
  18151. this.privEnableSpeakerId = false;
  18152. this.privExpectContentAssessmentResponse = false;
  18153. this.recognizeOverride = undefined;
  18154. this.recognizeSpeaker = undefined;
  18155. this.disconnectOverride = undefined;
  18156. this.receiveMessageOverride = undefined;
  18157. this.sendPrePayloadJSONOverride = undefined;
  18158. this.postConnectImplOverride = undefined;
  18159. this.configConnectionOverride = undefined;
  18160. this.handleSpeechPhraseMessage = undefined;
  18161. this.handleSpeechHypothesisMessage = undefined;
  18162. if (!authentication) {
  18163. throw new Exports_js_2.ArgumentNullError("authentication");
  18164. }
  18165. if (!connectionFactory) {
  18166. throw new Exports_js_2.ArgumentNullError("connectionFactory");
  18167. }
  18168. if (!audioSource) {
  18169. throw new Exports_js_2.ArgumentNullError("audioSource");
  18170. }
  18171. if (!recognizerConfig) {
  18172. throw new Exports_js_2.ArgumentNullError("recognizerConfig");
  18173. }
  18174. this.privEnableSpeakerId = recognizerConfig.isSpeakerDiarizationEnabled;
  18175. this.privMustReportEndOfStream = false;
  18176. this.privAuthentication = authentication;
  18177. this.privConnectionFactory = connectionFactory;
  18178. this.privAudioSource = audioSource;
  18179. this.privRecognizerConfig = recognizerConfig;
  18180. this.privIsDisposed = false;
  18181. this.privRecognizer = recognizer;
  18182. this.privRequestSession = new Exports_js_4.RequestSession(this.privAudioSource.id());
  18183. this.privConnectionEvents = new Exports_js_2.EventSource();
  18184. this.privServiceEvents = new Exports_js_2.EventSource();
  18185. this.privDynamicGrammar = new Exports_js_4.DynamicGrammarBuilder();
  18186. this.privSpeechContext = new Exports_js_4.SpeechContext(this.privDynamicGrammar);
  18187. this.privAgentConfig = new Exports_js_4.AgentConfig();
  18188. const webWorkerLoadType = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.WebWorkerLoadType, "on").toLowerCase();
  18189. if (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") {
  18190. this.privSetTimeout = Exports_js_2.Timeout.setTimeout;
  18191. }
  18192. else {
  18193. if (typeof window !== "undefined") {
  18194. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  18195. this.privSetTimeout = window.setTimeout.bind(window);
  18196. }
  18197. if (typeof globalThis !== "undefined") {
  18198. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  18199. this.privSetTimeout = globalThis.setTimeout.bind(globalThis);
  18200. }
  18201. }
  18202. this.connectionEvents.attach((connectionEvent) => {
  18203. if (connectionEvent.name === "ConnectionClosedEvent") {
  18204. const connectionClosedEvent = connectionEvent;
  18205. if (connectionClosedEvent.statusCode === 1003 ||
  18206. connectionClosedEvent.statusCode === 1007 ||
  18207. connectionClosedEvent.statusCode === 1002 ||
  18208. connectionClosedEvent.statusCode === 4000 ||
  18209. this.privRequestSession.numConnectionAttempts > this.privRecognizerConfig.maxRetryCount) {
  18210. void this.cancelRecognitionLocal(Exports_js_3.CancellationReason.Error, connectionClosedEvent.statusCode === 1007 ? Exports_js_3.CancellationErrorCode.BadRequestParameters : Exports_js_3.CancellationErrorCode.ConnectionFailure, `${connectionClosedEvent.reason} websocket error code: ${connectionClosedEvent.statusCode}`);
  18211. }
  18212. }
  18213. });
  18214. if (this.privEnableSpeakerId) {
  18215. this.privDiarizationSessionId = (0, Exports_js_2.createNoDashGuid)();
  18216. }
  18217. }
  18218. setTranslationJson() {
  18219. const targetLanguages = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages, undefined);
  18220. if (targetLanguages !== undefined) {
  18221. const languages = targetLanguages.split(",");
  18222. const translationVoice = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationVoice, undefined);
  18223. const categoryId = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationCategoryId, undefined);
  18224. const action = (translationVoice !== undefined) ? OnSuccess_js_1.NextAction.Synthesize : OnSuccess_js_1.NextAction.None;
  18225. this.privSpeechContext.getContext().translation = {
  18226. onPassthrough: { action },
  18227. onSuccess: { action },
  18228. output: {
  18229. includePassThroughResults: true,
  18230. interimResults: { mode: InterimResults_js_1.Mode.Always }
  18231. },
  18232. targetLanguages: languages,
  18233. };
  18234. // Add category if specified
  18235. if (categoryId !== undefined) {
  18236. this.privSpeechContext.getContext().translation.category = categoryId;
  18237. }
  18238. if (translationVoice !== undefined) {
  18239. const languageToVoiceMap = {};
  18240. for (const lang of languages) {
  18241. languageToVoiceMap[lang] = translationVoice;
  18242. }
  18243. this.privSpeechContext.getContext().synthesis = {
  18244. defaultVoices: languageToVoiceMap
  18245. };
  18246. }
  18247. // Configure phrase detection for translation
  18248. const phraseDetection = this.privSpeechContext.getContext().phraseDetection || {};
  18249. phraseDetection.onSuccess = { action: OnSuccess_js_3.NextAction.Translate };
  18250. phraseDetection.onInterim = { action: OnSuccess_js_3.NextAction.Translate };
  18251. this.privSpeechContext.getContext().phraseDetection = phraseDetection;
  18252. }
  18253. }
  18254. setSpeechSegmentationTimeoutJson() {
  18255. const speechSegmentationSilenceTimeoutMs = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.Speech_SegmentationSilenceTimeoutMs, undefined);
  18256. const speechSegmentationMaximumTimeMs = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.Speech_SegmentationMaximumTimeMs, undefined);
  18257. const speechSegmentationStrategy = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.Speech_SegmentationStrategy, undefined);
  18258. const segmentation = {
  18259. mode: Segmentation_js_1.SegmentationMode.Normal,
  18260. segmentationForcedTimeoutMs: 0,
  18261. segmentationSilenceTimeoutMs: 0,
  18262. };
  18263. let configuredSegment = false;
  18264. if (speechSegmentationStrategy !== undefined) {
  18265. configuredSegment = true;
  18266. let segMode = Segmentation_js_1.SegmentationMode.Normal;
  18267. switch (speechSegmentationStrategy.toLowerCase()) {
  18268. case "default":
  18269. break;
  18270. case "time":
  18271. segMode = Segmentation_js_1.SegmentationMode.Custom;
  18272. break;
  18273. case "semantic":
  18274. segMode = Segmentation_js_1.SegmentationMode.Semantic;
  18275. break;
  18276. }
  18277. segmentation.mode = segMode;
  18278. }
  18279. if (speechSegmentationSilenceTimeoutMs !== undefined) {
  18280. configuredSegment = true;
  18281. const segmentationSilenceTimeoutMs = parseInt(speechSegmentationSilenceTimeoutMs, 10);
  18282. segmentation.mode = Segmentation_js_1.SegmentationMode.Custom;
  18283. segmentation.segmentationSilenceTimeoutMs = segmentationSilenceTimeoutMs;
  18284. }
  18285. if (speechSegmentationMaximumTimeMs !== undefined) {
  18286. configuredSegment = true;
  18287. const segmentationMaximumTimeMs = parseInt(speechSegmentationMaximumTimeMs, 10);
  18288. segmentation.mode = Segmentation_js_1.SegmentationMode.Custom;
  18289. segmentation.segmentationForcedTimeoutMs = segmentationMaximumTimeMs;
  18290. }
  18291. if (configuredSegment) {
  18292. const phraseDetection = this.privSpeechContext.getContext().phraseDetection || {};
  18293. phraseDetection.mode = this.recognitionMode;
  18294. switch (this.recognitionMode) {
  18295. case PhraseDetectionContext_js_1.RecognitionMode.Conversation:
  18296. phraseDetection.conversation = phraseDetection.conversation ?? { segmentation: {} };
  18297. phraseDetection.conversation.segmentation = segmentation;
  18298. break;
  18299. case PhraseDetectionContext_js_1.RecognitionMode.Interactive:
  18300. phraseDetection.interactive = phraseDetection.interactive ?? { segmentation: {} };
  18301. phraseDetection.interactive.segmentation = segmentation;
  18302. break;
  18303. case PhraseDetectionContext_js_1.RecognitionMode.Dictation:
  18304. phraseDetection.dictation = phraseDetection.dictation ?? {};
  18305. phraseDetection.dictation.segmentation = segmentation;
  18306. break;
  18307. }
  18308. this.privSpeechContext.getContext().phraseDetection = phraseDetection;
  18309. }
  18310. }
  18311. setLanguageIdJson() {
  18312. const phraseDetection = this.privSpeechContext.getContext().phraseDetection || {};
  18313. if (this.privRecognizerConfig.autoDetectSourceLanguages !== undefined) {
  18314. const sourceLanguages = this.privRecognizerConfig.autoDetectSourceLanguages.split(",");
  18315. if (sourceLanguages.length === 1 && sourceLanguages[0] === Exports_js_4.AutoDetectSourceLanguagesOpenRangeOptionName) {
  18316. sourceLanguages[0] = "UND";
  18317. }
  18318. let speechContextLidMode;
  18319. if (this.privRecognizerConfig.languageIdMode === "Continuous") {
  18320. speechContextLidMode = LanguageIdContext_js_1.LanguageIdDetectionMode.DetectContinuous;
  18321. }
  18322. else { // recognizerConfig.languageIdMode === "AtStart"
  18323. speechContextLidMode = LanguageIdContext_js_1.LanguageIdDetectionMode.DetectAtAudioStart;
  18324. }
  18325. this.privSpeechContext.getContext().languageId = {
  18326. languages: sourceLanguages,
  18327. mode: speechContextLidMode,
  18328. onSuccess: { action: OnSuccess_js_2.NextAction.Recognize },
  18329. onUnknown: { action: OnUnknown_js_1.OnUnknownAction.None },
  18330. priority: LanguageIdContext_js_1.LanguageIdDetectionPriority.PrioritizeLatency
  18331. };
  18332. this.privSpeechContext.getContext().phraseOutput = {
  18333. interimResults: {
  18334. resultType: InterimResults_js_2.ResultType.Auto
  18335. },
  18336. phraseResults: {
  18337. resultType: PhraseResults_js_1.PhraseResultOutputType.Always
  18338. }
  18339. };
  18340. const customModels = this.privRecognizerConfig.sourceLanguageModels;
  18341. if (customModels !== undefined) {
  18342. phraseDetection.customModels = customModels;
  18343. phraseDetection.onInterim = { action: OnSuccess_js_3.NextAction.None };
  18344. phraseDetection.onSuccess = { action: OnSuccess_js_3.NextAction.None };
  18345. }
  18346. }
  18347. // No longer setting translation-specific configuration here
  18348. // This is now handled in setTranslationJson and setupTranslationWithLanguageId methods
  18349. this.privSpeechContext.getContext().phraseDetection = phraseDetection;
  18350. }
  18351. setOutputDetailLevelJson() {
  18352. if (this.privEnableSpeakerId) {
  18353. const requestWordLevelTimestamps = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, "false").toLowerCase();
  18354. if (requestWordLevelTimestamps === "true") {
  18355. this.privSpeechContext.setWordLevelTimings();
  18356. }
  18357. else {
  18358. const outputFormat = this.privRecognizerConfig.parameters.getProperty(Exports_js_4.OutputFormatPropertyName, Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Simple]).toLowerCase();
  18359. if (outputFormat === Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Detailed].toLocaleLowerCase()) {
  18360. this.privSpeechContext.setDetailedOutputFormat();
  18361. }
  18362. }
  18363. }
  18364. }
  18365. get isSpeakerDiarizationEnabled() {
  18366. return this.privEnableSpeakerId;
  18367. }
  18368. get audioSource() {
  18369. return this.privAudioSource;
  18370. }
  18371. get speechContext() {
  18372. return this.privSpeechContext;
  18373. }
  18374. get dynamicGrammar() {
  18375. return this.privDynamicGrammar;
  18376. }
  18377. get agentConfig() {
  18378. return this.privAgentConfig;
  18379. }
  18380. set conversationTranslatorToken(token) {
  18381. this.privRecognizerConfig.parameters.setProperty(Exports_js_3.PropertyId.ConversationTranslator_Token, token);
  18382. }
  18383. set voiceProfileType(type) {
  18384. this.privRecognizerConfig.parameters.setProperty(Exports_js_3.PropertyId.SpeechServiceConnection_SpeakerIdMode, type);
  18385. }
  18386. set authentication(auth) {
  18387. this.privAuthentication = auth;
  18388. }
  18389. isDisposed() {
  18390. return this.privIsDisposed;
  18391. }
  18392. async dispose(reason) {
  18393. this.privIsDisposed = true;
  18394. if (this.privConnectionPromise !== undefined) {
  18395. try {
  18396. const connection = await this.privConnectionPromise;
  18397. await connection.dispose(reason);
  18398. }
  18399. catch (error) {
  18400. // The connection is in a bad state. But we're trying to kill it, so...
  18401. return;
  18402. }
  18403. }
  18404. }
  18405. get connectionEvents() {
  18406. return this.privConnectionEvents;
  18407. }
  18408. get serviceEvents() {
  18409. return this.privServiceEvents;
  18410. }
  18411. get recognitionMode() {
  18412. return this.privRecognizerConfig.recognitionMode;
  18413. }
  18414. async recognize(recoMode, successCallback, errorCallBack) {
  18415. if (this.recognizeOverride !== undefined) {
  18416. await this.recognizeOverride(recoMode, successCallback, errorCallBack);
  18417. return;
  18418. }
  18419. // Clear the existing configuration promise to force a re-transmission of config and context.
  18420. this.privConnectionConfigurationPromise = undefined;
  18421. this.privRecognizerConfig.recognitionMode = recoMode;
  18422. if (this.privRecognizerConfig.recognitionEndpointVersion === "2") {
  18423. const phraseDetection = this.privSpeechContext.getContext().phraseDetection || {};
  18424. phraseDetection.mode = recoMode;
  18425. this.privSpeechContext.getContext().phraseDetection = phraseDetection;
  18426. }
  18427. // Set language ID (if configured)
  18428. this.setLanguageIdJson();
  18429. // Then set translation (if configured)
  18430. this.setTranslationJson();
  18431. // Configure the integration between language ID and translation (if both are used)
  18432. if (this.privRecognizerConfig.autoDetectSourceLanguages !== undefined &&
  18433. this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages, undefined) !== undefined) {
  18434. this.setupTranslationWithLanguageId();
  18435. }
  18436. this.setSpeechSegmentationTimeoutJson();
  18437. this.setOutputDetailLevelJson();
  18438. this.privSuccessCallback = successCallback;
  18439. this.privErrorCallback = errorCallBack;
  18440. this.privRequestSession.startNewRecognition();
  18441. this.privRequestSession.listenForServiceTelemetry(this.privAudioSource.events);
  18442. // Start the connection to the service. The promise this will create is stored and will be used by configureConnection().
  18443. const conPromise = this.connectImpl();
  18444. let audioNode;
  18445. try {
  18446. const audioStreamNode = await this.audioSource.attach(this.privRequestSession.audioNodeId);
  18447. const format = await this.audioSource.format;
  18448. const deviceInfo = await this.audioSource.deviceInfo;
  18449. this.privIsLiveAudio = deviceInfo.type && deviceInfo.type === Exports_js_4.type.Microphones;
  18450. audioNode = new Exports_js_1.ReplayableAudioNode(audioStreamNode, format.avgBytesPerSec);
  18451. await this.privRequestSession.onAudioSourceAttachCompleted(audioNode, false);
  18452. this.privRecognizerConfig.SpeechServiceConfig.Context.audio = { source: deviceInfo };
  18453. }
  18454. catch (error) {
  18455. await this.privRequestSession.onStopRecognizing();
  18456. throw error;
  18457. }
  18458. try {
  18459. await conPromise;
  18460. }
  18461. catch (error) {
  18462. await this.cancelRecognitionLocal(Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.ConnectionFailure, error);
  18463. return;
  18464. }
  18465. const sessionStartEventArgs = new Exports_js_3.SessionEventArgs(this.privRequestSession.sessionId);
  18466. if (!!this.privRecognizer.sessionStarted) {
  18467. this.privRecognizer.sessionStarted(this.privRecognizer, sessionStartEventArgs);
  18468. }
  18469. void this.receiveMessage();
  18470. const audioSendPromise = this.sendAudio(audioNode);
  18471. audioSendPromise.catch(async (error) => {
  18472. await this.cancelRecognitionLocal(Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.RuntimeError, error);
  18473. });
  18474. return;
  18475. }
  18476. async stopRecognizing() {
  18477. if (this.privRequestSession.isRecognizing) {
  18478. try {
  18479. await this.audioSource.turnOff();
  18480. await this.sendFinalAudio();
  18481. await this.privRequestSession.onStopRecognizing();
  18482. await this.privRequestSession.turnCompletionPromise;
  18483. }
  18484. finally {
  18485. await this.privRequestSession.dispose();
  18486. }
  18487. }
  18488. return;
  18489. }
  18490. async connect() {
  18491. await this.connectImpl();
  18492. return Promise.resolve();
  18493. }
  18494. connectAsync(cb, err) {
  18495. this.connectImpl().then(() => {
  18496. try {
  18497. if (!!cb) {
  18498. cb();
  18499. }
  18500. }
  18501. catch (e) {
  18502. if (!!err) {
  18503. err(e);
  18504. }
  18505. }
  18506. }, (reason) => {
  18507. try {
  18508. if (!!err) {
  18509. err(reason);
  18510. }
  18511. /* eslint-disable no-empty */
  18512. }
  18513. catch (error) {
  18514. }
  18515. });
  18516. }
  18517. async disconnect() {
  18518. await this.cancelRecognitionLocal(Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.NoError, "Disconnecting");
  18519. if (this.disconnectOverride !== undefined) {
  18520. await this.disconnectOverride();
  18521. }
  18522. if (this.privConnectionPromise !== undefined) {
  18523. try {
  18524. await (await this.privConnectionPromise).dispose();
  18525. }
  18526. catch (error) {
  18527. }
  18528. }
  18529. this.privConnectionPromise = undefined;
  18530. }
  18531. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  18532. sendMessage(message) {
  18533. return;
  18534. }
  18535. async sendNetworkMessage(path, payload) {
  18536. const type = typeof payload === "string" ? Exports_js_2.MessageType.Text : Exports_js_2.MessageType.Binary;
  18537. const contentType = typeof payload === "string" ? "application/json" : "";
  18538. const connection = await this.fetchConnection();
  18539. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(type, path, this.privRequestSession.requestId, contentType, payload));
  18540. }
  18541. set activityTemplate(messagePayload) {
  18542. this.privActivityTemplate = messagePayload;
  18543. }
  18544. get activityTemplate() {
  18545. return this.privActivityTemplate;
  18546. }
  18547. set expectContentAssessmentResponse(value) {
  18548. this.privExpectContentAssessmentResponse = value;
  18549. }
  18550. async sendTelemetryData() {
  18551. const telemetryData = this.privRequestSession.getTelemetry();
  18552. if (ServiceRecognizerBase.telemetryDataEnabled !== true ||
  18553. this.privIsDisposed ||
  18554. null === telemetryData) {
  18555. return;
  18556. }
  18557. if (!!ServiceRecognizerBase.telemetryData) {
  18558. try {
  18559. ServiceRecognizerBase.telemetryData(telemetryData);
  18560. /* eslint-disable no-empty */
  18561. }
  18562. catch { }
  18563. }
  18564. const connection = await this.fetchConnection();
  18565. await connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, "telemetry", this.privRequestSession.requestId, "application/json", telemetryData));
  18566. }
  18567. // Cancels recognition.
  18568. async cancelRecognitionLocal(cancellationReason, errorCode, error) {
  18569. if (!!this.privRequestSession.isRecognizing) {
  18570. await this.privRequestSession.onStopRecognizing();
  18571. this.cancelRecognition(this.privRequestSession.sessionId, this.privRequestSession.requestId, cancellationReason, errorCode, error);
  18572. }
  18573. }
  18574. async receiveMessage() {
  18575. try {
  18576. if (this.privIsDisposed) {
  18577. // We're done.
  18578. return;
  18579. }
  18580. let connection = await this.fetchConnection();
  18581. const message = await connection.read();
  18582. if (this.receiveMessageOverride !== undefined) {
  18583. return this.receiveMessageOverride();
  18584. }
  18585. // indicates we are draining the queue and it came with no message;
  18586. if (!message) {
  18587. return this.receiveMessage();
  18588. }
  18589. this.privServiceHasSentMessage = true;
  18590. const connectionMessage = SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage.fromConnectionMessage(message);
  18591. if (connectionMessage.requestId.toLowerCase() === this.privRequestSession.requestId.toLowerCase()) {
  18592. switch (connectionMessage.path.toLowerCase()) {
  18593. case "turn.start":
  18594. this.privMustReportEndOfStream = true;
  18595. this.privRequestSession.onServiceTurnStartResponse();
  18596. break;
  18597. case "speech.startdetected":
  18598. const speechStartDetected = Exports_js_4.SpeechDetected.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  18599. const speechStartEventArgs = new Exports_js_3.RecognitionEventArgs(speechStartDetected.Offset, this.privRequestSession.sessionId);
  18600. if (!!this.privRecognizer.speechStartDetected) {
  18601. this.privRecognizer.speechStartDetected(this.privRecognizer, speechStartEventArgs);
  18602. }
  18603. break;
  18604. case "speech.enddetected":
  18605. let json;
  18606. if (connectionMessage.textBody.length > 0) {
  18607. json = connectionMessage.textBody;
  18608. }
  18609. else {
  18610. // If the request was empty, the JSON returned is empty.
  18611. json = "{ Offset: 0 }";
  18612. }
  18613. const speechStopDetected = Exports_js_4.SpeechDetected.fromJSON(json, this.privRequestSession.currentTurnAudioOffset);
  18614. const speechStopEventArgs = new Exports_js_3.RecognitionEventArgs(speechStopDetected.Offset + this.privRequestSession.currentTurnAudioOffset, this.privRequestSession.sessionId);
  18615. if (!!this.privRecognizer.speechEndDetected) {
  18616. this.privRecognizer.speechEndDetected(this.privRecognizer, speechStopEventArgs);
  18617. }
  18618. break;
  18619. case "turn.end":
  18620. await this.sendTelemetryData();
  18621. if (this.privRequestSession.isSpeechEnded && this.privMustReportEndOfStream) {
  18622. this.privMustReportEndOfStream = false;
  18623. await this.cancelRecognitionLocal(Exports_js_3.CancellationReason.EndOfStream, Exports_js_3.CancellationErrorCode.NoError, undefined);
  18624. }
  18625. const sessionStopEventArgs = new Exports_js_3.SessionEventArgs(this.privRequestSession.sessionId);
  18626. await this.privRequestSession.onServiceTurnEndResponse(this.privRecognizerConfig.isContinuousRecognition);
  18627. if (!this.privRecognizerConfig.isContinuousRecognition || this.privRequestSession.isSpeechEnded || !this.privRequestSession.isRecognizing) {
  18628. if (!!this.privRecognizer.sessionStopped) {
  18629. this.privRecognizer.sessionStopped(this.privRecognizer, sessionStopEventArgs);
  18630. }
  18631. return;
  18632. }
  18633. else {
  18634. connection = await this.fetchConnection();
  18635. await this.sendPrePayloadJSON(connection);
  18636. }
  18637. break;
  18638. default:
  18639. if (!await this.processTypeSpecificMessages(connectionMessage)) {
  18640. // here are some messages that the derived class has not processed, dispatch them to connect class
  18641. if (!!this.privServiceEvents) {
  18642. this.serviceEvents.onEvent(new Exports_js_2.ServiceEvent(connectionMessage.path.toLowerCase(), connectionMessage.textBody));
  18643. }
  18644. }
  18645. }
  18646. }
  18647. return this.receiveMessage();
  18648. }
  18649. catch (error) {
  18650. return null;
  18651. }
  18652. }
  18653. updateSpeakerDiarizationAudioOffset() {
  18654. const bytesSent = this.privRequestSession.recognitionBytesSent;
  18655. const audioOffsetMs = this.privAverageBytesPerMs !== 0 ? bytesSent / this.privAverageBytesPerMs : 0;
  18656. this.privSpeechContext.setSpeakerDiarizationAudioOffsetMs(audioOffsetMs);
  18657. }
  18658. sendSpeechContext(connection, generateNewRequestId) {
  18659. if (this.privEnableSpeakerId) {
  18660. this.updateSpeakerDiarizationAudioOffset();
  18661. }
  18662. const speechContextJson = this.speechContext.toJSON();
  18663. if (generateNewRequestId) {
  18664. this.privRequestSession.onSpeechContext();
  18665. }
  18666. if (speechContextJson) {
  18667. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, "speech.context", this.privRequestSession.requestId, "application/json", speechContextJson));
  18668. }
  18669. return;
  18670. }
  18671. setupTranslationWithLanguageId() {
  18672. const targetLanguages = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationToLanguages, undefined);
  18673. const hasLanguageId = this.privRecognizerConfig.autoDetectSourceLanguages !== undefined;
  18674. if (targetLanguages !== undefined && hasLanguageId) {
  18675. // Configure phraseOutput for translation + language ID scenario
  18676. this.privSpeechContext.getContext().phraseOutput = {
  18677. interimResults: {
  18678. resultType: InterimResults_js_2.ResultType.None
  18679. },
  18680. phraseResults: {
  18681. resultType: PhraseResults_js_1.PhraseResultOutputType.None
  18682. }
  18683. };
  18684. // Handle custom language models and voice mapping
  18685. const translationContext = this.privSpeechContext.getContext().translation;
  18686. if (translationContext) {
  18687. const customModels = this.privRecognizerConfig.sourceLanguageModels;
  18688. if (customModels !== undefined && customModels.length > 0) {
  18689. const phraseDetection = this.privSpeechContext.getContext().phraseDetection || {};
  18690. phraseDetection.customModels = customModels;
  18691. this.privSpeechContext.getContext().phraseDetection = phraseDetection;
  18692. }
  18693. const translationVoice = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_TranslationVoice, undefined);
  18694. if (translationVoice !== undefined) {
  18695. // Update translation actions for synthesis
  18696. translationContext.onSuccess = { action: OnSuccess_js_1.NextAction.Synthesize };
  18697. translationContext.onPassthrough = { action: OnSuccess_js_1.NextAction.Synthesize };
  18698. }
  18699. }
  18700. }
  18701. }
  18702. noOp() {
  18703. // operation not supported
  18704. return;
  18705. }
  18706. // Encapsulated for derived service recognizers that need to send additional JSON
  18707. async sendPrePayloadJSON(connection, generateNewRequestId = true) {
  18708. if (this.sendPrePayloadJSONOverride !== undefined) {
  18709. return this.sendPrePayloadJSONOverride(connection);
  18710. }
  18711. await this.sendSpeechContext(connection, generateNewRequestId);
  18712. await this.sendWaveHeader(connection);
  18713. return;
  18714. }
  18715. async sendWaveHeader(connection) {
  18716. const format = await this.audioSource.format;
  18717. // this.writeBufferToConsole(format.header);
  18718. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Binary, "audio", this.privRequestSession.requestId, "audio/x-wav", format.header));
  18719. }
  18720. // Establishes a websocket connection to the end point.
  18721. connectImpl() {
  18722. if (this.privConnectionPromise !== undefined) {
  18723. return this.privConnectionPromise.then((connection) => {
  18724. if (connection.state() === Exports_js_2.ConnectionState.Disconnected) {
  18725. this.privConnectionId = null;
  18726. this.privConnectionPromise = undefined;
  18727. this.privServiceHasSentMessage = false;
  18728. return this.connectImpl();
  18729. }
  18730. return this.privConnectionPromise;
  18731. }, () => {
  18732. this.privConnectionId = null;
  18733. this.privConnectionPromise = undefined;
  18734. this.privServiceHasSentMessage = false;
  18735. return this.connectImpl();
  18736. });
  18737. }
  18738. this.privConnectionPromise = this.retryableConnect();
  18739. // Attach an empty handler to allow the promise to run in the background while
  18740. // other startup events happen. It'll eventually be awaited on.
  18741. // eslint-disable-next-line @typescript-eslint/no-empty-function
  18742. this.privConnectionPromise.catch(() => { });
  18743. if (this.postConnectImplOverride !== undefined) {
  18744. return this.postConnectImplOverride(this.privConnectionPromise);
  18745. }
  18746. return this.privConnectionPromise;
  18747. }
  18748. sendSpeechServiceConfig(connection, requestSession, SpeechServiceConfigJson) {
  18749. requestSession.onSpeechContext();
  18750. // filter out anything that is not required for the service to work.
  18751. if (ServiceRecognizerBase.telemetryDataEnabled !== true) {
  18752. const withTelemetry = JSON.parse(SpeechServiceConfigJson);
  18753. const replacement = {
  18754. context: {
  18755. system: withTelemetry.context.system,
  18756. },
  18757. };
  18758. SpeechServiceConfigJson = JSON.stringify(replacement);
  18759. }
  18760. if (this.privRecognizerConfig.parameters.getProperty("f0f5debc-f8c9-4892-ac4b-90a7ab359fd2", "false").toLowerCase() === "true") {
  18761. const json = JSON.parse(SpeechServiceConfigJson);
  18762. json.context.DisableReferenceChannel = "True";
  18763. json.context.MicSpec = "1_0_0";
  18764. SpeechServiceConfigJson = JSON.stringify(json);
  18765. }
  18766. if (SpeechServiceConfigJson) {
  18767. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, "speech.config", requestSession.requestId, "application/json", SpeechServiceConfigJson));
  18768. }
  18769. return;
  18770. }
  18771. async fetchConnection() {
  18772. if (this.privConnectionConfigurationPromise !== undefined) {
  18773. return this.privConnectionConfigurationPromise.then((connection) => {
  18774. if (connection.state() === Exports_js_2.ConnectionState.Disconnected) {
  18775. this.privConnectionId = null;
  18776. this.privConnectionConfigurationPromise = undefined;
  18777. this.privServiceHasSentMessage = false;
  18778. return this.fetchConnection();
  18779. }
  18780. return this.privConnectionConfigurationPromise;
  18781. }, () => {
  18782. this.privConnectionId = null;
  18783. this.privConnectionConfigurationPromise = undefined;
  18784. this.privServiceHasSentMessage = false;
  18785. return this.fetchConnection();
  18786. });
  18787. }
  18788. this.privConnectionConfigurationPromise = this.configureConnection();
  18789. return await this.privConnectionConfigurationPromise;
  18790. }
  18791. async sendAudio(audioStreamNode) {
  18792. const audioFormat = await this.audioSource.format;
  18793. this.privAverageBytesPerMs = audioFormat.avgBytesPerSec / 1000;
  18794. // The time we last sent data to the service.
  18795. let nextSendTime = Date.now();
  18796. // Max amount to send before we start to throttle
  18797. const fastLaneSizeMs = this.privRecognizerConfig.parameters.getProperty("SPEECH-TransmitLengthBeforThrottleMs", "5000");
  18798. const maxSendUnthrottledBytes = audioFormat.avgBytesPerSec / 1000 * parseInt(fastLaneSizeMs, 10);
  18799. const startRecogNumber = this.privRequestSession.recogNumber;
  18800. const readAndUploadCycle = async () => {
  18801. // If speech is done, stop sending audio.
  18802. if (!this.privIsDisposed &&
  18803. !this.privRequestSession.isSpeechEnded &&
  18804. this.privRequestSession.isRecognizing &&
  18805. this.privRequestSession.recogNumber === startRecogNumber) {
  18806. const connection = await this.fetchConnection();
  18807. const audioStreamChunk = await audioStreamNode.read();
  18808. // we have a new audio chunk to upload.
  18809. if (this.privRequestSession.isSpeechEnded) {
  18810. // If service already recognized audio end then don't send any more audio
  18811. return;
  18812. }
  18813. let payload;
  18814. let sendDelay;
  18815. if (!audioStreamChunk || audioStreamChunk.isEnd) {
  18816. payload = null;
  18817. sendDelay = 0;
  18818. }
  18819. else {
  18820. payload = audioStreamChunk.buffer;
  18821. this.privRequestSession.onAudioSent(payload.byteLength);
  18822. if (maxSendUnthrottledBytes >= this.privRequestSession.bytesSent) {
  18823. sendDelay = 0;
  18824. }
  18825. else {
  18826. sendDelay = Math.max(0, nextSendTime - Date.now());
  18827. }
  18828. }
  18829. if (0 !== sendDelay) {
  18830. await this.delay(sendDelay);
  18831. }
  18832. if (payload !== null) {
  18833. nextSendTime = Date.now() + (payload.byteLength * 1000 / (audioFormat.avgBytesPerSec * 2));
  18834. }
  18835. // Are we still alive?
  18836. if (!this.privIsDisposed &&
  18837. !this.privRequestSession.isSpeechEnded &&
  18838. this.privRequestSession.isRecognizing &&
  18839. this.privRequestSession.recogNumber === startRecogNumber) {
  18840. connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Binary, "audio", this.privRequestSession.requestId, null, payload)).catch(() => {
  18841. // eslint-disable-next-line @typescript-eslint/no-empty-function
  18842. this.privRequestSession.onServiceTurnEndResponse(this.privRecognizerConfig.isContinuousRecognition).catch(() => { });
  18843. });
  18844. if (!audioStreamChunk?.isEnd) {
  18845. // this.writeBufferToConsole(payload);
  18846. // Regardless of success or failure, schedule the next upload.
  18847. // If the underlying connection was broken, the next cycle will
  18848. // get a new connection and re-transmit missing audio automatically.
  18849. return readAndUploadCycle();
  18850. }
  18851. else {
  18852. // the audio stream has been closed, no need to schedule next
  18853. // read-upload cycle.
  18854. if (!this.privIsLiveAudio) {
  18855. this.privRequestSession.onSpeechEnded();
  18856. }
  18857. }
  18858. }
  18859. }
  18860. };
  18861. return readAndUploadCycle();
  18862. }
  18863. async retryableConnect() {
  18864. let isUnAuthorized = false;
  18865. this.privAuthFetchEventId = (0, Exports_js_2.createNoDashGuid)();
  18866. const sessionId = this.privRequestSession.sessionId;
  18867. this.privConnectionId = (sessionId !== undefined) ? sessionId : (0, Exports_js_2.createNoDashGuid)();
  18868. this.privRequestSession.onPreConnectionStart(this.privAuthFetchEventId, this.privConnectionId);
  18869. let lastStatusCode = 0;
  18870. let lastReason = "";
  18871. while (this.privRequestSession.numConnectionAttempts <= this.privRecognizerConfig.maxRetryCount) {
  18872. this.privRequestSession.onRetryConnection();
  18873. // Get the auth information for the connection. This is a bit of overkill for the current API surface, but leaving the plumbing in place to be able to raise a developer-customer
  18874. // facing event when a connection fails to let them try and provide new auth information.
  18875. const authPromise = isUnAuthorized ? this.privAuthentication.fetchOnExpiry(this.privAuthFetchEventId) : this.privAuthentication.fetch(this.privAuthFetchEventId);
  18876. const auth = await authPromise;
  18877. await this.privRequestSession.onAuthCompleted(false);
  18878. // Create the connection
  18879. const connection = await this.privConnectionFactory.create(this.privRecognizerConfig, auth, this.privConnectionId);
  18880. // Attach the telemetry handlers.
  18881. this.privRequestSession.listenForServiceTelemetry(connection.events);
  18882. // Attach to the underlying event. No need to hold onto the detach pointers as in the event the connection goes away,
  18883. // it'll stop sending events.
  18884. connection.events.attach((event) => {
  18885. this.connectionEvents.onEvent(event);
  18886. });
  18887. const response = await connection.open();
  18888. // 200 == everything is fine.
  18889. if (response.statusCode === 200) {
  18890. await this.privRequestSession.onConnectionEstablishCompleted(response.statusCode);
  18891. return Promise.resolve(connection);
  18892. }
  18893. else if (response.statusCode === 1006) {
  18894. isUnAuthorized = true;
  18895. }
  18896. lastStatusCode = response.statusCode;
  18897. lastReason = response.reason;
  18898. }
  18899. await this.privRequestSession.onConnectionEstablishCompleted(lastStatusCode, lastReason);
  18900. return Promise.reject(`Unable to contact server. StatusCode: ${lastStatusCode}, ${this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Endpoint)} Reason: ${lastReason}`);
  18901. }
  18902. delay(delayMs) {
  18903. return new Promise((resolve) => this.privSetTimeout(resolve, delayMs));
  18904. }
  18905. writeBufferToConsole(buffer) {
  18906. let out = "Buffer Size: ";
  18907. if (null === buffer) {
  18908. out += "null";
  18909. }
  18910. else {
  18911. const readView = new Uint8Array(buffer);
  18912. out += `${buffer.byteLength}\r\n`;
  18913. for (let i = 0; i < buffer.byteLength; i++) {
  18914. out += readView[i].toString(16).padStart(2, "0") + " ";
  18915. if (((i + 1) % 16) === 0) {
  18916. // eslint-disable-next-line no-console
  18917. console.info(out);
  18918. out = "";
  18919. }
  18920. }
  18921. }
  18922. // eslint-disable-next-line no-console
  18923. console.info(out);
  18924. }
  18925. async sendFinalAudio() {
  18926. const connection = await this.fetchConnection();
  18927. await connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Binary, "audio", this.privRequestSession.requestId, null, null));
  18928. return;
  18929. }
  18930. // Takes an established websocket connection to the endpoint and sends speech configuration information.
  18931. async configureConnection() {
  18932. const connection = await this.connectImpl();
  18933. if (this.configConnectionOverride !== undefined) {
  18934. return this.configConnectionOverride(connection);
  18935. }
  18936. await this.sendSpeechServiceConfig(connection, this.privRequestSession, this.privRecognizerConfig.SpeechServiceConfig.serialize());
  18937. await this.sendPrePayloadJSON(connection, false);
  18938. return connection;
  18939. }
  18940. }
  18941. exports.ServiceRecognizerBase = ServiceRecognizerBase;
  18942. ServiceRecognizerBase.telemetryDataEnabled = true;
  18943. /***/ }),
  18944. /* 207 */
  18945. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  18946. "use strict";
  18947. // Copyright (c) Microsoft Corporation. All rights reserved.
  18948. // Licensed under the MIT license.
  18949. Object.defineProperty(exports, "__esModule", ({ value: true }));
  18950. exports.SpeechConnectionMessage = void 0;
  18951. const Exports_js_1 = __webpack_require__(4);
  18952. const HeaderNames_js_1 = __webpack_require__(54);
  18953. class SpeechConnectionMessage extends Exports_js_1.ConnectionMessage {
  18954. constructor(messageType, path, requestId, contentType, body, streamId, additionalHeaders, id) {
  18955. if (!path) {
  18956. throw new Exports_js_1.ArgumentNullError("path");
  18957. }
  18958. if (!requestId) {
  18959. throw new Exports_js_1.ArgumentNullError("requestId");
  18960. }
  18961. const headers = {};
  18962. headers[HeaderNames_js_1.HeaderNames.Path] = path;
  18963. headers[HeaderNames_js_1.HeaderNames.RequestId] = requestId;
  18964. headers[HeaderNames_js_1.HeaderNames.RequestTimestamp] = new Date().toISOString();
  18965. if (contentType) {
  18966. headers[HeaderNames_js_1.HeaderNames.ContentType] = contentType;
  18967. }
  18968. if (streamId) {
  18969. headers[HeaderNames_js_1.HeaderNames.RequestStreamId] = streamId;
  18970. }
  18971. if (additionalHeaders) {
  18972. for (const headerName in additionalHeaders) {
  18973. if (headerName) {
  18974. headers[headerName] = additionalHeaders[headerName];
  18975. }
  18976. }
  18977. }
  18978. if (id) {
  18979. super(messageType, body, headers, id);
  18980. }
  18981. else {
  18982. super(messageType, body, headers);
  18983. }
  18984. this.privPath = path;
  18985. this.privRequestId = requestId;
  18986. this.privContentType = contentType;
  18987. this.privStreamId = streamId;
  18988. this.privAdditionalHeaders = additionalHeaders;
  18989. }
  18990. get path() {
  18991. return this.privPath;
  18992. }
  18993. get requestId() {
  18994. return this.privRequestId;
  18995. }
  18996. get contentType() {
  18997. return this.privContentType;
  18998. }
  18999. get streamId() {
  19000. return this.privStreamId;
  19001. }
  19002. get additionalHeaders() {
  19003. return this.privAdditionalHeaders;
  19004. }
  19005. static fromConnectionMessage(message) {
  19006. let path = null;
  19007. let requestId = null;
  19008. let contentType = null;
  19009. // let requestTimestamp = null;
  19010. let streamId = null;
  19011. const additionalHeaders = {};
  19012. if (message.headers) {
  19013. for (const headerName in message.headers) {
  19014. if (headerName) {
  19015. if (headerName.toLowerCase() === HeaderNames_js_1.HeaderNames.Path.toLowerCase()) {
  19016. path = message.headers[headerName];
  19017. }
  19018. else if (headerName.toLowerCase() === HeaderNames_js_1.HeaderNames.RequestId.toLowerCase()) {
  19019. requestId = message.headers[headerName];
  19020. // } else if (headerName.toLowerCase() === HeaderNames.RequestTimestamp.toLowerCase()) {
  19021. // requestTimestamp = message.headers[headerName];
  19022. }
  19023. else if (headerName.toLowerCase() === HeaderNames_js_1.HeaderNames.ContentType.toLowerCase()) {
  19024. contentType = message.headers[headerName];
  19025. }
  19026. else if (headerName.toLowerCase() === HeaderNames_js_1.HeaderNames.RequestStreamId.toLowerCase()) {
  19027. streamId = message.headers[headerName];
  19028. }
  19029. else {
  19030. additionalHeaders[headerName] = message.headers[headerName];
  19031. }
  19032. }
  19033. }
  19034. }
  19035. return new SpeechConnectionMessage(message.messageType, path, requestId, contentType, message.body, streamId, additionalHeaders, message.id);
  19036. }
  19037. }
  19038. exports.SpeechConnectionMessage = SpeechConnectionMessage;
  19039. /***/ }),
  19040. /* 208 */
  19041. /***/ ((__unused_webpack_module, exports) => {
  19042. "use strict";
  19043. //
  19044. // Copyright (c) Microsoft. All rights reserved.
  19045. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  19046. //
  19047. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19048. exports.SegmentationMode = void 0;
  19049. /**
  19050. * The segmentation mode.
  19051. */
  19052. var SegmentationMode;
  19053. (function (SegmentationMode) {
  19054. SegmentationMode["Normal"] = "Normal";
  19055. SegmentationMode["Disabled"] = "Disabled";
  19056. SegmentationMode["Custom"] = "Custom";
  19057. SegmentationMode["Semantic"] = "Semantic";
  19058. })(SegmentationMode = exports.SegmentationMode || (exports.SegmentationMode = {}));
  19059. /***/ }),
  19060. /* 209 */
  19061. /***/ ((__unused_webpack_module, exports) => {
  19062. "use strict";
  19063. //
  19064. // Copyright (c) Microsoft. All rights reserved.
  19065. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  19066. //
  19067. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19068. exports.NextAction = void 0;
  19069. /**
  19070. * The action to take on success
  19071. */
  19072. var NextAction;
  19073. (function (NextAction) {
  19074. NextAction["None"] = "None";
  19075. NextAction["Synthesize"] = "Synthesize";
  19076. })(NextAction = exports.NextAction || (exports.NextAction = {}));
  19077. /***/ }),
  19078. /* 210 */
  19079. /***/ ((__unused_webpack_module, exports) => {
  19080. "use strict";
  19081. //
  19082. // Copyright (c) Microsoft. All rights reserved.
  19083. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  19084. //
  19085. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19086. exports.Mode = void 0;
  19087. /**
  19088. * Result type
  19089. */
  19090. var Mode;
  19091. (function (Mode) {
  19092. Mode["None"] = "None";
  19093. Mode["Always"] = "Always";
  19094. })(Mode = exports.Mode || (exports.Mode = {}));
  19095. /***/ }),
  19096. /* 211 */
  19097. /***/ ((__unused_webpack_module, exports) => {
  19098. "use strict";
  19099. //
  19100. // Copyright (c) Microsoft. All rights reserved.
  19101. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  19102. //
  19103. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19104. exports.LanguageIdDetectionPriority = exports.LanguageIdDetectionMode = void 0;
  19105. /**
  19106. * The enum that represents which mode will language detection take place
  19107. * There is only detectAtAudioStart mode for now as language detection models are not trained for different modes
  19108. * This enum can be extended in future to support different modes
  19109. */
  19110. var LanguageIdDetectionMode;
  19111. (function (LanguageIdDetectionMode) {
  19112. LanguageIdDetectionMode["DetectAtAudioStart"] = "DetectAtAudioStart";
  19113. LanguageIdDetectionMode["DetectContinuous"] = "DetectContinuous";
  19114. LanguageIdDetectionMode["DetectSegments"] = "DetectSegments";
  19115. })(LanguageIdDetectionMode = exports.LanguageIdDetectionMode || (exports.LanguageIdDetectionMode = {}));
  19116. /**
  19117. * The language id detection mode, setting this will load the detection setting of MaxAudioDuration and MaxSpeechDuration
  19118. * If the maxAudioDuration and maxSpeechDuration is set in the speech.context, then this detection mode will be ignored
  19119. */
  19120. var LanguageIdDetectionPriority;
  19121. (function (LanguageIdDetectionPriority) {
  19122. /**
  19123. * default, Service decides the best mode to use.
  19124. */
  19125. LanguageIdDetectionPriority["Auto"] = "Auto";
  19126. /**
  19127. * Offers lower latency via a trade-off of accuracy.
  19128. */
  19129. LanguageIdDetectionPriority["PrioritizeLatency"] = "PrioritizeLatency";
  19130. /**
  19131. * Offers higher accuracy via a trade-off of latency.
  19132. */
  19133. LanguageIdDetectionPriority["PrioritizeAccuracy"] = "PrioritizeAccuracy";
  19134. })(LanguageIdDetectionPriority = exports.LanguageIdDetectionPriority || (exports.LanguageIdDetectionPriority = {}));
  19135. /***/ }),
  19136. /* 212 */
  19137. /***/ ((__unused_webpack_module, exports) => {
  19138. "use strict";
  19139. //
  19140. // Copyright (c) Microsoft. All rights reserved.
  19141. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  19142. //
  19143. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19144. exports.NextAction = void 0;
  19145. /**
  19146. * The action to take on successful language detection
  19147. */
  19148. var NextAction;
  19149. (function (NextAction) {
  19150. NextAction["Recognize"] = "Recognize";
  19151. NextAction["None"] = "None";
  19152. })(NextAction = exports.NextAction || (exports.NextAction = {}));
  19153. /***/ }),
  19154. /* 213 */
  19155. /***/ ((__unused_webpack_module, exports) => {
  19156. "use strict";
  19157. //
  19158. // Copyright (c) Microsoft. All rights reserved.
  19159. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  19160. //
  19161. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19162. exports.OnUnknownAction = void 0;
  19163. /**
  19164. * An enum that defines actions that can be taken on unknown language detection
  19165. */
  19166. var OnUnknownAction;
  19167. (function (OnUnknownAction) {
  19168. OnUnknownAction["RecognizeWithDefaultLanguage"] = "RecognizeWithDefaultLanguage";
  19169. OnUnknownAction["None"] = "None";
  19170. })(OnUnknownAction = exports.OnUnknownAction || (exports.OnUnknownAction = {}));
  19171. /***/ }),
  19172. /* 214 */
  19173. /***/ ((__unused_webpack_module, exports) => {
  19174. "use strict";
  19175. //
  19176. // Copyright (c) Microsoft. All rights reserved.
  19177. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  19178. //
  19179. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19180. exports.ResultType = void 0;
  19181. /**
  19182. * The result type enum
  19183. */
  19184. var ResultType;
  19185. (function (ResultType) {
  19186. ResultType["Auto"] = "Auto";
  19187. ResultType["StableFragment"] = "StableFragment";
  19188. ResultType["Hypothesis"] = "Hypothesis";
  19189. ResultType["None"] = "None";
  19190. })(ResultType = exports.ResultType || (exports.ResultType = {}));
  19191. /***/ }),
  19192. /* 215 */
  19193. /***/ ((__unused_webpack_module, exports) => {
  19194. "use strict";
  19195. //
  19196. // Copyright (c) Microsoft. All rights reserved.
  19197. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  19198. //
  19199. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19200. exports.PhraseResultOutputType = void 0;
  19201. /**
  19202. * The phrase result output type
  19203. */
  19204. var PhraseResultOutputType;
  19205. (function (PhraseResultOutputType) {
  19206. PhraseResultOutputType["Always"] = "Always";
  19207. PhraseResultOutputType["None"] = "None";
  19208. })(PhraseResultOutputType = exports.PhraseResultOutputType || (exports.PhraseResultOutputType = {}));
  19209. /***/ }),
  19210. /* 216 */
  19211. /***/ ((__unused_webpack_module, exports) => {
  19212. "use strict";
  19213. //
  19214. // Copyright (c) Microsoft. All rights reserved.
  19215. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  19216. //
  19217. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19218. exports.NextAction = void 0;
  19219. /**
  19220. * The action enum when speech recognition return a final phrase result
  19221. */
  19222. var NextAction;
  19223. (function (NextAction) {
  19224. NextAction["None"] = "None";
  19225. NextAction["Translate"] = "Translate";
  19226. })(NextAction = exports.NextAction || (exports.NextAction = {}));
  19227. /***/ }),
  19228. /* 217 */
  19229. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  19230. "use strict";
  19231. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19232. exports.ConversationServiceRecognizer = void 0;
  19233. const Exports_js_1 = __webpack_require__(79);
  19234. const Exports_js_2 = __webpack_require__(2);
  19235. class ConversationServiceRecognizer extends Exports_js_2.ServiceRecognizerBase {
  19236. constructor(authentication, connectionFactory, audioSource, recognizerConfig, recognizer) {
  19237. super(authentication, connectionFactory, audioSource, recognizerConfig, recognizer);
  19238. this.handleSpeechPhraseMessage = async (textBody) => this.handleSpeechPhrase(textBody);
  19239. this.handleSpeechHypothesisMessage = (textBody) => this.handleSpeechHypothesis(textBody);
  19240. }
  19241. processTypeSpecificMessages(connectionMessage) {
  19242. void connectionMessage;
  19243. return;
  19244. }
  19245. handleRecognizedCallback(result, offset, sessionId) {
  19246. void result;
  19247. void offset;
  19248. void sessionId;
  19249. return;
  19250. }
  19251. handleRecognizingCallback(result, duration, sessionId) {
  19252. void result;
  19253. void duration;
  19254. void sessionId;
  19255. return;
  19256. }
  19257. async processSpeechMessages(connectionMessage) {
  19258. let processed = false;
  19259. switch (connectionMessage.path.toLowerCase()) {
  19260. case "speech.hypothesis":
  19261. case "speech.fragment":
  19262. if (!!this.handleSpeechHypothesisMessage) {
  19263. this.handleSpeechHypothesisMessage(connectionMessage.textBody);
  19264. }
  19265. processed = true;
  19266. break;
  19267. case "speech.phrase":
  19268. if (!!this.handleSpeechPhraseMessage) {
  19269. await this.handleSpeechPhraseMessage(connectionMessage.textBody);
  19270. }
  19271. processed = true;
  19272. break;
  19273. default:
  19274. break;
  19275. }
  19276. return processed;
  19277. }
  19278. cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  19279. // Implementing to allow inheritance
  19280. void sessionId;
  19281. void requestId;
  19282. void cancellationReason;
  19283. void errorCode;
  19284. void error;
  19285. }
  19286. async handleSpeechPhrase(textBody) {
  19287. const simple = Exports_js_2.SimpleSpeechPhrase.fromJSON(textBody, this.privRequestSession.currentTurnAudioOffset);
  19288. const resultReason = Exports_js_2.EnumTranslation.implTranslateRecognitionResult(simple.RecognitionStatus);
  19289. let result;
  19290. const resultProps = new Exports_js_1.PropertyCollection();
  19291. resultProps.setProperty(Exports_js_1.PropertyId.SpeechServiceResponse_JsonResult, textBody);
  19292. this.privRequestSession.onPhraseRecognized(simple.Offset + simple.Duration);
  19293. if (Exports_js_1.ResultReason.Canceled === resultReason) {
  19294. const cancelReason = Exports_js_2.EnumTranslation.implTranslateCancelResult(simple.RecognitionStatus);
  19295. const cancellationErrorCode = Exports_js_2.EnumTranslation.implTranslateCancelErrorCode(simple.RecognitionStatus);
  19296. await this.cancelRecognitionLocal(cancelReason, cancellationErrorCode, Exports_js_2.EnumTranslation.implTranslateErrorDetails(cancellationErrorCode));
  19297. }
  19298. else {
  19299. if (simple.RecognitionStatus !== Exports_js_2.RecognitionStatus.EndOfDictation) {
  19300. if (this.privRecognizerConfig.parameters.getProperty(Exports_js_2.OutputFormatPropertyName) === Exports_js_1.OutputFormat[Exports_js_1.OutputFormat.Simple]) {
  19301. result = new Exports_js_1.SpeechRecognitionResult(this.privRequestSession.requestId, resultReason, simple.DisplayText, simple.Duration, simple.Offset, simple.Language, simple.LanguageDetectionConfidence, simple.SpeakerId, undefined, simple.asJson(), resultProps);
  19302. }
  19303. else {
  19304. const detailed = Exports_js_2.DetailedSpeechPhrase.fromJSON(textBody, this.privRequestSession.currentTurnAudioOffset);
  19305. result = new Exports_js_1.SpeechRecognitionResult(this.privRequestSession.requestId, resultReason, detailed.Text, detailed.Duration, detailed.Offset, detailed.Language, detailed.LanguageDetectionConfidence, detailed.SpeakerId, undefined, detailed.asJson(), resultProps);
  19306. }
  19307. this.handleRecognizedCallback(result, result.offset, this.privRequestSession.sessionId);
  19308. }
  19309. }
  19310. }
  19311. handleSpeechHypothesis(textBody) {
  19312. const hypothesis = Exports_js_2.SpeechHypothesis.fromJSON(textBody, this.privRequestSession.currentTurnAudioOffset);
  19313. const resultProps = new Exports_js_1.PropertyCollection();
  19314. resultProps.setProperty(Exports_js_1.PropertyId.SpeechServiceResponse_JsonResult, textBody);
  19315. const result = new Exports_js_1.SpeechRecognitionResult(this.privRequestSession.requestId, Exports_js_1.ResultReason.RecognizingSpeech, hypothesis.Text, hypothesis.Duration, hypothesis.Offset, hypothesis.Language, hypothesis.LanguageDetectionConfidence, hypothesis.SpeakerId, undefined, hypothesis.asJson(), resultProps);
  19316. this.privRequestSession.onHypothesis(hypothesis.Offset);
  19317. this.handleRecognizingCallback(result, hypothesis.Duration, this.privRequestSession.sessionId);
  19318. }
  19319. }
  19320. exports.ConversationServiceRecognizer = ConversationServiceRecognizer;
  19321. /***/ }),
  19322. /* 218 */
  19323. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  19324. "use strict";
  19325. // Copyright (c) Microsoft Corporation. All rights reserved.
  19326. // Licensed under the MIT license.
  19327. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19328. exports.RecognizerConfig = exports.SpeechResultFormat = void 0;
  19329. /* eslint-disable max-classes-per-file */
  19330. const Exports_js_1 = __webpack_require__(79);
  19331. const Exports_js_2 = __webpack_require__(2);
  19332. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  19333. var SpeechResultFormat;
  19334. (function (SpeechResultFormat) {
  19335. SpeechResultFormat[SpeechResultFormat["Simple"] = 0] = "Simple";
  19336. SpeechResultFormat[SpeechResultFormat["Detailed"] = 1] = "Detailed";
  19337. })(SpeechResultFormat = exports.SpeechResultFormat || (exports.SpeechResultFormat = {}));
  19338. class RecognizerConfig {
  19339. constructor(speechServiceConfig, parameters) {
  19340. this.privSpeechServiceConfig = speechServiceConfig ? speechServiceConfig : new Exports_js_2.SpeechServiceConfig(new Exports_js_2.Context(null));
  19341. this.privParameters = parameters;
  19342. this.privMaxRetryCount = parseInt(parameters.getProperty("SPEECH-Error-MaxRetryCount", "4"), 10);
  19343. this.privLanguageIdMode = parameters.getProperty(Exports_js_1.PropertyId.SpeechServiceConnection_LanguageIdMode, undefined);
  19344. this.privEnableSpeakerId = false;
  19345. }
  19346. get parameters() {
  19347. return this.privParameters;
  19348. }
  19349. get recognitionMode() {
  19350. return this.privRecognitionMode;
  19351. }
  19352. set recognitionMode(value) {
  19353. this.privRecognitionMode = value;
  19354. this.privRecognitionActivityTimeout = value === PhraseDetectionContext_js_1.RecognitionMode.Interactive ? 8000 : 25000;
  19355. this.privSpeechServiceConfig.Recognition = PhraseDetectionContext_js_1.RecognitionMode[value];
  19356. }
  19357. get SpeechServiceConfig() {
  19358. return this.privSpeechServiceConfig;
  19359. }
  19360. get recognitionActivityTimeout() {
  19361. return this.privRecognitionActivityTimeout;
  19362. }
  19363. get isContinuousRecognition() {
  19364. return this.privRecognitionMode !== PhraseDetectionContext_js_1.RecognitionMode.Interactive;
  19365. }
  19366. get languageIdMode() {
  19367. return this.privLanguageIdMode;
  19368. }
  19369. get autoDetectSourceLanguages() {
  19370. return this.parameters.getProperty(Exports_js_1.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages, undefined);
  19371. }
  19372. get recognitionEndpointVersion() {
  19373. return this.parameters.getProperty(Exports_js_1.PropertyId.SpeechServiceConnection_RecognitionEndpointVersion, "2");
  19374. }
  19375. set recognitionEndpointVersion(version) {
  19376. this.parameters.setProperty(Exports_js_1.PropertyId.SpeechServiceConnection_RecognitionEndpointVersion, version);
  19377. }
  19378. get sourceLanguageModels() {
  19379. const models = [];
  19380. let modelsExist = false;
  19381. if (this.autoDetectSourceLanguages !== undefined) {
  19382. for (const language of this.autoDetectSourceLanguages.split(",")) {
  19383. const customProperty = language + Exports_js_1.PropertyId.SpeechServiceConnection_EndpointId.toString();
  19384. const modelId = this.parameters.getProperty(customProperty, undefined);
  19385. if (modelId !== undefined) {
  19386. models.push({ language, endpoint: modelId });
  19387. modelsExist = true;
  19388. }
  19389. else {
  19390. models.push({ language, endpoint: "" });
  19391. }
  19392. }
  19393. }
  19394. return modelsExist ? models : undefined;
  19395. }
  19396. get maxRetryCount() {
  19397. return this.privMaxRetryCount;
  19398. }
  19399. get isSpeakerDiarizationEnabled() {
  19400. return this.privEnableSpeakerId;
  19401. }
  19402. set isSpeakerDiarizationEnabled(value) {
  19403. this.privEnableSpeakerId = value;
  19404. }
  19405. }
  19406. exports.RecognizerConfig = RecognizerConfig;
  19407. /***/ }),
  19408. /* 219 */
  19409. /***/ ((__unused_webpack_module, exports) => {
  19410. "use strict";
  19411. // Copyright (c) Microsoft Corporation. All rights reserved.
  19412. // Licensed under the MIT license.
  19413. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19414. /***/ }),
  19415. /* 220 */
  19416. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  19417. "use strict";
  19418. // Copyright (c) Microsoft Corporation. All rights reserved.
  19419. // Licensed under the MIT license.
  19420. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19421. exports.WebsocketMessageFormatter = void 0;
  19422. const Exports_js_1 = __webpack_require__(4);
  19423. const CRLF = "\r\n";
  19424. class WebsocketMessageFormatter {
  19425. toConnectionMessage(message) {
  19426. const deferral = new Exports_js_1.Deferred();
  19427. try {
  19428. if (message.messageType === Exports_js_1.MessageType.Text) {
  19429. const textMessage = message.textContent;
  19430. let headers = {};
  19431. let body = null;
  19432. if (textMessage) {
  19433. const headerBodySplit = textMessage.split("\r\n\r\n");
  19434. if (headerBodySplit && headerBodySplit.length > 0) {
  19435. headers = this.parseHeaders(headerBodySplit[0]);
  19436. if (headerBodySplit.length > 1) {
  19437. body = headerBodySplit[1];
  19438. }
  19439. }
  19440. }
  19441. deferral.resolve(new Exports_js_1.ConnectionMessage(message.messageType, body, headers, message.id));
  19442. }
  19443. else if (message.messageType === Exports_js_1.MessageType.Binary) {
  19444. const binaryMessage = message.binaryContent;
  19445. let headers = {};
  19446. let body = null;
  19447. if (!binaryMessage || binaryMessage.byteLength < 2) {
  19448. throw new Error("Invalid binary message format. Header length missing.");
  19449. }
  19450. const dataView = new DataView(binaryMessage);
  19451. const headerLength = dataView.getInt16(0);
  19452. if (binaryMessage.byteLength < headerLength + 2) {
  19453. throw new Error("Invalid binary message format. Header content missing.");
  19454. }
  19455. let headersString = "";
  19456. for (let i = 0; i < headerLength; i++) {
  19457. headersString += String.fromCharCode((dataView).getInt8(i + 2));
  19458. }
  19459. headers = this.parseHeaders(headersString);
  19460. if (binaryMessage.byteLength > headerLength + 2) {
  19461. body = binaryMessage.slice(2 + headerLength);
  19462. }
  19463. deferral.resolve(new Exports_js_1.ConnectionMessage(message.messageType, body, headers, message.id));
  19464. }
  19465. }
  19466. catch (e) {
  19467. deferral.reject(`Error formatting the message. Error: ${e}`);
  19468. }
  19469. return deferral.promise;
  19470. }
  19471. fromConnectionMessage(message) {
  19472. const deferral = new Exports_js_1.Deferred();
  19473. try {
  19474. if (message.messageType === Exports_js_1.MessageType.Text) {
  19475. const payload = `${this.makeHeaders(message)}${CRLF}${message.textBody ? message.textBody : ""}`;
  19476. deferral.resolve(new Exports_js_1.RawWebsocketMessage(Exports_js_1.MessageType.Text, payload, message.id));
  19477. }
  19478. else if (message.messageType === Exports_js_1.MessageType.Binary) {
  19479. const headersString = this.makeHeaders(message);
  19480. const content = message.binaryBody;
  19481. const headerBuffer = this.stringToArrayBuffer(headersString);
  19482. const headerInt8Array = new Int8Array(headerBuffer);
  19483. const headerLength = headerInt8Array.byteLength;
  19484. const payloadInt8Array = new Int8Array(2 + headerLength + (content ? content.byteLength : 0));
  19485. payloadInt8Array[0] = ((headerLength >> 8) & 0xff);
  19486. payloadInt8Array[1] = headerLength & 0xff;
  19487. payloadInt8Array.set(headerInt8Array, 2);
  19488. if (content) {
  19489. const bodyInt8Array = new Int8Array(content);
  19490. payloadInt8Array.set(bodyInt8Array, 2 + headerLength);
  19491. }
  19492. const payload = payloadInt8Array.buffer;
  19493. deferral.resolve(new Exports_js_1.RawWebsocketMessage(Exports_js_1.MessageType.Binary, payload, message.id));
  19494. }
  19495. }
  19496. catch (e) {
  19497. deferral.reject(`Error formatting the message. ${e}`);
  19498. }
  19499. return deferral.promise;
  19500. }
  19501. makeHeaders(message) {
  19502. let headersString = "";
  19503. if (message.headers) {
  19504. for (const header in message.headers) {
  19505. if (header) {
  19506. headersString += `${header}: ${message.headers[header]}${CRLF}`;
  19507. }
  19508. }
  19509. }
  19510. return headersString;
  19511. }
  19512. parseHeaders(headersString) {
  19513. const headers = {};
  19514. if (headersString) {
  19515. const headerMatches = headersString.match(/[^\r\n]+/g);
  19516. if (headers) {
  19517. for (const header of headerMatches) {
  19518. if (header) {
  19519. const separatorIndex = header.indexOf(":");
  19520. const headerName = separatorIndex > 0 ? header.substr(0, separatorIndex).trim().toLowerCase() : header;
  19521. const headerValue = separatorIndex > 0 && header.length > (separatorIndex + 1) ?
  19522. header.substr(separatorIndex + 1).trim() :
  19523. "";
  19524. headers[headerName] = headerValue;
  19525. }
  19526. }
  19527. }
  19528. }
  19529. return headers;
  19530. }
  19531. stringToArrayBuffer(str) {
  19532. const buffer = new ArrayBuffer(str.length);
  19533. const view = new DataView(buffer);
  19534. for (let i = 0; i < str.length; i++) {
  19535. view.setUint8(i, str.charCodeAt(i));
  19536. }
  19537. return buffer;
  19538. }
  19539. }
  19540. exports.WebsocketMessageFormatter = WebsocketMessageFormatter;
  19541. /***/ }),
  19542. /* 221 */
  19543. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  19544. "use strict";
  19545. // Copyright (c) Microsoft Corporation. All rights reserved.
  19546. // Licensed under the MIT license.
  19547. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19548. exports.SpeechConnectionFactory = void 0;
  19549. const Exports_js_1 = __webpack_require__(60);
  19550. const Exports_js_2 = __webpack_require__(2);
  19551. const Exports_js_3 = __webpack_require__(79);
  19552. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  19553. const Exports_js_4 = __webpack_require__(2);
  19554. const HeaderNames_js_1 = __webpack_require__(54);
  19555. const QueryParameterNames_js_1 = __webpack_require__(136);
  19556. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  19557. class SpeechConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {
  19558. constructor() {
  19559. super(...arguments);
  19560. this.interactiveRelativeUri = "/speech/recognition/interactive/cognitiveservices/v1";
  19561. this.conversationRelativeUri = "/speech/recognition/conversation/cognitiveservices/v1";
  19562. this.dictationRelativeUri = "/speech/recognition/dictation/cognitiveservices/v1";
  19563. this.universalUri = "/stt/speech/universal/v";
  19564. }
  19565. async create(config, authInfo, connectionId) {
  19566. let endpoint = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Endpoint, undefined);
  19567. const region = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Region, undefined);
  19568. const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);
  19569. const host = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Host, "wss://" + region + ".stt.speech" + hostSuffix);
  19570. const queryParams = {};
  19571. const endpointId = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_EndpointId, undefined);
  19572. const language = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage, undefined);
  19573. if (endpointId) {
  19574. if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId) === -1) {
  19575. queryParams[QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId] = endpointId;
  19576. }
  19577. }
  19578. else if (language) {
  19579. if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.Language) === -1) {
  19580. queryParams[QueryParameterNames_js_1.QueryParameterNames.Language] = language;
  19581. }
  19582. }
  19583. if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.Format) === -1) {
  19584. queryParams[QueryParameterNames_js_1.QueryParameterNames.Format] = config.parameters.getProperty(Exports_js_2.OutputFormatPropertyName, Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Simple]).toLowerCase();
  19585. }
  19586. if (config.autoDetectSourceLanguages !== undefined) {
  19587. queryParams[QueryParameterNames_js_1.QueryParameterNames.EnableLanguageId] = "true";
  19588. }
  19589. this.setCommonUrlParams(config, queryParams, endpoint);
  19590. if (!!endpoint) {
  19591. const endpointUrl = new URL(endpoint);
  19592. const pathName = endpointUrl.pathname;
  19593. if (pathName === "" || pathName === "/") {
  19594. // We need to generate the path, and we need to check for a redirect.
  19595. endpointUrl.pathname = this.universalUri + config.recognitionEndpointVersion;
  19596. endpoint = await ConnectionFactoryBase_js_1.ConnectionFactoryBase.getRedirectUrlFromEndpoint(endpointUrl.toString());
  19597. }
  19598. }
  19599. if (!endpoint) {
  19600. switch (config.recognitionMode) {
  19601. case PhraseDetectionContext_js_1.RecognitionMode.Conversation:
  19602. if (config.parameters.getProperty(Exports_js_2.ForceDictationPropertyName, "false") === "true") {
  19603. endpoint = host + this.dictationRelativeUri;
  19604. }
  19605. else {
  19606. if (config.recognitionEndpointVersion !== undefined && parseInt(config.recognitionEndpointVersion, 10) > 1) {
  19607. endpoint = `${host}${this.universalUri}${config.recognitionEndpointVersion}`;
  19608. }
  19609. else {
  19610. endpoint = host + this.conversationRelativeUri;
  19611. }
  19612. }
  19613. break;
  19614. case PhraseDetectionContext_js_1.RecognitionMode.Dictation:
  19615. endpoint = host + this.dictationRelativeUri;
  19616. break;
  19617. default:
  19618. if (config.recognitionEndpointVersion !== undefined && parseInt(config.recognitionEndpointVersion, 10) > 1) {
  19619. endpoint = `${host}${this.universalUri}${config.recognitionEndpointVersion}`;
  19620. }
  19621. else {
  19622. endpoint = host + this.interactiveRelativeUri; // default is interactive
  19623. }
  19624. break;
  19625. }
  19626. }
  19627. const headers = {};
  19628. if (authInfo.token !== undefined && authInfo.token !== "") {
  19629. headers[authInfo.headerName] = authInfo.token;
  19630. }
  19631. headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;
  19632. headers.connectionId = connectionId;
  19633. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "false") === "true";
  19634. const webSocketConnection = new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_4.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);
  19635. // Set the value of SpeechServiceConnection_Url to webSocketConnection.uri (and not to `endpoint`), since this value is the final
  19636. // URI that was used to make the connection (including query parameters).
  19637. const uri = webSocketConnection.uri;
  19638. config.parameters.setProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Url, uri);
  19639. return webSocketConnection;
  19640. }
  19641. }
  19642. exports.SpeechConnectionFactory = SpeechConnectionFactory;
  19643. /***/ }),
  19644. /* 222 */
  19645. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  19646. "use strict";
  19647. // Copyright (c) Microsoft Corporation. All rights reserved.
  19648. // Licensed under the MIT license.
  19649. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19650. exports.ConversationTranscriberConnectionFactory = void 0;
  19651. const Exports_js_1 = __webpack_require__(60);
  19652. const Exports_js_2 = __webpack_require__(79);
  19653. const Exports_js_3 = __webpack_require__(2);
  19654. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  19655. const Exports_js_4 = __webpack_require__(2);
  19656. const HeaderNames_js_1 = __webpack_require__(54);
  19657. const QueryParameterNames_js_1 = __webpack_require__(136);
  19658. class ConversationTranscriberConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {
  19659. constructor() {
  19660. super(...arguments);
  19661. this.universalUri = "/speech/universal/v2";
  19662. }
  19663. async create(config, authInfo, connectionId) {
  19664. let endpoint = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint, undefined);
  19665. const region = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region, undefined);
  19666. const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);
  19667. const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, "wss://" + region + ".stt.speech" + hostSuffix);
  19668. const queryParams = {};
  19669. const endpointId = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_EndpointId, undefined);
  19670. const language = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage, undefined);
  19671. if (endpointId) {
  19672. if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId) === -1) {
  19673. queryParams[QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId] = endpointId;
  19674. }
  19675. }
  19676. else if (language) {
  19677. if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.Language) === -1) {
  19678. queryParams[QueryParameterNames_js_1.QueryParameterNames.Language] = language;
  19679. }
  19680. }
  19681. if (config.autoDetectSourceLanguages !== undefined) {
  19682. queryParams[QueryParameterNames_js_1.QueryParameterNames.EnableLanguageId] = "true";
  19683. }
  19684. this.setV2UrlParams(config, queryParams, endpoint);
  19685. if (!!endpoint) {
  19686. const endpointUrl = new URL(endpoint);
  19687. const pathName = endpointUrl.pathname;
  19688. if (pathName === "" || pathName === "/") {
  19689. // We need to generate the path, and we need to check for a redirect.
  19690. endpointUrl.pathname = this.universalUri;
  19691. endpoint = await ConnectionFactoryBase_js_1.ConnectionFactoryBase.getRedirectUrlFromEndpoint(endpointUrl.toString());
  19692. }
  19693. }
  19694. if (!endpoint) {
  19695. endpoint = `${host}${this.universalUri}`;
  19696. }
  19697. const headers = {};
  19698. if (authInfo.token !== undefined && authInfo.token !== "") {
  19699. headers[authInfo.headerName] = authInfo.token;
  19700. }
  19701. headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;
  19702. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "false") === "true";
  19703. const webSocketConnection = new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_4.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);
  19704. // Set the value of SpeechServiceConnection_Url to webSocketConnection.uri (and not to `endpoint`), since this value is the final
  19705. // URI that was used to make the connection (including query parameters).
  19706. const uri = webSocketConnection.uri;
  19707. config.parameters.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Url, uri);
  19708. return webSocketConnection;
  19709. }
  19710. setV2UrlParams(config, queryParams, endpoint) {
  19711. const propertyIdToParameterMap = new Map([
  19712. [Exports_js_2.PropertyId.Speech_SegmentationSilenceTimeoutMs, QueryParameterNames_js_1.QueryParameterNames.SegmentationSilenceTimeoutMs],
  19713. [Exports_js_2.PropertyId.SpeechServiceConnection_EnableAudioLogging, QueryParameterNames_js_1.QueryParameterNames.EnableAudioLogging],
  19714. [Exports_js_2.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, QueryParameterNames_js_1.QueryParameterNames.EndSilenceTimeoutMs],
  19715. [Exports_js_2.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, QueryParameterNames_js_1.QueryParameterNames.InitialSilenceTimeoutMs],
  19716. [Exports_js_2.PropertyId.SpeechServiceResponse_PostProcessingOption, QueryParameterNames_js_1.QueryParameterNames.Postprocessing],
  19717. [Exports_js_2.PropertyId.SpeechServiceResponse_ProfanityOption, QueryParameterNames_js_1.QueryParameterNames.Profanity],
  19718. [Exports_js_2.PropertyId.SpeechServiceResponse_StablePartialResultThreshold, QueryParameterNames_js_1.QueryParameterNames.StableIntermediateThreshold],
  19719. ]);
  19720. propertyIdToParameterMap.forEach((parameterName, propertyId) => {
  19721. this.setUrlParameter(propertyId, parameterName, config, queryParams, endpoint);
  19722. });
  19723. const serviceProperties = JSON.parse(config.parameters.getProperty(Exports_js_3.ServicePropertiesPropertyName, "{}"));
  19724. Object.keys(serviceProperties).forEach((value) => {
  19725. queryParams[value] = serviceProperties[value];
  19726. });
  19727. }
  19728. }
  19729. exports.ConversationTranscriberConnectionFactory = ConversationTranscriberConnectionFactory;
  19730. /***/ }),
  19731. /* 223 */
  19732. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  19733. "use strict";
  19734. // Copyright (c) Microsoft Corporation. All rights reserved.
  19735. // Licensed under the MIT license.
  19736. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19737. exports.TranscriberConnectionFactory = void 0;
  19738. const Exports_js_1 = __webpack_require__(60);
  19739. const Exports_js_2 = __webpack_require__(79);
  19740. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  19741. const Exports_js_3 = __webpack_require__(2);
  19742. const HeaderNames_js_1 = __webpack_require__(54);
  19743. const QueryParameterNames_js_1 = __webpack_require__(136);
  19744. class TranscriberConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {
  19745. constructor() {
  19746. super(...arguments);
  19747. this.multiaudioRelativeUri = "/speech/recognition/multiaudio";
  19748. }
  19749. create(config, authInfo, connectionId) {
  19750. let endpoint = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint, undefined);
  19751. const region = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region, "centralus");
  19752. const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);
  19753. const hostDefault = "wss://transcribe." + region + ".cts.speech" + hostSuffix + this.multiaudioRelativeUri;
  19754. const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, hostDefault);
  19755. const queryParams = {};
  19756. this.setQueryParams(queryParams, config, endpoint);
  19757. if (!endpoint) {
  19758. endpoint = host;
  19759. }
  19760. const headers = {};
  19761. if (authInfo.token !== undefined && authInfo.token !== "") {
  19762. headers[authInfo.headerName] = authInfo.token;
  19763. }
  19764. headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;
  19765. config.parameters.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Url, endpoint);
  19766. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "false") === "true";
  19767. return Promise.resolve(new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_3.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId));
  19768. }
  19769. setQueryParams(queryParams, config, endpointUrl) {
  19770. const endpointId = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_EndpointId, undefined);
  19771. const language = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage, undefined);
  19772. if (endpointId && !(QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId in queryParams)) {
  19773. queryParams[QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId] = endpointId;
  19774. }
  19775. if (language && !(QueryParameterNames_js_1.QueryParameterNames.Language in queryParams)) {
  19776. queryParams[QueryParameterNames_js_1.QueryParameterNames.Language] = language;
  19777. }
  19778. const wordLevelTimings = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, "false").toLowerCase() === "true";
  19779. const detailed = config.parameters.getProperty(Exports_js_3.OutputFormatPropertyName, Exports_js_2.OutputFormat[Exports_js_2.OutputFormat.Simple]) !== Exports_js_2.OutputFormat[Exports_js_2.OutputFormat.Simple];
  19780. if (wordLevelTimings || detailed) {
  19781. queryParams[QueryParameterNames_js_1.QueryParameterNames.Format] = Exports_js_2.OutputFormat[Exports_js_2.OutputFormat.Detailed].toLowerCase();
  19782. }
  19783. this.setCommonUrlParams(config, queryParams, endpointUrl);
  19784. }
  19785. }
  19786. exports.TranscriberConnectionFactory = TranscriberConnectionFactory;
  19787. /***/ }),
  19788. /* 224 */
  19789. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  19790. "use strict";
  19791. // Copyright (c) Microsoft Corporation. All rights reserved.
  19792. // Licensed under the MIT license.
  19793. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19794. exports.TranslationConnectionFactory = void 0;
  19795. const Exports_js_1 = __webpack_require__(60);
  19796. const StringUtils_js_1 = __webpack_require__(167);
  19797. const Exports_js_2 = __webpack_require__(79);
  19798. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  19799. const Exports_js_3 = __webpack_require__(2);
  19800. const HeaderNames_js_1 = __webpack_require__(54);
  19801. const QueryParameterNames_js_1 = __webpack_require__(136);
  19802. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  19803. class TranslationConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {
  19804. constructor() {
  19805. super(...arguments);
  19806. this.universalUri = "/stt/speech/universal/v2";
  19807. this.translationV1Uri = "/speech/translation/cognitiveservices/v1";
  19808. }
  19809. async create(config, authInfo, connectionId) {
  19810. let endpoint = this.getEndpointUrl(config);
  19811. const queryParams = {};
  19812. // Determine if we're using V1 or V2 endpoint
  19813. this.setQueryParams(queryParams, config, endpoint);
  19814. if (!!endpoint) {
  19815. const endpointUrl = new URL(endpoint);
  19816. const pathName = endpointUrl.pathname;
  19817. if (pathName === "" || pathName === "/") {
  19818. // We need to generate the path, and we need to check for a redirect.
  19819. endpointUrl.pathname = this.universalUri;
  19820. endpoint = await ConnectionFactoryBase_js_1.ConnectionFactoryBase.getRedirectUrlFromEndpoint(endpointUrl.toString());
  19821. }
  19822. }
  19823. const headers = {};
  19824. if (authInfo.token !== undefined && authInfo.token !== "") {
  19825. headers[authInfo.headerName] = authInfo.token;
  19826. }
  19827. headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;
  19828. config.parameters.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Url, endpoint);
  19829. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "false") === "true";
  19830. const webSocketConnection = new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_3.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);
  19831. return webSocketConnection;
  19832. }
  19833. getEndpointUrl(config, returnRegionPlaceholder) {
  19834. const region = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region);
  19835. const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);
  19836. // First check for an explicitly specified endpoint
  19837. let endpointUrl = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint, undefined);
  19838. // If an explicit endpoint is provided, use it
  19839. if (endpointUrl) {
  19840. if (returnRegionPlaceholder === true) {
  19841. return endpointUrl;
  19842. }
  19843. return StringUtils_js_1.StringUtils.formatString(endpointUrl, { region });
  19844. }
  19845. // Check if V1 endpoint is explicitly requested
  19846. const forceV1Endpoint = config.parameters.getProperty("SPEECH-ForceV1Endpoint", "false") === "true";
  19847. if (forceV1Endpoint) {
  19848. // Use V1 endpoint with s2s.speech host
  19849. const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, "wss://{region}.s2s.speech" + hostSuffix);
  19850. endpointUrl = host + this.translationV1Uri;
  19851. }
  19852. else {
  19853. // Default to V2 endpoint with stt.speech host
  19854. const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, "wss://{region}.stt.speech" + hostSuffix);
  19855. endpointUrl = host + this.universalUri;
  19856. }
  19857. if (returnRegionPlaceholder === true) {
  19858. return endpointUrl;
  19859. }
  19860. return StringUtils_js_1.StringUtils.formatString(endpointUrl, { region });
  19861. }
  19862. setQueryParams(queryParams, config, endpointUrl) {
  19863. // Common parameters for both V1 and V2 endpoints
  19864. queryParams.from = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage);
  19865. queryParams.to = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationToLanguages);
  19866. queryParams.scenario = config.recognitionMode === PhraseDetectionContext_js_1.RecognitionMode.Interactive ? "interactive" :
  19867. config.recognitionMode === PhraseDetectionContext_js_1.RecognitionMode.Conversation ? "conversation" : "";
  19868. // Set common parameters
  19869. this.setCommonUrlParams(config, queryParams, endpointUrl);
  19870. this.setUrlParameter(Exports_js_2.PropertyId.SpeechServiceResponse_TranslationRequestStablePartialResult, QueryParameterNames_js_1.QueryParameterNames.StableTranslation, config, queryParams, endpointUrl);
  19871. // Handle translation voice if specified
  19872. const translationVoice = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationVoice, undefined);
  19873. if (translationVoice !== undefined) {
  19874. queryParams.voice = translationVoice;
  19875. // Updated to match C++ implementation
  19876. queryParams.features = "requireVoice";
  19877. }
  19878. }
  19879. }
  19880. exports.TranslationConnectionFactory = TranslationConnectionFactory;
  19881. /***/ }),
  19882. /* 225 */
  19883. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  19884. "use strict";
  19885. // Copyright (c) Microsoft Corporation. All rights reserved.
  19886. // Licensed under the MIT license.
  19887. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19888. exports.EnumTranslation = void 0;
  19889. const Exports_js_1 = __webpack_require__(79);
  19890. const Exports_js_2 = __webpack_require__(2);
  19891. class EnumTranslation {
  19892. static implTranslateRecognitionResult(recognitionStatus, expectEndOfDictation = false) {
  19893. let reason = Exports_js_1.ResultReason.Canceled;
  19894. switch (recognitionStatus) {
  19895. case Exports_js_2.RecognitionStatus.Success:
  19896. reason = Exports_js_1.ResultReason.RecognizedSpeech;
  19897. break;
  19898. case Exports_js_2.RecognitionStatus.EndOfDictation:
  19899. // If we need the result in EndOfDictation (typically some session level result),
  19900. // translate into RecognizedSpeech, otherwise NoMatch
  19901. reason = expectEndOfDictation ? Exports_js_1.ResultReason.RecognizedSpeech : Exports_js_1.ResultReason.NoMatch;
  19902. break;
  19903. case Exports_js_2.RecognitionStatus.NoMatch:
  19904. case Exports_js_2.RecognitionStatus.InitialSilenceTimeout:
  19905. case Exports_js_2.RecognitionStatus.BabbleTimeout:
  19906. reason = Exports_js_1.ResultReason.NoMatch;
  19907. break;
  19908. case Exports_js_2.RecognitionStatus.Error:
  19909. case Exports_js_2.RecognitionStatus.BadRequest:
  19910. case Exports_js_2.RecognitionStatus.Forbidden:
  19911. default:
  19912. reason = Exports_js_1.ResultReason.Canceled;
  19913. break;
  19914. }
  19915. return reason;
  19916. }
  19917. static implTranslateCancelResult(recognitionStatus) {
  19918. let reason = Exports_js_1.CancellationReason.EndOfStream;
  19919. switch (recognitionStatus) {
  19920. case Exports_js_2.RecognitionStatus.Success:
  19921. case Exports_js_2.RecognitionStatus.EndOfDictation:
  19922. case Exports_js_2.RecognitionStatus.NoMatch:
  19923. reason = Exports_js_1.CancellationReason.EndOfStream;
  19924. break;
  19925. case Exports_js_2.RecognitionStatus.InitialSilenceTimeout:
  19926. case Exports_js_2.RecognitionStatus.BabbleTimeout:
  19927. case Exports_js_2.RecognitionStatus.Error:
  19928. case Exports_js_2.RecognitionStatus.BadRequest:
  19929. case Exports_js_2.RecognitionStatus.Forbidden:
  19930. default:
  19931. reason = Exports_js_1.CancellationReason.Error;
  19932. break;
  19933. }
  19934. return reason;
  19935. }
  19936. static implTranslateCancelErrorCode(recognitionStatus) {
  19937. let reason = Exports_js_1.CancellationErrorCode.NoError;
  19938. switch (recognitionStatus) {
  19939. case Exports_js_2.RecognitionStatus.Error:
  19940. reason = Exports_js_1.CancellationErrorCode.ServiceError;
  19941. break;
  19942. case Exports_js_2.RecognitionStatus.TooManyRequests:
  19943. reason = Exports_js_1.CancellationErrorCode.TooManyRequests;
  19944. break;
  19945. case Exports_js_2.RecognitionStatus.BadRequest:
  19946. reason = Exports_js_1.CancellationErrorCode.BadRequestParameters;
  19947. break;
  19948. case Exports_js_2.RecognitionStatus.Forbidden:
  19949. reason = Exports_js_1.CancellationErrorCode.Forbidden;
  19950. break;
  19951. default:
  19952. reason = Exports_js_1.CancellationErrorCode.NoError;
  19953. break;
  19954. }
  19955. return reason;
  19956. }
  19957. static implTranslateErrorDetails(cancellationErrorCode) {
  19958. let errorDetails = "The speech service encountered an internal error and could not continue.";
  19959. switch (cancellationErrorCode) {
  19960. case Exports_js_1.CancellationErrorCode.Forbidden:
  19961. errorDetails = "The recognizer is using a free subscription that ran out of quota.";
  19962. break;
  19963. case Exports_js_1.CancellationErrorCode.BadRequestParameters:
  19964. errorDetails = "Invalid parameter or unsupported audio format in the request.";
  19965. break;
  19966. case Exports_js_1.CancellationErrorCode.TooManyRequests:
  19967. errorDetails = "The number of parallel requests exceeded the number of allowed concurrent transcriptions.";
  19968. break;
  19969. default:
  19970. break;
  19971. }
  19972. return errorDetails;
  19973. }
  19974. }
  19975. exports.EnumTranslation = EnumTranslation;
  19976. /***/ }),
  19977. /* 226 */
  19978. /***/ ((__unused_webpack_module, exports) => {
  19979. "use strict";
  19980. // Copyright (c) Microsoft Corporation. All rights reserved.
  19981. // Licensed under the MIT license.
  19982. Object.defineProperty(exports, "__esModule", ({ value: true }));
  19983. exports.RecognitionStatus = exports.SynthesisStatus = void 0;
  19984. /**
  19985. * @class SynthesisStatus
  19986. * @private
  19987. */
  19988. var SynthesisStatus;
  19989. (function (SynthesisStatus) {
  19990. /**
  19991. * The response contains valid audio data.
  19992. * @member SynthesisStatus.Success
  19993. */
  19994. SynthesisStatus[SynthesisStatus["Success"] = 0] = "Success";
  19995. /**
  19996. * Indicates the end of audio data. No valid audio data is included in the message.
  19997. * @member SynthesisStatus.SynthesisEnd
  19998. */
  19999. SynthesisStatus[SynthesisStatus["SynthesisEnd"] = 1] = "SynthesisEnd";
  20000. /**
  20001. * Indicates an error occurred during synthesis data processing.
  20002. * @member SynthesisStatus.Error
  20003. */
  20004. SynthesisStatus[SynthesisStatus["Error"] = 2] = "Error";
  20005. })(SynthesisStatus = exports.SynthesisStatus || (exports.SynthesisStatus = {}));
  20006. var RecognitionStatus;
  20007. (function (RecognitionStatus) {
  20008. RecognitionStatus[RecognitionStatus["Success"] = 0] = "Success";
  20009. RecognitionStatus[RecognitionStatus["NoMatch"] = 1] = "NoMatch";
  20010. RecognitionStatus[RecognitionStatus["InitialSilenceTimeout"] = 2] = "InitialSilenceTimeout";
  20011. RecognitionStatus[RecognitionStatus["BabbleTimeout"] = 3] = "BabbleTimeout";
  20012. RecognitionStatus[RecognitionStatus["Error"] = 4] = "Error";
  20013. RecognitionStatus[RecognitionStatus["EndOfDictation"] = 5] = "EndOfDictation";
  20014. RecognitionStatus[RecognitionStatus["TooManyRequests"] = 6] = "TooManyRequests";
  20015. RecognitionStatus[RecognitionStatus["BadRequest"] = 7] = "BadRequest";
  20016. RecognitionStatus[RecognitionStatus["Forbidden"] = 8] = "Forbidden";
  20017. })(RecognitionStatus = exports.RecognitionStatus || (exports.RecognitionStatus = {}));
  20018. /***/ }),
  20019. /* 227 */
  20020. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20021. "use strict";
  20022. // Copyright (c) Microsoft Corporation. All rights reserved.
  20023. // Licensed under the MIT license.
  20024. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20025. exports.TranslationSynthesisEnd = void 0;
  20026. const Exports_js_1 = __webpack_require__(2);
  20027. class TranslationSynthesisEnd {
  20028. constructor(json) {
  20029. this.privSynthesisEnd = JSON.parse(json);
  20030. if (!!this.privSynthesisEnd.SynthesisStatus) {
  20031. this.privSynthesisEnd.SynthesisStatus = Exports_js_1.SynthesisStatus[this.privSynthesisEnd.SynthesisStatus];
  20032. }
  20033. if (!!this.privSynthesisEnd.Status) {
  20034. this.privSynthesisEnd.SynthesisStatus = Exports_js_1.SynthesisStatus[this.privSynthesisEnd.Status];
  20035. }
  20036. }
  20037. static fromJSON(json) {
  20038. return new TranslationSynthesisEnd(json);
  20039. }
  20040. get SynthesisStatus() {
  20041. return this.privSynthesisEnd.SynthesisStatus;
  20042. }
  20043. get FailureReason() {
  20044. return this.privSynthesisEnd.FailureReason;
  20045. }
  20046. }
  20047. exports.TranslationSynthesisEnd = TranslationSynthesisEnd;
  20048. /***/ }),
  20049. /* 228 */
  20050. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20051. "use strict";
  20052. // Copyright (c) Microsoft Corporation. All rights reserved.
  20053. // Licensed under the MIT license.
  20054. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20055. exports.TranslationHypothesis = void 0;
  20056. const Contracts_js_1 = __webpack_require__(64);
  20057. const TranslationStatus_js_1 = __webpack_require__(48);
  20058. class TranslationHypothesis {
  20059. constructor(hypothesis, baseOffset) {
  20060. this.privTranslationHypothesis = hypothesis;
  20061. this.privTranslationHypothesis.Offset += baseOffset;
  20062. this.privTranslationHypothesis.Translation.TranslationStatus = this.mapTranslationStatus(this.privTranslationHypothesis.Translation.TranslationStatus);
  20063. }
  20064. static fromJSON(json, baseOffset) {
  20065. return new TranslationHypothesis(JSON.parse(json), baseOffset);
  20066. }
  20067. static fromTranslationResponse(translationHypothesis, baseOffset) {
  20068. Contracts_js_1.Contracts.throwIfNullOrUndefined(translationHypothesis, "translationHypothesis");
  20069. const hypothesis = translationHypothesis.SpeechHypothesis;
  20070. translationHypothesis.SpeechHypothesis = undefined;
  20071. hypothesis.Translation = translationHypothesis;
  20072. return new TranslationHypothesis(hypothesis, baseOffset);
  20073. }
  20074. get Duration() {
  20075. return this.privTranslationHypothesis.Duration;
  20076. }
  20077. get Offset() {
  20078. return this.privTranslationHypothesis.Offset;
  20079. }
  20080. get Text() {
  20081. return this.privTranslationHypothesis.Text;
  20082. }
  20083. get Translation() {
  20084. return this.privTranslationHypothesis.Translation;
  20085. }
  20086. get Language() {
  20087. return this.privTranslationHypothesis.PrimaryLanguage?.Language;
  20088. }
  20089. asJson() {
  20090. const jsonObj = { ...this.privTranslationHypothesis };
  20091. // Convert the enum value to its string representation for serialization purposes.
  20092. return jsonObj.Translation !== undefined ? JSON.stringify({
  20093. ...jsonObj,
  20094. TranslationStatus: TranslationStatus_js_1.TranslationStatus[jsonObj.Translation.TranslationStatus]
  20095. }) : JSON.stringify(jsonObj);
  20096. }
  20097. mapTranslationStatus(status) {
  20098. if (typeof status === "string") {
  20099. return TranslationStatus_js_1.TranslationStatus[status];
  20100. }
  20101. else if (typeof status === "number") {
  20102. return status;
  20103. }
  20104. }
  20105. }
  20106. exports.TranslationHypothesis = TranslationHypothesis;
  20107. /***/ }),
  20108. /* 229 */
  20109. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20110. "use strict";
  20111. // Copyright (c) Microsoft Corporation. All rights reserved.
  20112. // Licensed under the MIT license.
  20113. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20114. exports.TranslationPhrase = void 0;
  20115. const Contracts_js_1 = __webpack_require__(64);
  20116. const Exports_js_1 = __webpack_require__(2);
  20117. const TranslationStatus_js_1 = __webpack_require__(48);
  20118. class TranslationPhrase {
  20119. constructor(phrase, baseOffset) {
  20120. this.privTranslationPhrase = phrase;
  20121. this.privTranslationPhrase.Offset += baseOffset;
  20122. this.privTranslationPhrase.RecognitionStatus = this.mapRecognitionStatus(this.privTranslationPhrase.RecognitionStatus);
  20123. if (this.privTranslationPhrase.Translation !== undefined) {
  20124. this.privTranslationPhrase.Translation.TranslationStatus = this.mapTranslationStatus(this.privTranslationPhrase.Translation.TranslationStatus);
  20125. }
  20126. }
  20127. static fromJSON(json, baseOffset) {
  20128. return new TranslationPhrase(JSON.parse(json), baseOffset);
  20129. }
  20130. static fromTranslationResponse(translationResponse, baseOffset) {
  20131. Contracts_js_1.Contracts.throwIfNullOrUndefined(translationResponse, "translationResponse");
  20132. const phrase = translationResponse.SpeechPhrase;
  20133. translationResponse.SpeechPhrase = undefined;
  20134. phrase.Translation = translationResponse;
  20135. phrase.Text = phrase.DisplayText;
  20136. return new TranslationPhrase(phrase, baseOffset);
  20137. }
  20138. get RecognitionStatus() {
  20139. return this.privTranslationPhrase.RecognitionStatus;
  20140. }
  20141. get Offset() {
  20142. return this.privTranslationPhrase.Offset;
  20143. }
  20144. get Duration() {
  20145. return this.privTranslationPhrase.Duration;
  20146. }
  20147. get Text() {
  20148. return this.privTranslationPhrase.Text;
  20149. }
  20150. get Language() {
  20151. return this.privTranslationPhrase.PrimaryLanguage?.Language;
  20152. }
  20153. get Confidence() {
  20154. return this.privTranslationPhrase.PrimaryLanguage?.Confidence;
  20155. }
  20156. get Translation() {
  20157. return this.privTranslationPhrase.Translation;
  20158. }
  20159. asJson() {
  20160. const jsonObj = { ...this.privTranslationPhrase };
  20161. // Convert the enum values to their string representations for serialization
  20162. const serializedObj = {
  20163. ...jsonObj,
  20164. RecognitionStatus: Exports_js_1.RecognitionStatus[jsonObj.RecognitionStatus]
  20165. };
  20166. if (jsonObj.Translation) {
  20167. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
  20168. serializedObj.Translation = {
  20169. ...jsonObj.Translation,
  20170. TranslationStatus: TranslationStatus_js_1.TranslationStatus[jsonObj.Translation.TranslationStatus]
  20171. };
  20172. }
  20173. return JSON.stringify(serializedObj);
  20174. }
  20175. mapRecognitionStatus(status) {
  20176. if (typeof status === "string") {
  20177. return Exports_js_1.RecognitionStatus[status];
  20178. }
  20179. else if (typeof status === "number") {
  20180. return status;
  20181. }
  20182. }
  20183. mapTranslationStatus(status) {
  20184. if (typeof status === "string") {
  20185. return TranslationStatus_js_1.TranslationStatus[status];
  20186. }
  20187. else if (typeof status === "number") {
  20188. return status;
  20189. }
  20190. }
  20191. }
  20192. exports.TranslationPhrase = TranslationPhrase;
  20193. /***/ }),
  20194. /* 230 */
  20195. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20196. "use strict";
  20197. // Copyright (c) Microsoft Corporation. All rights reserved.
  20198. // Licensed under the MIT license.
  20199. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20200. exports.TranslationServiceRecognizer = void 0;
  20201. const Exports_js_1 = __webpack_require__(4);
  20202. const Exports_js_2 = __webpack_require__(79);
  20203. const Exports_js_3 = __webpack_require__(2);
  20204. // eslint-disable-next-line max-classes-per-file
  20205. class TranslationServiceRecognizer extends Exports_js_3.ConversationServiceRecognizer {
  20206. constructor(authentication, connectionFactory, audioSource, recognizerConfig, translationRecognizer) {
  20207. super(authentication, connectionFactory, audioSource, recognizerConfig, translationRecognizer);
  20208. this.privTranslationRecognizer = translationRecognizer;
  20209. this.connectionEvents.attach((connectionEvent) => {
  20210. if (connectionEvent.name === "ConnectionEstablishedEvent") {
  20211. this.privTranslationRecognizer.onConnection();
  20212. }
  20213. });
  20214. }
  20215. async processTypeSpecificMessages(connectionMessage) {
  20216. const resultProps = new Exports_js_2.PropertyCollection();
  20217. let processed = await this.processSpeechMessages(connectionMessage);
  20218. if (processed) {
  20219. return true;
  20220. }
  20221. const handleTranslationPhrase = async (translatedPhrase) => {
  20222. resultProps.setProperty(Exports_js_2.PropertyId.SpeechServiceResponse_JsonResult, translatedPhrase.asJson());
  20223. this.privRequestSession.onPhraseRecognized(translatedPhrase.Offset + translatedPhrase.Duration);
  20224. if (translatedPhrase.RecognitionStatus === Exports_js_3.RecognitionStatus.Success) {
  20225. // OK, the recognition was successful. How'd the translation do?
  20226. const result = this.fireEventForResult(translatedPhrase, resultProps);
  20227. if (!!this.privTranslationRecognizer.recognized) {
  20228. try {
  20229. this.privTranslationRecognizer.recognized(this.privTranslationRecognizer, result);
  20230. /* eslint-disable no-empty */
  20231. }
  20232. catch (error) {
  20233. // Not going to let errors in the event handler
  20234. // trip things up.
  20235. }
  20236. }
  20237. // report result to promise.
  20238. if (!!this.privSuccessCallback) {
  20239. try {
  20240. this.privSuccessCallback(result.result);
  20241. }
  20242. catch (e) {
  20243. if (!!this.privErrorCallback) {
  20244. this.privErrorCallback(e);
  20245. }
  20246. }
  20247. // Only invoke the call back once.
  20248. // and if it's successful don't invoke the
  20249. // error after that.
  20250. this.privSuccessCallback = undefined;
  20251. this.privErrorCallback = undefined;
  20252. }
  20253. }
  20254. else {
  20255. const reason = Exports_js_3.EnumTranslation.implTranslateRecognitionResult(translatedPhrase.RecognitionStatus);
  20256. const result = new Exports_js_2.TranslationRecognitionResult(undefined, this.privRequestSession.requestId, reason, translatedPhrase.Text, translatedPhrase.Duration, translatedPhrase.Offset, translatedPhrase.Language, translatedPhrase.Confidence, undefined, translatedPhrase.asJson(), resultProps);
  20257. if (reason === Exports_js_2.ResultReason.Canceled) {
  20258. const cancelReason = Exports_js_3.EnumTranslation.implTranslateCancelResult(translatedPhrase.RecognitionStatus);
  20259. const cancellationErrorCode = Exports_js_3.EnumTranslation.implTranslateCancelErrorCode(translatedPhrase.RecognitionStatus);
  20260. await this.cancelRecognitionLocal(cancelReason, cancellationErrorCode, Exports_js_3.EnumTranslation.implTranslateErrorDetails(cancellationErrorCode));
  20261. }
  20262. else {
  20263. if (translatedPhrase.RecognitionStatus !== Exports_js_3.RecognitionStatus.EndOfDictation) {
  20264. const ev = new Exports_js_2.TranslationRecognitionEventArgs(result, result.offset, this.privRequestSession.sessionId);
  20265. if (!!this.privTranslationRecognizer.recognized) {
  20266. try {
  20267. this.privTranslationRecognizer.recognized(this.privTranslationRecognizer, ev);
  20268. /* eslint-disable no-empty */
  20269. }
  20270. catch (error) {
  20271. // Not going to let errors in the event handler
  20272. // trip things up.
  20273. }
  20274. }
  20275. // report result to promise.
  20276. if (!!this.privSuccessCallback) {
  20277. try {
  20278. this.privSuccessCallback(result);
  20279. }
  20280. catch (e) {
  20281. if (!!this.privErrorCallback) {
  20282. this.privErrorCallback(e);
  20283. }
  20284. }
  20285. // Only invoke the call back once.
  20286. // and if it's successful don't invoke the
  20287. // error after that.
  20288. this.privSuccessCallback = undefined;
  20289. this.privErrorCallback = undefined;
  20290. }
  20291. }
  20292. }
  20293. processed = true;
  20294. }
  20295. };
  20296. const handleTranslationHypothesis = (hypothesis) => {
  20297. resultProps.setProperty(Exports_js_2.PropertyId.SpeechServiceResponse_JsonResult, hypothesis.asJson());
  20298. const result = this.fireEventForResult(hypothesis, resultProps);
  20299. this.privRequestSession.onHypothesis(result.offset);
  20300. if (!!this.privTranslationRecognizer.recognizing) {
  20301. try {
  20302. this.privTranslationRecognizer.recognizing(this.privTranslationRecognizer, result);
  20303. /* eslint-disable no-empty */
  20304. }
  20305. catch (error) {
  20306. // Not going to let errors in the event handler
  20307. // trip things up.
  20308. }
  20309. }
  20310. processed = true;
  20311. };
  20312. if (connectionMessage.messageType === Exports_js_1.MessageType.Text) {
  20313. resultProps.setProperty(Exports_js_2.PropertyId.SpeechServiceResponse_JsonResult, connectionMessage.textBody);
  20314. }
  20315. switch (connectionMessage.path.toLowerCase()) {
  20316. case "translation.hypothesis":
  20317. handleTranslationHypothesis(Exports_js_3.TranslationHypothesis.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset));
  20318. break;
  20319. case "translation.response":
  20320. const phrase = JSON.parse(connectionMessage.textBody);
  20321. if (!!phrase.SpeechPhrase) {
  20322. await handleTranslationPhrase(Exports_js_3.TranslationPhrase.fromTranslationResponse(phrase, this.privRequestSession.currentTurnAudioOffset));
  20323. }
  20324. else {
  20325. const hypothesis = JSON.parse(connectionMessage.textBody);
  20326. if (!!hypothesis.SpeechHypothesis) {
  20327. handleTranslationHypothesis(Exports_js_3.TranslationHypothesis.fromTranslationResponse(hypothesis, this.privRequestSession.currentTurnAudioOffset));
  20328. }
  20329. }
  20330. break;
  20331. case "translation.phrase":
  20332. await handleTranslationPhrase(Exports_js_3.TranslationPhrase.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset));
  20333. break;
  20334. case "translation.synthesis":
  20335. case "audio":
  20336. this.sendSynthesisAudio(connectionMessage.binaryBody, this.privRequestSession.sessionId);
  20337. processed = true;
  20338. break;
  20339. case "audio.end":
  20340. case "translation.synthesis.end":
  20341. const synthEnd = Exports_js_3.TranslationSynthesisEnd.fromJSON(connectionMessage.textBody);
  20342. switch (synthEnd.SynthesisStatus) {
  20343. case Exports_js_3.SynthesisStatus.Error:
  20344. if (!!this.privTranslationRecognizer.synthesizing) {
  20345. const result = new Exports_js_2.TranslationSynthesisResult(Exports_js_2.ResultReason.Canceled, undefined);
  20346. const retEvent = new Exports_js_2.TranslationSynthesisEventArgs(result, this.privRequestSession.sessionId);
  20347. try {
  20348. this.privTranslationRecognizer.synthesizing(this.privTranslationRecognizer, retEvent);
  20349. /* eslint-disable no-empty */
  20350. }
  20351. catch (error) {
  20352. // Not going to let errors in the event handler
  20353. // trip things up.
  20354. }
  20355. }
  20356. if (!!this.privTranslationRecognizer.canceled) {
  20357. // And raise a canceled event to send the rich(er) error message back.
  20358. const canceledResult = new Exports_js_2.TranslationRecognitionCanceledEventArgs(this.privRequestSession.sessionId, Exports_js_2.CancellationReason.Error, synthEnd.FailureReason, Exports_js_2.CancellationErrorCode.ServiceError, null);
  20359. try {
  20360. this.privTranslationRecognizer.canceled(this.privTranslationRecognizer, canceledResult);
  20361. /* eslint-disable no-empty */
  20362. }
  20363. catch (error) {
  20364. // Not going to let errors in the event handler
  20365. // trip things up.
  20366. }
  20367. }
  20368. break;
  20369. case Exports_js_3.SynthesisStatus.Success:
  20370. this.sendSynthesisAudio(undefined, this.privRequestSession.sessionId);
  20371. break;
  20372. default:
  20373. break;
  20374. }
  20375. processed = true;
  20376. break;
  20377. default:
  20378. break;
  20379. }
  20380. return processed;
  20381. }
  20382. // Cancels recognition.
  20383. cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  20384. const properties = new Exports_js_2.PropertyCollection();
  20385. properties.setProperty(Exports_js_3.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[errorCode]);
  20386. if (!!this.privTranslationRecognizer.canceled) {
  20387. const cancelEvent = new Exports_js_2.TranslationRecognitionCanceledEventArgs(sessionId, cancellationReason, error, errorCode, undefined);
  20388. try {
  20389. this.privTranslationRecognizer.canceled(this.privTranslationRecognizer, cancelEvent);
  20390. /* eslint-disable no-empty */
  20391. }
  20392. catch { }
  20393. }
  20394. if (!!this.privSuccessCallback) {
  20395. const result = new Exports_js_2.TranslationRecognitionResult(undefined, // Translations
  20396. requestId, Exports_js_2.ResultReason.Canceled, undefined, // Text
  20397. undefined, // Druation
  20398. undefined, // Offset
  20399. undefined, // Language
  20400. undefined, // LanguageDetectionConfidence
  20401. error, undefined, // Json
  20402. properties);
  20403. try {
  20404. this.privSuccessCallback(result);
  20405. /* eslint-disable no-empty */
  20406. this.privSuccessCallback = undefined;
  20407. }
  20408. catch { }
  20409. }
  20410. }
  20411. handleRecognizingCallback(result, offset, sessionId) {
  20412. try {
  20413. const ev = new Exports_js_2.TranslationRecognitionEventArgs(Exports_js_2.TranslationRecognitionResult.fromSpeechRecognitionResult(result), offset, sessionId);
  20414. this.privTranslationRecognizer.recognizing(this.privTranslationRecognizer, ev);
  20415. /* eslint-disable no-empty */
  20416. }
  20417. catch (error) {
  20418. // Not going to let errors in the event handler
  20419. // trip things up.
  20420. }
  20421. }
  20422. handleRecognizedCallback(result, offset, sessionId) {
  20423. try {
  20424. const ev = new Exports_js_2.TranslationRecognitionEventArgs(Exports_js_2.TranslationRecognitionResult.fromSpeechRecognitionResult(result), offset, sessionId);
  20425. this.privTranslationRecognizer.recognized(this.privTranslationRecognizer, ev);
  20426. }
  20427. catch (error) {
  20428. // Not going to let errors in the event handler
  20429. // trip things up.
  20430. }
  20431. }
  20432. fireEventForResult(serviceResult, properties) {
  20433. let translations;
  20434. if (undefined !== serviceResult.Translation.Translations) {
  20435. translations = new Exports_js_2.Translations();
  20436. for (const translation of serviceResult.Translation.Translations) {
  20437. translations.set(translation.Language, translation.Text || translation.DisplayText);
  20438. }
  20439. }
  20440. let resultReason;
  20441. let confidence;
  20442. if (serviceResult instanceof Exports_js_3.TranslationPhrase) {
  20443. if (!!serviceResult.Translation && serviceResult.Translation.TranslationStatus === Exports_js_1.TranslationStatus.Success) {
  20444. resultReason = Exports_js_2.ResultReason.TranslatedSpeech;
  20445. }
  20446. else {
  20447. resultReason = Exports_js_2.ResultReason.RecognizedSpeech;
  20448. }
  20449. confidence = serviceResult.Confidence;
  20450. }
  20451. else {
  20452. resultReason = Exports_js_2.ResultReason.TranslatingSpeech;
  20453. }
  20454. const language = serviceResult.Language;
  20455. const result = new Exports_js_2.TranslationRecognitionResult(translations, this.privRequestSession.requestId, resultReason, serviceResult.Text, serviceResult.Duration, serviceResult.Offset, language, confidence, serviceResult.Translation.FailureReason, serviceResult.asJson(), properties);
  20456. const ev = new Exports_js_2.TranslationRecognitionEventArgs(result, serviceResult.Offset, this.privRequestSession.sessionId);
  20457. return ev;
  20458. }
  20459. sendSynthesisAudio(audio, sessionId) {
  20460. const reason = (undefined === audio) ? Exports_js_2.ResultReason.SynthesizingAudioCompleted : Exports_js_2.ResultReason.SynthesizingAudio;
  20461. const result = new Exports_js_2.TranslationSynthesisResult(reason, audio);
  20462. const retEvent = new Exports_js_2.TranslationSynthesisEventArgs(result, sessionId);
  20463. if (!!this.privTranslationRecognizer.synthesizing) {
  20464. try {
  20465. this.privTranslationRecognizer.synthesizing(this.privTranslationRecognizer, retEvent);
  20466. /* eslint-disable no-empty */
  20467. }
  20468. catch (error) {
  20469. // Not going to let errors in the event handler
  20470. // trip things up.
  20471. }
  20472. }
  20473. }
  20474. }
  20475. exports.TranslationServiceRecognizer = TranslationServiceRecognizer;
  20476. /***/ }),
  20477. /* 231 */
  20478. /***/ ((__unused_webpack_module, exports) => {
  20479. "use strict";
  20480. // Copyright (c) Microsoft Corporation. All rights reserved.
  20481. // Licensed under the MIT license.
  20482. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20483. exports.SpeechDetected = void 0;
  20484. class SpeechDetected {
  20485. constructor(json, baseOffset) {
  20486. this.privSpeechStartDetected = JSON.parse(json);
  20487. this.privSpeechStartDetected.Offset += baseOffset;
  20488. }
  20489. static fromJSON(json, baseOffset) {
  20490. return new SpeechDetected(json, baseOffset);
  20491. }
  20492. get Offset() {
  20493. return this.privSpeechStartDetected.Offset;
  20494. }
  20495. }
  20496. exports.SpeechDetected = SpeechDetected;
  20497. /***/ }),
  20498. /* 232 */
  20499. /***/ ((__unused_webpack_module, exports) => {
  20500. "use strict";
  20501. // Copyright (c) Microsoft Corporation. All rights reserved.
  20502. // Licensed under the MIT license.
  20503. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20504. exports.SpeechHypothesis = void 0;
  20505. class SpeechHypothesis {
  20506. constructor(json, baseOffset) {
  20507. this.privSpeechHypothesis = JSON.parse(json);
  20508. this.updateOffset(baseOffset);
  20509. }
  20510. static fromJSON(json, baseOffset) {
  20511. return new SpeechHypothesis(json, baseOffset);
  20512. }
  20513. updateOffset(baseOffset) {
  20514. this.privSpeechHypothesis.Offset += baseOffset;
  20515. }
  20516. asJson() {
  20517. return JSON.stringify(this.privSpeechHypothesis);
  20518. }
  20519. get Text() {
  20520. return this.privSpeechHypothesis.Text;
  20521. }
  20522. get Offset() {
  20523. return this.privSpeechHypothesis.Offset;
  20524. }
  20525. get Duration() {
  20526. return this.privSpeechHypothesis.Duration;
  20527. }
  20528. get Language() {
  20529. return this.privSpeechHypothesis.PrimaryLanguage === undefined ? undefined : this.privSpeechHypothesis.PrimaryLanguage.Language;
  20530. }
  20531. get LanguageDetectionConfidence() {
  20532. return this.privSpeechHypothesis.PrimaryLanguage === undefined ? undefined : this.privSpeechHypothesis.PrimaryLanguage.Confidence;
  20533. }
  20534. get SpeakerId() {
  20535. return this.privSpeechHypothesis.SpeakerId;
  20536. }
  20537. }
  20538. exports.SpeechHypothesis = SpeechHypothesis;
  20539. /***/ }),
  20540. /* 233 */
  20541. /***/ ((__unused_webpack_module, exports) => {
  20542. "use strict";
  20543. // Copyright (c) Microsoft Corporation. All rights reserved.
  20544. // Licensed under the MIT license.
  20545. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20546. exports.SpeechKeyword = void 0;
  20547. class SpeechKeyword {
  20548. constructor(json, baseOffset) {
  20549. this.privSpeechKeyword = JSON.parse(json);
  20550. this.privSpeechKeyword.Offset += baseOffset;
  20551. }
  20552. static fromJSON(json, baseOffset) {
  20553. return new SpeechKeyword(json, baseOffset);
  20554. }
  20555. get Status() {
  20556. return this.privSpeechKeyword.Status;
  20557. }
  20558. get Text() {
  20559. return this.privSpeechKeyword.Text;
  20560. }
  20561. get Offset() {
  20562. return this.privSpeechKeyword.Offset;
  20563. }
  20564. get Duration() {
  20565. return this.privSpeechKeyword.Duration;
  20566. }
  20567. asJson() {
  20568. return JSON.stringify(this.privSpeechKeyword);
  20569. }
  20570. }
  20571. exports.SpeechKeyword = SpeechKeyword;
  20572. /***/ }),
  20573. /* 234 */
  20574. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20575. "use strict";
  20576. // Copyright (c) Microsoft Corporation. All rights reserved.
  20577. // Licensed under the MIT license.
  20578. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20579. exports.SpeechServiceRecognizer = void 0;
  20580. const Exports_js_1 = __webpack_require__(79);
  20581. const Exports_js_2 = __webpack_require__(2);
  20582. // eslint-disable-next-line max-classes-per-file
  20583. class SpeechServiceRecognizer extends Exports_js_2.ServiceRecognizerBase {
  20584. constructor(authentication, connectionFactory, audioSource, recognizerConfig, speechRecognizer) {
  20585. super(authentication, connectionFactory, audioSource, recognizerConfig, speechRecognizer);
  20586. this.privSpeechRecognizer = speechRecognizer;
  20587. }
  20588. async processTypeSpecificMessages(connectionMessage) {
  20589. let result;
  20590. const resultProps = new Exports_js_1.PropertyCollection();
  20591. let processed = false;
  20592. switch (connectionMessage.path.toLowerCase()) {
  20593. case "speech.hypothesis":
  20594. case "speech.fragment":
  20595. const hypothesis = Exports_js_2.SpeechHypothesis.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  20596. resultProps.setProperty(Exports_js_1.PropertyId.SpeechServiceResponse_JsonResult, hypothesis.asJson());
  20597. result = new Exports_js_1.SpeechRecognitionResult(this.privRequestSession.requestId, Exports_js_1.ResultReason.RecognizingSpeech, hypothesis.Text, hypothesis.Duration, hypothesis.Offset, hypothesis.Language, hypothesis.LanguageDetectionConfidence, undefined, // Speaker Id
  20598. undefined, hypothesis.asJson(), resultProps);
  20599. this.privRequestSession.onHypothesis(hypothesis.Offset);
  20600. const ev = new Exports_js_1.SpeechRecognitionEventArgs(result, hypothesis.Offset, this.privRequestSession.sessionId);
  20601. if (!!this.privSpeechRecognizer.recognizing) {
  20602. try {
  20603. this.privSpeechRecognizer.recognizing(this.privSpeechRecognizer, ev);
  20604. /* eslint-disable no-empty */
  20605. }
  20606. catch (error) {
  20607. // Not going to let errors in the event handler
  20608. // trip things up.
  20609. }
  20610. }
  20611. processed = true;
  20612. break;
  20613. case "speech.phrase":
  20614. const simple = Exports_js_2.SimpleSpeechPhrase.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  20615. resultProps.setProperty(Exports_js_1.PropertyId.SpeechServiceResponse_JsonResult, simple.asJson());
  20616. const resultReason = Exports_js_2.EnumTranslation.implTranslateRecognitionResult(simple.RecognitionStatus, this.privExpectContentAssessmentResponse);
  20617. this.privRequestSession.onPhraseRecognized(simple.Offset + simple.Duration);
  20618. if (Exports_js_1.ResultReason.Canceled === resultReason) {
  20619. const cancelReason = Exports_js_2.EnumTranslation.implTranslateCancelResult(simple.RecognitionStatus);
  20620. const cancellationErrorCode = Exports_js_2.EnumTranslation.implTranslateCancelErrorCode(simple.RecognitionStatus);
  20621. await this.cancelRecognitionLocal(cancelReason, cancellationErrorCode, Exports_js_2.EnumTranslation.implTranslateErrorDetails(cancellationErrorCode));
  20622. }
  20623. else {
  20624. // Like the native SDK's, don't event / return an EndOfDictation message.
  20625. if (simple.RecognitionStatus === Exports_js_2.RecognitionStatus.EndOfDictation) {
  20626. break;
  20627. }
  20628. if (this.privRecognizerConfig.parameters.getProperty(Exports_js_2.OutputFormatPropertyName) === Exports_js_1.OutputFormat[Exports_js_1.OutputFormat.Simple]) {
  20629. result = new Exports_js_1.SpeechRecognitionResult(this.privRequestSession.requestId, resultReason, simple.DisplayText, simple.Duration, simple.Offset, simple.Language, simple.LanguageDetectionConfidence, undefined, // Speaker Id
  20630. undefined, simple.asJson(), resultProps);
  20631. }
  20632. else {
  20633. const detailed = Exports_js_2.DetailedSpeechPhrase.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  20634. resultProps.setProperty(Exports_js_1.PropertyId.SpeechServiceResponse_JsonResult, detailed.asJson());
  20635. result = new Exports_js_1.SpeechRecognitionResult(this.privRequestSession.requestId, resultReason, detailed.RecognitionStatus === Exports_js_2.RecognitionStatus.Success ? detailed.NBest[0].Display : "", detailed.Duration, detailed.Offset, detailed.Language, detailed.LanguageDetectionConfidence, undefined, // Speaker Id
  20636. undefined, detailed.asJson(), resultProps);
  20637. }
  20638. const event = new Exports_js_1.SpeechRecognitionEventArgs(result, result.offset, this.privRequestSession.sessionId);
  20639. if (!!this.privSpeechRecognizer.recognized) {
  20640. try {
  20641. this.privSpeechRecognizer.recognized(this.privSpeechRecognizer, event);
  20642. /* eslint-disable no-empty */
  20643. }
  20644. catch (error) {
  20645. // Not going to let errors in the event handler
  20646. // trip things up.
  20647. }
  20648. }
  20649. if (!!this.privSuccessCallback) {
  20650. try {
  20651. this.privSuccessCallback(result);
  20652. }
  20653. catch (e) {
  20654. if (!!this.privErrorCallback) {
  20655. this.privErrorCallback(e);
  20656. }
  20657. }
  20658. // Only invoke the call back once.
  20659. // and if it's successful don't invoke the
  20660. // error after that.
  20661. this.privSuccessCallback = undefined;
  20662. this.privErrorCallback = undefined;
  20663. }
  20664. }
  20665. processed = true;
  20666. break;
  20667. default:
  20668. break;
  20669. }
  20670. return processed;
  20671. }
  20672. // Cancels recognition.
  20673. cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  20674. const properties = new Exports_js_1.PropertyCollection();
  20675. properties.setProperty(Exports_js_2.CancellationErrorCodePropertyName, Exports_js_1.CancellationErrorCode[errorCode]);
  20676. if (!!this.privSpeechRecognizer.canceled) {
  20677. const cancelEvent = new Exports_js_1.SpeechRecognitionCanceledEventArgs(cancellationReason, error, errorCode, undefined, sessionId);
  20678. try {
  20679. this.privSpeechRecognizer.canceled(this.privSpeechRecognizer, cancelEvent);
  20680. /* eslint-disable no-empty */
  20681. }
  20682. catch { }
  20683. }
  20684. if (!!this.privSuccessCallback) {
  20685. const result = new Exports_js_1.SpeechRecognitionResult(requestId, Exports_js_1.ResultReason.Canceled, undefined, // Text
  20686. undefined, // Duration
  20687. undefined, // Offset
  20688. undefined, // Language
  20689. undefined, // Language Detection Confidence
  20690. undefined, // Speaker Id
  20691. error, undefined, // Json
  20692. properties);
  20693. try {
  20694. this.privSuccessCallback(result);
  20695. this.privSuccessCallback = undefined;
  20696. /* eslint-disable no-empty */
  20697. }
  20698. catch { }
  20699. }
  20700. }
  20701. }
  20702. exports.SpeechServiceRecognizer = SpeechServiceRecognizer;
  20703. /***/ }),
  20704. /* 235 */
  20705. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20706. "use strict";
  20707. // Copyright (c) Microsoft Corporation. All rights reserved.
  20708. // Licensed under the MIT license.
  20709. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20710. exports.ConversationTranscriptionServiceRecognizer = void 0;
  20711. const Exports_js_1 = __webpack_require__(79);
  20712. const Exports_js_2 = __webpack_require__(2);
  20713. const SpeakerDiarization_js_1 = __webpack_require__(236);
  20714. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  20715. // eslint-disable-next-line max-classes-per-file
  20716. class ConversationTranscriptionServiceRecognizer extends Exports_js_2.ServiceRecognizerBase {
  20717. constructor(authentication, connectionFactory, audioSource, recognizerConfig, conversationTranscriber) {
  20718. super(authentication, connectionFactory, audioSource, recognizerConfig, conversationTranscriber);
  20719. this.privConversationTranscriber = conversationTranscriber;
  20720. this.setSpeakerDiarizationJson();
  20721. }
  20722. setSpeakerDiarizationJson() {
  20723. if (this.privEnableSpeakerId) {
  20724. const phraseDetection = this.privSpeechContext.getContext().phraseDetection || {};
  20725. phraseDetection.mode = PhraseDetectionContext_js_1.RecognitionMode.Conversation;
  20726. const speakerDiarization = {};
  20727. speakerDiarization.mode = SpeakerDiarization_js_1.SpeakerDiarizationMode.Anonymous;
  20728. speakerDiarization.audioSessionId = this.privDiarizationSessionId;
  20729. speakerDiarization.audioOffsetMs = 0;
  20730. speakerDiarization.diarizeIntermediates = this.privRecognizerConfig.parameters.getProperty(Exports_js_1.PropertyId.SpeechServiceResponse_DiarizeIntermediateResults, "false") === "true";
  20731. phraseDetection.speakerDiarization = speakerDiarization;
  20732. this.privSpeechContext.getContext().phraseDetection = phraseDetection;
  20733. }
  20734. }
  20735. async processTypeSpecificMessages(connectionMessage) {
  20736. let result;
  20737. const resultProps = new Exports_js_1.PropertyCollection();
  20738. resultProps.setProperty(Exports_js_1.PropertyId.SpeechServiceResponse_JsonResult, connectionMessage.textBody);
  20739. let processed = false;
  20740. switch (connectionMessage.path.toLowerCase()) {
  20741. case "speech.hypothesis":
  20742. case "speech.fragment":
  20743. const hypothesis = Exports_js_2.SpeechHypothesis.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  20744. result = new Exports_js_1.ConversationTranscriptionResult(this.privRequestSession.requestId, Exports_js_1.ResultReason.RecognizingSpeech, hypothesis.Text, hypothesis.Duration, hypothesis.Offset, hypothesis.Language, hypothesis.LanguageDetectionConfidence, hypothesis.SpeakerId, undefined, hypothesis.asJson(), resultProps);
  20745. this.privRequestSession.onHypothesis(hypothesis.Offset);
  20746. const ev = new Exports_js_1.ConversationTranscriptionEventArgs(result, hypothesis.Duration, this.privRequestSession.sessionId);
  20747. if (!!this.privConversationTranscriber.transcribing) {
  20748. try {
  20749. this.privConversationTranscriber.transcribing(this.privConversationTranscriber, ev);
  20750. /* eslint-disable no-empty */
  20751. }
  20752. catch (error) {
  20753. // Not going to let errors in the event handler
  20754. // trip things up.
  20755. }
  20756. }
  20757. processed = true;
  20758. break;
  20759. case "speech.phrase":
  20760. const simple = Exports_js_2.SimpleSpeechPhrase.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  20761. const resultReason = Exports_js_2.EnumTranslation.implTranslateRecognitionResult(simple.RecognitionStatus);
  20762. this.privRequestSession.onPhraseRecognized(simple.Offset + simple.Duration);
  20763. if (Exports_js_1.ResultReason.Canceled === resultReason) {
  20764. const cancelReason = Exports_js_2.EnumTranslation.implTranslateCancelResult(simple.RecognitionStatus);
  20765. const cancellationErrorCode = Exports_js_2.EnumTranslation.implTranslateCancelErrorCode(simple.RecognitionStatus);
  20766. await this.cancelRecognitionLocal(cancelReason, cancellationErrorCode, Exports_js_2.EnumTranslation.implTranslateErrorDetails(cancellationErrorCode));
  20767. }
  20768. else {
  20769. if (!(this.privRequestSession.isSpeechEnded && resultReason === Exports_js_1.ResultReason.NoMatch && simple.RecognitionStatus !== Exports_js_2.RecognitionStatus.InitialSilenceTimeout)) {
  20770. if (this.privRecognizerConfig.parameters.getProperty(Exports_js_2.OutputFormatPropertyName) === Exports_js_1.OutputFormat[Exports_js_1.OutputFormat.Simple]) {
  20771. result = new Exports_js_1.ConversationTranscriptionResult(this.privRequestSession.requestId, resultReason, simple.DisplayText, simple.Duration, simple.Offset, simple.Language, simple.LanguageDetectionConfidence, simple.SpeakerId, undefined, simple.asJson(), resultProps);
  20772. }
  20773. else {
  20774. const detailed = Exports_js_2.DetailedSpeechPhrase.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  20775. result = new Exports_js_1.ConversationTranscriptionResult(this.privRequestSession.requestId, resultReason, detailed.RecognitionStatus === Exports_js_2.RecognitionStatus.Success ? detailed.NBest[0].Display : undefined, detailed.Duration, detailed.Offset, detailed.Language, detailed.LanguageDetectionConfidence, simple.SpeakerId, undefined, detailed.asJson(), resultProps);
  20776. }
  20777. const event = new Exports_js_1.ConversationTranscriptionEventArgs(result, result.offset, this.privRequestSession.sessionId);
  20778. if (!!this.privConversationTranscriber.transcribed) {
  20779. try {
  20780. this.privConversationTranscriber.transcribed(this.privConversationTranscriber, event);
  20781. /* eslint-disable no-empty */
  20782. }
  20783. catch (error) {
  20784. // Not going to let errors in the event handler
  20785. // trip things up.
  20786. }
  20787. }
  20788. }
  20789. }
  20790. processed = true;
  20791. break;
  20792. default:
  20793. break;
  20794. }
  20795. return processed;
  20796. }
  20797. // Cancels recognition.
  20798. cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  20799. const properties = new Exports_js_1.PropertyCollection();
  20800. properties.setProperty(Exports_js_2.CancellationErrorCodePropertyName, Exports_js_1.CancellationErrorCode[errorCode]);
  20801. if (!!this.privConversationTranscriber.canceled) {
  20802. const cancelEvent = new Exports_js_1.ConversationTranscriptionCanceledEventArgs(cancellationReason, error, errorCode, undefined, sessionId);
  20803. try {
  20804. this.privConversationTranscriber.canceled(this.privConversationTranscriber, cancelEvent);
  20805. /* eslint-disable no-empty */
  20806. }
  20807. catch { }
  20808. }
  20809. }
  20810. }
  20811. exports.ConversationTranscriptionServiceRecognizer = ConversationTranscriptionServiceRecognizer;
  20812. /***/ }),
  20813. /* 236 */
  20814. /***/ ((__unused_webpack_module, exports) => {
  20815. "use strict";
  20816. //
  20817. // Copyright (c) Microsoft. All rights reserved.
  20818. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  20819. //
  20820. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20821. exports.IdentityProvider = exports.SpeakerDiarizationMode = void 0;
  20822. /**
  20823. * The speaker diarization mode
  20824. */
  20825. var SpeakerDiarizationMode;
  20826. (function (SpeakerDiarizationMode) {
  20827. SpeakerDiarizationMode["None"] = "None";
  20828. SpeakerDiarizationMode["Identity"] = "Identity";
  20829. SpeakerDiarizationMode["Anonymous"] = "Anonymous";
  20830. })(SpeakerDiarizationMode = exports.SpeakerDiarizationMode || (exports.SpeakerDiarizationMode = {}));
  20831. /**
  20832. * The identity provider
  20833. */
  20834. var IdentityProvider;
  20835. (function (IdentityProvider) {
  20836. IdentityProvider["CallCenter"] = "CallCenter";
  20837. })(IdentityProvider = exports.IdentityProvider || (exports.IdentityProvider = {}));
  20838. /***/ }),
  20839. /* 237 */
  20840. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20841. "use strict";
  20842. // Copyright (c) Microsoft Corporation. All rights reserved.
  20843. // Licensed under the MIT license.
  20844. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20845. exports.TranscriptionServiceRecognizer = void 0;
  20846. const Exports_js_1 = __webpack_require__(4);
  20847. const Exports_js_2 = __webpack_require__(79);
  20848. const Exports_js_3 = __webpack_require__(2);
  20849. const SpeechConnectionMessage_Internal_js_1 = __webpack_require__(207);
  20850. // eslint-disable-next-line max-classes-per-file
  20851. class TranscriptionServiceRecognizer extends Exports_js_3.ConversationServiceRecognizer {
  20852. constructor(authentication, connectionFactory, audioSource, recognizerConfig, transcriber) {
  20853. super(authentication, connectionFactory, audioSource, recognizerConfig, transcriber);
  20854. this.privTranscriberRecognizer = transcriber;
  20855. this.sendPrePayloadJSONOverride = (connection) => this.sendTranscriptionStartJSON(connection);
  20856. if (this.privRecognizerConfig.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps) === "true") {
  20857. this.privSpeechContext.setWordLevelTimings();
  20858. }
  20859. }
  20860. async sendSpeechEventAsync(info, command) {
  20861. if (!!this.privRequestSession.isRecognizing) {
  20862. const connection = await this.fetchConnection();
  20863. await this.sendSpeechEvent(connection, this.createSpeechEventPayload(info, command));
  20864. }
  20865. }
  20866. async sendMeetingSpeechEventAsync(info, command) {
  20867. if (!!this.privRequestSession.isRecognizing) {
  20868. const connection = await this.fetchConnection();
  20869. await this.sendSpeechEvent(connection, this.createMeetingSpeechEventPayload(info, command));
  20870. }
  20871. }
  20872. processTypeSpecificMessages(connectionMessage) {
  20873. return this.processSpeechMessages(connectionMessage);
  20874. }
  20875. handleRecognizedCallback(result, offset, sessionId) {
  20876. try {
  20877. const event = new Exports_js_2.SpeechRecognitionEventArgs(result, offset, sessionId);
  20878. this.privTranscriberRecognizer.recognized(this.privTranscriberRecognizer, event);
  20879. if (!!this.privSuccessCallback) {
  20880. try {
  20881. this.privSuccessCallback(result);
  20882. }
  20883. catch (e) {
  20884. if (!!this.privErrorCallback) {
  20885. this.privErrorCallback(e);
  20886. }
  20887. }
  20888. // Only invoke the call back once.
  20889. // and if it's successful don't invoke the
  20890. // error after that.
  20891. this.privSuccessCallback = undefined;
  20892. this.privErrorCallback = undefined;
  20893. }
  20894. /* eslint-disable no-empty */
  20895. }
  20896. catch (error) {
  20897. // Not going to let errors in the event handler
  20898. // trip things up.
  20899. }
  20900. }
  20901. handleRecognizingCallback(result, duration, sessionId) {
  20902. try {
  20903. const ev = new Exports_js_2.SpeechRecognitionEventArgs(result, duration, sessionId);
  20904. this.privTranscriberRecognizer.recognizing(this.privTranscriberRecognizer, ev);
  20905. /* eslint-disable no-empty */
  20906. }
  20907. catch (error) {
  20908. // Not going to let errors in the event handler
  20909. // trip things up.
  20910. }
  20911. }
  20912. // Cancels recognition.
  20913. cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  20914. const properties = new Exports_js_2.PropertyCollection();
  20915. properties.setProperty(Exports_js_3.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[errorCode]);
  20916. if (this.privTranscriberRecognizer.IsMeetingRecognizer()) {
  20917. if (!!this.privTranscriberRecognizer.canceled) {
  20918. const cancelEvent = new Exports_js_2.MeetingTranscriptionCanceledEventArgs(cancellationReason, error, errorCode, undefined, sessionId);
  20919. try {
  20920. this.privTranscriberRecognizer.canceled(this.privTranscriberRecognizer, cancelEvent);
  20921. /* eslint-disable no-empty */
  20922. }
  20923. catch { }
  20924. }
  20925. }
  20926. else {
  20927. if (!!this.privTranscriberRecognizer.canceled) {
  20928. const cancelEvent = new Exports_js_2.ConversationTranscriptionCanceledEventArgs(cancellationReason, error, errorCode, undefined, sessionId);
  20929. try {
  20930. this.privTranscriberRecognizer.canceled(this.privTranscriberRecognizer, cancelEvent);
  20931. /* eslint-disable no-empty */
  20932. }
  20933. catch { }
  20934. }
  20935. }
  20936. if (!!this.privSuccessCallback) {
  20937. const result = new Exports_js_2.SpeechRecognitionResult(requestId, Exports_js_2.ResultReason.Canceled, undefined, // Text
  20938. undefined, // Duration
  20939. undefined, // Offset
  20940. undefined, // Language
  20941. undefined, // Language Detection Confidence
  20942. undefined, // Speaker Id
  20943. error, undefined, // Json
  20944. properties);
  20945. try {
  20946. this.privSuccessCallback(result);
  20947. this.privSuccessCallback = undefined;
  20948. /* eslint-disable no-empty */
  20949. }
  20950. catch { }
  20951. }
  20952. }
  20953. // Encapsulated for derived service recognizers that need to send additional JSON
  20954. async sendTranscriptionStartJSON(connection) {
  20955. await this.sendSpeechContext(connection, true);
  20956. if (this.privTranscriberRecognizer.IsMeetingRecognizer()) {
  20957. const info = this.privTranscriberRecognizer.getMeetingInfo();
  20958. const payload = this.createMeetingSpeechEventPayload(info, "start");
  20959. await this.sendSpeechEvent(connection, payload);
  20960. }
  20961. else {
  20962. const info = this.privTranscriberRecognizer.getConversationInfo();
  20963. const payload = this.createSpeechEventPayload(info, "start");
  20964. await this.sendSpeechEvent(connection, payload);
  20965. }
  20966. await this.sendWaveHeader(connection);
  20967. return;
  20968. }
  20969. sendSpeechEvent(connection, payload) {
  20970. const speechEventJson = JSON.stringify(payload);
  20971. if (speechEventJson) {
  20972. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_1.MessageType.Text, "speech.event", this.privRequestSession.requestId, "application/json", speechEventJson));
  20973. }
  20974. return;
  20975. }
  20976. createSpeechEventPayload(info, command) {
  20977. const eventDict = { id: "meeting", name: command, meeting: info.conversationProperties };
  20978. eventDict.meeting.id = info.id;
  20979. eventDict.meeting.attendees = info.participants;
  20980. return eventDict;
  20981. }
  20982. createMeetingSpeechEventPayload(info, command) {
  20983. const eventDict = { id: "meeting", name: command, meeting: info.meetingProperties };
  20984. eventDict.meeting.id = info.id;
  20985. eventDict.meeting.attendees = info.participants;
  20986. return eventDict;
  20987. }
  20988. }
  20989. exports.TranscriptionServiceRecognizer = TranscriptionServiceRecognizer;
  20990. /***/ }),
  20991. /* 238 */
  20992. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20993. "use strict";
  20994. // Copyright (c) Microsoft Corporation. All rights reserved.
  20995. // Licensed under the MIT license.
  20996. Object.defineProperty(exports, "__esModule", ({ value: true }));
  20997. exports.DetailedSpeechPhrase = void 0;
  20998. const Exports_js_1 = __webpack_require__(2);
  20999. class DetailedSpeechPhrase {
  21000. constructor(json, baseOffset) {
  21001. this.privDetailedSpeechPhrase = JSON.parse(json);
  21002. this.privDetailedSpeechPhrase.RecognitionStatus = this.mapRecognitionStatus(this.privDetailedSpeechPhrase.RecognitionStatus);
  21003. this.updateOffsets(baseOffset);
  21004. }
  21005. static fromJSON(json, baseOffset) {
  21006. return new DetailedSpeechPhrase(json, baseOffset);
  21007. }
  21008. updateOffsets(baseOffset) {
  21009. this.privDetailedSpeechPhrase.Offset += baseOffset;
  21010. if (!!this.privDetailedSpeechPhrase.NBest) {
  21011. for (const phrase of this.privDetailedSpeechPhrase.NBest) {
  21012. if (!!phrase.Words) {
  21013. for (const word of phrase.Words) {
  21014. word.Offset += baseOffset;
  21015. }
  21016. }
  21017. if (!!phrase.DisplayWords) {
  21018. for (const word of phrase.DisplayWords) {
  21019. word.Offset += baseOffset;
  21020. }
  21021. }
  21022. }
  21023. }
  21024. }
  21025. asJson() {
  21026. const jsonObj = { ...this.privDetailedSpeechPhrase };
  21027. // Convert the enum value to its string representation for serialization purposes.
  21028. return JSON.stringify({
  21029. ...jsonObj,
  21030. RecognitionStatus: Exports_js_1.RecognitionStatus[jsonObj.RecognitionStatus]
  21031. });
  21032. }
  21033. get RecognitionStatus() {
  21034. return this.privDetailedSpeechPhrase.RecognitionStatus;
  21035. }
  21036. get NBest() {
  21037. return this.privDetailedSpeechPhrase.NBest;
  21038. }
  21039. get Duration() {
  21040. return this.privDetailedSpeechPhrase.Duration;
  21041. }
  21042. get Offset() {
  21043. return this.privDetailedSpeechPhrase.Offset;
  21044. }
  21045. get Language() {
  21046. return this.privDetailedSpeechPhrase.PrimaryLanguage === undefined ? undefined : this.privDetailedSpeechPhrase.PrimaryLanguage.Language;
  21047. }
  21048. get LanguageDetectionConfidence() {
  21049. return this.privDetailedSpeechPhrase.PrimaryLanguage === undefined ? undefined : this.privDetailedSpeechPhrase.PrimaryLanguage.Confidence;
  21050. }
  21051. get Text() {
  21052. if (!!this.privDetailedSpeechPhrase.NBest && this.privDetailedSpeechPhrase.NBest[0]) {
  21053. return this.privDetailedSpeechPhrase.NBest[0].Display || this.privDetailedSpeechPhrase.NBest[0].DisplayText;
  21054. }
  21055. return this.privDetailedSpeechPhrase.DisplayText;
  21056. }
  21057. get SpeakerId() {
  21058. return this.privDetailedSpeechPhrase.SpeakerId;
  21059. }
  21060. mapRecognitionStatus(status) {
  21061. if (typeof status === "string") {
  21062. return Exports_js_1.RecognitionStatus[status];
  21063. }
  21064. else if (typeof status === "number") {
  21065. return status;
  21066. }
  21067. }
  21068. }
  21069. exports.DetailedSpeechPhrase = DetailedSpeechPhrase;
  21070. /***/ }),
  21071. /* 239 */
  21072. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21073. "use strict";
  21074. // Copyright (c) Microsoft Corporation. All rights reserved.
  21075. // Licensed under the MIT license.
  21076. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21077. exports.SimpleSpeechPhrase = void 0;
  21078. const Exports_js_1 = __webpack_require__(2);
  21079. class SimpleSpeechPhrase {
  21080. constructor(json, baseOffset = 0) {
  21081. this.privSimpleSpeechPhrase = JSON.parse(json);
  21082. this.privSimpleSpeechPhrase.RecognitionStatus = this.mapRecognitionStatus(this.privSimpleSpeechPhrase.RecognitionStatus); // RecognitionStatus[this.privSimpleSpeechPhrase.RecognitionStatus as unknown as keyof typeof RecognitionStatus];
  21083. this.updateOffset(baseOffset);
  21084. }
  21085. static fromJSON(json, baseOffset) {
  21086. return new SimpleSpeechPhrase(json, baseOffset);
  21087. }
  21088. updateOffset(baseOffset) {
  21089. this.privSimpleSpeechPhrase.Offset += baseOffset;
  21090. }
  21091. asJson() {
  21092. const jsonObj = { ...this.privSimpleSpeechPhrase };
  21093. // Convert the enum value to its string representation for serialization purposes.
  21094. return JSON.stringify({
  21095. ...jsonObj,
  21096. RecognitionStatus: Exports_js_1.RecognitionStatus[jsonObj.RecognitionStatus]
  21097. });
  21098. }
  21099. get RecognitionStatus() {
  21100. return this.privSimpleSpeechPhrase.RecognitionStatus;
  21101. }
  21102. get DisplayText() {
  21103. return this.privSimpleSpeechPhrase.DisplayText;
  21104. }
  21105. get Offset() {
  21106. return this.privSimpleSpeechPhrase.Offset;
  21107. }
  21108. get Duration() {
  21109. return this.privSimpleSpeechPhrase.Duration;
  21110. }
  21111. get Language() {
  21112. return this.privSimpleSpeechPhrase.PrimaryLanguage === undefined ? undefined : this.privSimpleSpeechPhrase.PrimaryLanguage.Language;
  21113. }
  21114. get LanguageDetectionConfidence() {
  21115. return this.privSimpleSpeechPhrase.PrimaryLanguage === undefined ? undefined : this.privSimpleSpeechPhrase.PrimaryLanguage.Confidence;
  21116. }
  21117. get SpeakerId() {
  21118. return this.privSimpleSpeechPhrase.SpeakerId;
  21119. }
  21120. mapRecognitionStatus(status) {
  21121. if (typeof status === "string") {
  21122. return Exports_js_1.RecognitionStatus[status];
  21123. }
  21124. else if (typeof status === "number") {
  21125. return status;
  21126. }
  21127. }
  21128. }
  21129. exports.SimpleSpeechPhrase = SimpleSpeechPhrase;
  21130. /***/ }),
  21131. /* 240 */
  21132. /***/ ((__unused_webpack_module, exports) => {
  21133. "use strict";
  21134. // Copyright (c) Microsoft Corporation. All rights reserved.
  21135. // Licensed under the MIT license.
  21136. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21137. exports.AddedLmIntent = void 0;
  21138. /**
  21139. * @class AddedLmIntent
  21140. */
  21141. // eslint-disable-next-line max-classes-per-file
  21142. class AddedLmIntent {
  21143. /**
  21144. * Creates and initializes an instance of this class.
  21145. * @constructor
  21146. * @param modelImpl - The model.
  21147. * @param intentName - The intent name.
  21148. */
  21149. constructor(modelImpl, intentName) {
  21150. this.modelImpl = modelImpl;
  21151. this.intentName = intentName;
  21152. }
  21153. }
  21154. exports.AddedLmIntent = AddedLmIntent;
  21155. /***/ }),
  21156. /* 241 */
  21157. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21158. "use strict";
  21159. // Copyright (c) Microsoft Corporation. All rights reserved.
  21160. // Licensed under the MIT license.
  21161. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21162. exports.IntentServiceRecognizer = void 0;
  21163. const Exports_js_1 = __webpack_require__(4);
  21164. const Exports_js_2 = __webpack_require__(79);
  21165. const Exports_js_3 = __webpack_require__(2);
  21166. // eslint-disable-next-line max-classes-per-file
  21167. class IntentServiceRecognizer extends Exports_js_3.ServiceRecognizerBase {
  21168. constructor(authentication, connectionFactory, audioSource, recognizerConfig, recognizer) {
  21169. super(authentication, connectionFactory, audioSource, recognizerConfig, recognizer);
  21170. this.privIntentRecognizer = recognizer;
  21171. this.privIntentDataSent = false;
  21172. recognizerConfig.recognitionEndpointVersion = "1";
  21173. }
  21174. setIntents(addedIntents, umbrellaIntent) {
  21175. this.privAddedLmIntents = addedIntents;
  21176. this.privUmbrellaIntent = umbrellaIntent;
  21177. this.privIntentDataSent = true;
  21178. }
  21179. processTypeSpecificMessages(connectionMessage) {
  21180. let result;
  21181. let ev;
  21182. let processed = false;
  21183. const resultProps = new Exports_js_2.PropertyCollection();
  21184. if (connectionMessage.messageType === Exports_js_1.MessageType.Text) {
  21185. resultProps.setProperty(Exports_js_2.PropertyId.SpeechServiceResponse_JsonResult, connectionMessage.textBody);
  21186. }
  21187. switch (connectionMessage.path.toLowerCase()) {
  21188. case "speech.hypothesis":
  21189. const speechHypothesis = Exports_js_3.SpeechHypothesis.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  21190. result = new Exports_js_2.IntentRecognitionResult(undefined, this.privRequestSession.requestId, Exports_js_2.ResultReason.RecognizingIntent, speechHypothesis.Text, speechHypothesis.Duration, speechHypothesis.Offset, speechHypothesis.Language, speechHypothesis.LanguageDetectionConfidence, undefined, speechHypothesis.asJson(), resultProps);
  21191. this.privRequestSession.onHypothesis(result.offset);
  21192. ev = new Exports_js_2.IntentRecognitionEventArgs(result, speechHypothesis.Offset, this.privRequestSession.sessionId);
  21193. if (!!this.privIntentRecognizer.recognizing) {
  21194. try {
  21195. this.privIntentRecognizer.recognizing(this.privIntentRecognizer, ev);
  21196. /* eslint-disable no-empty */
  21197. }
  21198. catch (error) {
  21199. // Not going to let errors in the event handler
  21200. // trip things up.
  21201. }
  21202. }
  21203. processed = true;
  21204. break;
  21205. case "speech.phrase":
  21206. const simple = Exports_js_3.SimpleSpeechPhrase.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  21207. result = new Exports_js_2.IntentRecognitionResult(undefined, this.privRequestSession.requestId, Exports_js_3.EnumTranslation.implTranslateRecognitionResult(simple.RecognitionStatus), simple.DisplayText, simple.Duration, simple.Offset, simple.Language, simple.LanguageDetectionConfidence, undefined, simple.asJson(), resultProps);
  21208. ev = new Exports_js_2.IntentRecognitionEventArgs(result, result.offset, this.privRequestSession.sessionId);
  21209. const sendEvent = () => {
  21210. if (!!this.privIntentRecognizer.recognized) {
  21211. try {
  21212. this.privIntentRecognizer.recognized(this.privIntentRecognizer, ev);
  21213. /* eslint-disable no-empty */
  21214. }
  21215. catch (error) {
  21216. // Not going to let errors in the event handler
  21217. // trip things up.
  21218. }
  21219. }
  21220. // report result to promise.
  21221. if (!!this.privSuccessCallback) {
  21222. try {
  21223. this.privSuccessCallback(result);
  21224. }
  21225. catch (e) {
  21226. if (!!this.privErrorCallback) {
  21227. this.privErrorCallback(e);
  21228. }
  21229. }
  21230. // Only invoke the call back once.
  21231. // and if it's successful don't invoke the
  21232. // error after that.
  21233. this.privSuccessCallback = undefined;
  21234. this.privErrorCallback = undefined;
  21235. }
  21236. };
  21237. // If intent data was sent, the terminal result for this recognizer is an intent being found.
  21238. // If no intent data was sent, the terminal event is speech recognition being successful.
  21239. if (false === this.privIntentDataSent || Exports_js_2.ResultReason.NoMatch === ev.result.reason) {
  21240. // Advance the buffers.
  21241. this.privRequestSession.onPhraseRecognized(ev.offset + ev.result.duration);
  21242. sendEvent();
  21243. }
  21244. else {
  21245. // Squirrel away the args, when the response event arrives it will build upon them
  21246. // and then return
  21247. this.privPendingIntentArgs = ev;
  21248. }
  21249. processed = true;
  21250. break;
  21251. case "response":
  21252. // Response from LUIS
  21253. ev = this.privPendingIntentArgs;
  21254. this.privPendingIntentArgs = undefined;
  21255. if (undefined === ev) {
  21256. if ("" === connectionMessage.textBody) {
  21257. // This condition happens if there is nothing but silence in the
  21258. // audio sent to the service.
  21259. return;
  21260. }
  21261. // Odd... Not sure this can happen
  21262. ev = new Exports_js_2.IntentRecognitionEventArgs(new Exports_js_2.IntentRecognitionResult(), 0, this.privRequestSession.sessionId);
  21263. }
  21264. const intentResponse = Exports_js_3.IntentResponse.fromJSON(connectionMessage.textBody);
  21265. // If LUIS didn't return anything, send the existing event, else
  21266. // modify it to show the match.
  21267. // See if the intent found is in the list of intents asked for.
  21268. if (null !== intentResponse && !!intentResponse.topScoringIntent && !!intentResponse.topScoringIntent.intent) {
  21269. let addedIntent = this.privAddedLmIntents[intentResponse.topScoringIntent.intent];
  21270. if (this.privUmbrellaIntent !== undefined) {
  21271. addedIntent = this.privUmbrellaIntent;
  21272. }
  21273. if (!!addedIntent) {
  21274. const intentId = addedIntent === undefined || addedIntent.intentName === undefined ? intentResponse.topScoringIntent.intent : addedIntent.intentName;
  21275. let reason = ev.result.reason;
  21276. if (undefined !== intentId) {
  21277. reason = Exports_js_2.ResultReason.RecognizedIntent;
  21278. }
  21279. // make sure, properties is set.
  21280. const properties = (undefined !== ev.result.properties) ?
  21281. ev.result.properties : new Exports_js_2.PropertyCollection();
  21282. properties.setProperty(Exports_js_2.PropertyId.LanguageUnderstandingServiceResponse_JsonResult, connectionMessage.textBody);
  21283. ev = new Exports_js_2.IntentRecognitionEventArgs(new Exports_js_2.IntentRecognitionResult(intentId, ev.result.resultId, reason, ev.result.text, ev.result.duration, ev.result.offset, undefined, undefined, ev.result.errorDetails, ev.result.json, properties), ev.offset, ev.sessionId);
  21284. }
  21285. }
  21286. this.privRequestSession.onPhraseRecognized(ev.offset + ev.result.duration);
  21287. if (!!this.privIntentRecognizer.recognized) {
  21288. try {
  21289. this.privIntentRecognizer.recognized(this.privIntentRecognizer, ev);
  21290. /* eslint-disable no-empty */
  21291. }
  21292. catch (error) {
  21293. // Not going to let errors in the event handler
  21294. // trip things up.
  21295. }
  21296. }
  21297. // report result to promise.
  21298. if (!!this.privSuccessCallback) {
  21299. try {
  21300. this.privSuccessCallback(ev.result);
  21301. }
  21302. catch (e) {
  21303. if (!!this.privErrorCallback) {
  21304. this.privErrorCallback(e);
  21305. }
  21306. }
  21307. // Only invoke the call back once.
  21308. // and if it's successful don't invoke the
  21309. // error after that.
  21310. this.privSuccessCallback = undefined;
  21311. this.privErrorCallback = undefined;
  21312. }
  21313. processed = true;
  21314. break;
  21315. default:
  21316. break;
  21317. }
  21318. const defferal = new Exports_js_1.Deferred();
  21319. defferal.resolve(processed);
  21320. return defferal.promise;
  21321. }
  21322. // Cancels recognition.
  21323. cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  21324. const properties = new Exports_js_2.PropertyCollection();
  21325. properties.setProperty(Exports_js_3.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[errorCode]);
  21326. if (!!this.privIntentRecognizer.canceled) {
  21327. const cancelEvent = new Exports_js_2.IntentRecognitionCanceledEventArgs(cancellationReason, error, errorCode, undefined, undefined, sessionId);
  21328. try {
  21329. this.privIntentRecognizer.canceled(this.privIntentRecognizer, cancelEvent);
  21330. /* eslint-disable no-empty */
  21331. }
  21332. catch { }
  21333. }
  21334. if (!!this.privSuccessCallback) {
  21335. const result = new Exports_js_2.IntentRecognitionResult(undefined, // Intent Id
  21336. requestId, Exports_js_2.ResultReason.Canceled, undefined, // Text
  21337. undefined, // Duration
  21338. undefined, // Offset
  21339. undefined, // Language
  21340. undefined, // LanguageDetectionConfidence
  21341. error, undefined, // Json
  21342. properties);
  21343. try {
  21344. this.privSuccessCallback(result);
  21345. this.privSuccessCallback = undefined;
  21346. /* eslint-disable no-empty */
  21347. }
  21348. catch { }
  21349. }
  21350. }
  21351. }
  21352. exports.IntentServiceRecognizer = IntentServiceRecognizer;
  21353. /***/ }),
  21354. /* 242 */
  21355. /***/ ((__unused_webpack_module, exports) => {
  21356. "use strict";
  21357. // Copyright (c) Microsoft Corporation. All rights reserved.
  21358. // Licensed under the MIT license.
  21359. // response
  21360. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21361. exports.IntentResponse = void 0;
  21362. class IntentResponse {
  21363. constructor(json) {
  21364. if (json === "") {
  21365. this.privIntentResponse = {};
  21366. }
  21367. else {
  21368. this.privIntentResponse = JSON.parse(json);
  21369. }
  21370. }
  21371. static fromJSON(json) {
  21372. return new IntentResponse(json);
  21373. }
  21374. get query() {
  21375. return this.privIntentResponse.query;
  21376. }
  21377. get topScoringIntent() {
  21378. return this.privIntentResponse.topScoringIntent;
  21379. }
  21380. get entities() {
  21381. return this.privIntentResponse.entities;
  21382. }
  21383. }
  21384. exports.IntentResponse = IntentResponse;
  21385. /***/ }),
  21386. /* 243 */
  21387. /***/ ((__unused_webpack_module, exports) => {
  21388. "use strict";
  21389. // Copyright (c) Microsoft Corporation. All rights reserved.
  21390. // Licensed under the MIT license.
  21391. /* eslint-disable max-classes-per-file */
  21392. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21393. /***/ }),
  21394. /* 244 */
  21395. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21396. "use strict";
  21397. // Copyright (c) Microsoft Corporation. All rights reserved.
  21398. // Licensed under the MIT license.
  21399. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21400. exports.RequestSession = void 0;
  21401. const Exports_js_1 = __webpack_require__(4);
  21402. const RecognitionEvents_js_1 = __webpack_require__(205);
  21403. const ServiceTelemetryListener_Internal_js_1 = __webpack_require__(245);
  21404. class RequestSession {
  21405. constructor(audioSourceId) {
  21406. this.privIsDisposed = false;
  21407. this.privDetachables = new Array();
  21408. this.privIsAudioNodeDetached = false;
  21409. this.privIsRecognizing = false;
  21410. this.privIsSpeechEnded = false;
  21411. this.privTurnStartAudioOffset = 0;
  21412. this.privLastRecoOffset = 0;
  21413. this.privHypothesisReceived = false;
  21414. this.privBytesSent = 0;
  21415. this.privRecognitionBytesSent = 0;
  21416. this.privRecogNumber = 0;
  21417. this.privInTurn = false;
  21418. this.privConnectionAttempts = 0;
  21419. this.privAudioSourceId = audioSourceId;
  21420. this.privRequestId = (0, Exports_js_1.createNoDashGuid)();
  21421. this.privAudioNodeId = (0, Exports_js_1.createNoDashGuid)();
  21422. this.privTurnDeferral = new Exports_js_1.Deferred();
  21423. // We're not in a turn, so resolve.
  21424. this.privTurnDeferral.resolve();
  21425. }
  21426. get sessionId() {
  21427. return this.privSessionId;
  21428. }
  21429. get requestId() {
  21430. return this.privRequestId;
  21431. }
  21432. get audioNodeId() {
  21433. return this.privAudioNodeId;
  21434. }
  21435. get turnCompletionPromise() {
  21436. return this.privTurnDeferral.promise;
  21437. }
  21438. get isSpeechEnded() {
  21439. return this.privIsSpeechEnded;
  21440. }
  21441. get isRecognizing() {
  21442. return this.privIsRecognizing;
  21443. }
  21444. get currentTurnAudioOffset() {
  21445. return this.privTurnStartAudioOffset;
  21446. }
  21447. get recogNumber() {
  21448. return this.privRecogNumber;
  21449. }
  21450. get numConnectionAttempts() {
  21451. return this.privConnectionAttempts;
  21452. }
  21453. // The number of bytes sent for the current connection.
  21454. // Counter is reset to 0 each time a connection is established.
  21455. get bytesSent() {
  21456. return this.privBytesSent;
  21457. }
  21458. // The number of bytes sent for the current recognition.
  21459. // Counter is reset to 0 each time recognition is started.
  21460. get recognitionBytesSent() {
  21461. return this.privRecognitionBytesSent;
  21462. }
  21463. listenForServiceTelemetry(eventSource) {
  21464. if (!!this.privServiceTelemetryListener) {
  21465. this.privDetachables.push(eventSource.attachListener(this.privServiceTelemetryListener));
  21466. }
  21467. }
  21468. startNewRecognition() {
  21469. this.privRecognitionBytesSent = 0;
  21470. this.privIsSpeechEnded = false;
  21471. this.privIsRecognizing = true;
  21472. this.privTurnStartAudioOffset = 0;
  21473. this.privLastRecoOffset = 0;
  21474. this.privRecogNumber++;
  21475. this.privServiceTelemetryListener = new ServiceTelemetryListener_Internal_js_1.ServiceTelemetryListener(this.privRequestId, this.privAudioSourceId, this.privAudioNodeId);
  21476. this.onEvent(new RecognitionEvents_js_1.RecognitionTriggeredEvent(this.requestId, this.privSessionId, this.privAudioSourceId, this.privAudioNodeId));
  21477. }
  21478. async onAudioSourceAttachCompleted(audioNode, isError) {
  21479. this.privAudioNode = audioNode;
  21480. this.privIsAudioNodeDetached = false;
  21481. if (isError) {
  21482. await this.onComplete();
  21483. }
  21484. else {
  21485. this.onEvent(new RecognitionEvents_js_1.ListeningStartedEvent(this.privRequestId, this.privSessionId, this.privAudioSourceId, this.privAudioNodeId));
  21486. }
  21487. }
  21488. onPreConnectionStart(authFetchEventId, connectionId) {
  21489. this.privAuthFetchEventId = authFetchEventId;
  21490. this.privSessionId = connectionId;
  21491. this.onEvent(new RecognitionEvents_js_1.ConnectingToServiceEvent(this.privRequestId, this.privAuthFetchEventId, this.privSessionId));
  21492. }
  21493. async onAuthCompleted(isError) {
  21494. if (isError) {
  21495. await this.onComplete();
  21496. }
  21497. }
  21498. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  21499. async onConnectionEstablishCompleted(statusCode, reason) {
  21500. if (statusCode === 200) {
  21501. this.onEvent(new RecognitionEvents_js_1.RecognitionStartedEvent(this.requestId, this.privAudioSourceId, this.privAudioNodeId, this.privAuthFetchEventId, this.privSessionId));
  21502. if (!!this.privAudioNode) {
  21503. this.privAudioNode.replay();
  21504. }
  21505. this.privTurnStartAudioOffset = this.privLastRecoOffset;
  21506. this.privBytesSent = 0;
  21507. return;
  21508. }
  21509. else if (statusCode === 403) {
  21510. await this.onComplete();
  21511. }
  21512. }
  21513. async onServiceTurnEndResponse(continuousRecognition) {
  21514. this.privTurnDeferral.resolve();
  21515. if (!continuousRecognition || this.isSpeechEnded) {
  21516. await this.onComplete();
  21517. this.privInTurn = false;
  21518. }
  21519. else {
  21520. // Start a new request set.
  21521. this.privTurnStartAudioOffset = this.privLastRecoOffset;
  21522. this.privAudioNode.replay();
  21523. }
  21524. }
  21525. onSpeechContext() {
  21526. this.privRequestId = (0, Exports_js_1.createNoDashGuid)();
  21527. }
  21528. onServiceTurnStartResponse() {
  21529. if (!!this.privTurnDeferral && !!this.privInTurn) {
  21530. // What? How are we starting a turn with another not done?
  21531. this.privTurnDeferral.reject("Another turn started before current completed.");
  21532. // Avoid UnhandledPromiseRejection if privTurnDeferral is not being awaited
  21533. // eslint-disable-next-line @typescript-eslint/no-empty-function
  21534. this.privTurnDeferral.promise.then().catch(() => { });
  21535. }
  21536. this.privInTurn = true;
  21537. this.privTurnDeferral = new Exports_js_1.Deferred();
  21538. }
  21539. onHypothesis(offset) {
  21540. if (!this.privHypothesisReceived) {
  21541. this.privHypothesisReceived = true;
  21542. this.privServiceTelemetryListener.hypothesisReceived(this.privAudioNode.findTimeAtOffset(offset));
  21543. }
  21544. }
  21545. onPhraseRecognized(offset) {
  21546. this.privServiceTelemetryListener.phraseReceived(this.privAudioNode.findTimeAtOffset(offset));
  21547. this.onServiceRecognized(offset);
  21548. }
  21549. onServiceRecognized(offset) {
  21550. this.privLastRecoOffset = offset;
  21551. this.privHypothesisReceived = false;
  21552. this.privAudioNode.shrinkBuffers(offset);
  21553. this.privConnectionAttempts = 0;
  21554. }
  21555. onAudioSent(bytesSent) {
  21556. this.privBytesSent += bytesSent;
  21557. this.privRecognitionBytesSent += bytesSent;
  21558. }
  21559. onRetryConnection() {
  21560. this.privConnectionAttempts++;
  21561. }
  21562. async dispose() {
  21563. if (!this.privIsDisposed) {
  21564. // we should have completed by now. If we did not its an unknown error.
  21565. this.privIsDisposed = true;
  21566. for (const detachable of this.privDetachables) {
  21567. await detachable.detach();
  21568. }
  21569. if (!!this.privServiceTelemetryListener) {
  21570. this.privServiceTelemetryListener.dispose();
  21571. }
  21572. this.privIsRecognizing = false;
  21573. }
  21574. }
  21575. getTelemetry() {
  21576. if (this.privServiceTelemetryListener.hasTelemetry) {
  21577. return this.privServiceTelemetryListener.getTelemetry();
  21578. }
  21579. else {
  21580. return null;
  21581. }
  21582. }
  21583. async onStopRecognizing() {
  21584. await this.onComplete();
  21585. }
  21586. // Should be called with the audioNode for this session has indicated that it is out of speech.
  21587. onSpeechEnded() {
  21588. this.privIsSpeechEnded = true;
  21589. }
  21590. onEvent(event) {
  21591. if (!!this.privServiceTelemetryListener) {
  21592. this.privServiceTelemetryListener.onEvent(event);
  21593. }
  21594. Exports_js_1.Events.instance.onEvent(event);
  21595. }
  21596. async onComplete() {
  21597. if (!!this.privIsRecognizing) {
  21598. this.privIsRecognizing = false;
  21599. await this.detachAudioNode();
  21600. }
  21601. }
  21602. async detachAudioNode() {
  21603. if (!this.privIsAudioNodeDetached) {
  21604. this.privIsAudioNodeDetached = true;
  21605. if (this.privAudioNode) {
  21606. await this.privAudioNode.detach();
  21607. }
  21608. }
  21609. }
  21610. }
  21611. exports.RequestSession = RequestSession;
  21612. /***/ }),
  21613. /* 245 */
  21614. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21615. "use strict";
  21616. // Copyright (c) Microsoft Corporation. All rights reserved.
  21617. // Licensed under the MIT license.
  21618. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21619. exports.ServiceTelemetryListener = void 0;
  21620. /* eslint-disable max-classes-per-file */
  21621. const Exports_js_1 = __webpack_require__(4);
  21622. const RecognitionEvents_js_1 = __webpack_require__(205);
  21623. class ServiceTelemetryListener {
  21624. constructor(requestId, audioSourceId, audioNodeId) {
  21625. this.privIsDisposed = false;
  21626. this.privListeningTriggerMetric = null;
  21627. this.privMicMetric = null;
  21628. this.privConnectionEstablishMetric = null;
  21629. this.privRequestId = requestId;
  21630. this.privAudioSourceId = audioSourceId;
  21631. this.privAudioNodeId = audioNodeId;
  21632. this.privReceivedMessages = {};
  21633. this.privPhraseLatencies = [];
  21634. this.privHypothesisLatencies = [];
  21635. }
  21636. phraseReceived(audioReceivedTime) {
  21637. if (audioReceivedTime > 0) { // 0 indicates the time is unknown. Drop it.
  21638. this.privPhraseLatencies.push(Date.now() - audioReceivedTime);
  21639. }
  21640. }
  21641. hypothesisReceived(audioReceivedTime) {
  21642. if (audioReceivedTime > 0) { // 0 indicates the time is unknown. Drop it.
  21643. this.privHypothesisLatencies.push(Date.now() - audioReceivedTime);
  21644. }
  21645. }
  21646. onEvent(e) {
  21647. if (this.privIsDisposed) {
  21648. return;
  21649. }
  21650. if (e instanceof RecognitionEvents_js_1.RecognitionTriggeredEvent && e.requestId === this.privRequestId) {
  21651. this.privListeningTriggerMetric = {
  21652. End: e.eventTime,
  21653. Name: "ListeningTrigger",
  21654. Start: e.eventTime,
  21655. };
  21656. }
  21657. if (e instanceof Exports_js_1.AudioStreamNodeAttachingEvent && e.audioSourceId === this.privAudioSourceId && e.audioNodeId === this.privAudioNodeId) {
  21658. this.privMicStartTime = e.eventTime;
  21659. }
  21660. if (e instanceof Exports_js_1.AudioStreamNodeAttachedEvent && e.audioSourceId === this.privAudioSourceId && e.audioNodeId === this.privAudioNodeId) {
  21661. this.privMicStartTime = e.eventTime;
  21662. }
  21663. if (e instanceof Exports_js_1.AudioSourceErrorEvent && e.audioSourceId === this.privAudioSourceId) {
  21664. if (!this.privMicMetric) {
  21665. this.privMicMetric = {
  21666. End: e.eventTime,
  21667. Error: e.error,
  21668. Name: "Microphone",
  21669. Start: this.privMicStartTime,
  21670. };
  21671. }
  21672. }
  21673. if (e instanceof Exports_js_1.AudioStreamNodeErrorEvent && e.audioSourceId === this.privAudioSourceId && e.audioNodeId === this.privAudioNodeId) {
  21674. if (!this.privMicMetric) {
  21675. this.privMicMetric = {
  21676. End: e.eventTime,
  21677. Error: e.error,
  21678. Name: "Microphone",
  21679. Start: this.privMicStartTime,
  21680. };
  21681. }
  21682. }
  21683. if (e instanceof Exports_js_1.AudioStreamNodeDetachedEvent && e.audioSourceId === this.privAudioSourceId && e.audioNodeId === this.privAudioNodeId) {
  21684. if (!this.privMicMetric) {
  21685. this.privMicMetric = {
  21686. End: e.eventTime,
  21687. Name: "Microphone",
  21688. Start: this.privMicStartTime,
  21689. };
  21690. }
  21691. }
  21692. if (e instanceof RecognitionEvents_js_1.ConnectingToServiceEvent && e.requestId === this.privRequestId) {
  21693. this.privConnectionId = e.sessionId;
  21694. }
  21695. if (e instanceof Exports_js_1.ConnectionStartEvent && e.connectionId === this.privConnectionId) {
  21696. this.privConnectionStartTime = e.eventTime;
  21697. }
  21698. if (e instanceof Exports_js_1.ConnectionEstablishedEvent && e.connectionId === this.privConnectionId) {
  21699. if (!this.privConnectionEstablishMetric) {
  21700. this.privConnectionEstablishMetric = {
  21701. End: e.eventTime,
  21702. Id: this.privConnectionId,
  21703. Name: "Connection",
  21704. Start: this.privConnectionStartTime,
  21705. };
  21706. }
  21707. }
  21708. if (e instanceof Exports_js_1.ConnectionEstablishErrorEvent && e.connectionId === this.privConnectionId) {
  21709. if (!this.privConnectionEstablishMetric) {
  21710. this.privConnectionEstablishMetric = {
  21711. End: e.eventTime,
  21712. Error: this.getConnectionError(e.statusCode),
  21713. Id: this.privConnectionId,
  21714. Name: "Connection",
  21715. Start: this.privConnectionStartTime,
  21716. };
  21717. }
  21718. }
  21719. if (e instanceof Exports_js_1.ConnectionMessageReceivedEvent && e.connectionId === this.privConnectionId) {
  21720. if (e.message && e.message.headers && e.message.headers.path) {
  21721. if (!this.privReceivedMessages[e.message.headers.path]) {
  21722. this.privReceivedMessages[e.message.headers.path] = new Array();
  21723. }
  21724. const maxMessagesToSend = 50;
  21725. if (this.privReceivedMessages[e.message.headers.path].length < maxMessagesToSend) {
  21726. this.privReceivedMessages[e.message.headers.path].push(e.networkReceivedTime);
  21727. }
  21728. }
  21729. }
  21730. }
  21731. getTelemetry() {
  21732. const metrics = new Array();
  21733. if (this.privListeningTriggerMetric) {
  21734. metrics.push(this.privListeningTriggerMetric);
  21735. }
  21736. if (this.privMicMetric) {
  21737. metrics.push(this.privMicMetric);
  21738. }
  21739. if (this.privConnectionEstablishMetric) {
  21740. metrics.push(this.privConnectionEstablishMetric);
  21741. }
  21742. if (this.privPhraseLatencies.length > 0) {
  21743. metrics.push({
  21744. PhraseLatencyMs: this.privPhraseLatencies,
  21745. });
  21746. }
  21747. if (this.privHypothesisLatencies.length > 0) {
  21748. metrics.push({
  21749. FirstHypothesisLatencyMs: this.privHypothesisLatencies,
  21750. });
  21751. }
  21752. const telemetry = {
  21753. Metrics: metrics,
  21754. ReceivedMessages: this.privReceivedMessages,
  21755. };
  21756. const json = JSON.stringify(telemetry);
  21757. // We dont want to send the same telemetry again. So clean those out.
  21758. this.privReceivedMessages = {};
  21759. this.privListeningTriggerMetric = null;
  21760. this.privMicMetric = null;
  21761. this.privConnectionEstablishMetric = null;
  21762. this.privPhraseLatencies = [];
  21763. this.privHypothesisLatencies = [];
  21764. return json;
  21765. }
  21766. // Determines if there are any telemetry events to send to the service.
  21767. get hasTelemetry() {
  21768. return (Object.keys(this.privReceivedMessages).length !== 0 ||
  21769. this.privListeningTriggerMetric !== null ||
  21770. this.privMicMetric !== null ||
  21771. this.privConnectionEstablishMetric !== null ||
  21772. this.privPhraseLatencies.length !== 0 ||
  21773. this.privHypothesisLatencies.length !== 0);
  21774. }
  21775. dispose() {
  21776. this.privIsDisposed = true;
  21777. }
  21778. getConnectionError(statusCode) {
  21779. /*
  21780. -- Websocket status codes --
  21781. NormalClosure = 1000,
  21782. EndpointUnavailable = 1001,
  21783. ProtocolError = 1002,
  21784. InvalidMessageType = 1003,
  21785. Empty = 1005,
  21786. InvalidPayloadData = 1007,
  21787. PolicyViolation = 1008,
  21788. MessageTooBig = 1009,
  21789. MandatoryExtension = 1010,
  21790. InternalServerError = 1011
  21791. */
  21792. switch (statusCode) {
  21793. case 400:
  21794. case 1002:
  21795. case 1003:
  21796. case 1005:
  21797. case 1007:
  21798. case 1008:
  21799. case 1009: return "BadRequest";
  21800. case 401: return "Unauthorized";
  21801. case 403: return "Forbidden";
  21802. case 503:
  21803. case 1001: return "ServerUnavailable";
  21804. case 500:
  21805. case 1011: return "ServerError";
  21806. case 408:
  21807. case 504: return "Timeout";
  21808. default: return "statuscode:" + statusCode.toString();
  21809. }
  21810. }
  21811. }
  21812. exports.ServiceTelemetryListener = ServiceTelemetryListener;
  21813. /***/ }),
  21814. /* 246 */
  21815. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21816. "use strict";
  21817. // Copyright (c) Microsoft Corporation. All rights reserved.
  21818. // Licensed under the MIT license.
  21819. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21820. exports.SpeechContext = void 0;
  21821. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  21822. const PhraseOutput_js_1 = __webpack_require__(247);
  21823. /**
  21824. * Represents the JSON used in the speech.context message sent to the speech service.
  21825. * The dynamic grammar is always refreshed from the encapsulated dynamic grammar object.
  21826. */
  21827. class SpeechContext {
  21828. constructor(dynamicGrammar) {
  21829. this.privContext = {};
  21830. this.privDynamicGrammar = dynamicGrammar;
  21831. }
  21832. getContext() {
  21833. return this.privContext;
  21834. }
  21835. /**
  21836. * @Internal
  21837. * This is only used by pronunciation assessment config.
  21838. * Do not use externally, object returned will change without warning or notice.
  21839. */
  21840. setPronunciationAssessmentParams(params, contentAssessmentTopic, isSpeakerDiarizationEnabled = false) {
  21841. if (this.privContext.phraseDetection === undefined) {
  21842. this.privContext.phraseDetection = {
  21843. enrichment: {
  21844. pronunciationAssessment: {}
  21845. }
  21846. };
  21847. }
  21848. if (this.privContext.phraseDetection.enrichment === undefined) {
  21849. this.privContext.phraseDetection.enrichment = {
  21850. pronunciationAssessment: {}
  21851. };
  21852. }
  21853. this.privContext.phraseDetection.enrichment.pronunciationAssessment = JSON.parse(params) || {};
  21854. if (isSpeakerDiarizationEnabled) {
  21855. this.privContext.phraseDetection.mode = PhraseDetectionContext_js_1.RecognitionMode.Conversation;
  21856. }
  21857. this.setWordLevelTimings();
  21858. this.privContext.phraseOutput.detailed.options.push(PhraseOutput_js_1.PhraseOption.PronunciationAssessment);
  21859. if (this.privContext.phraseOutput.detailed.options.indexOf(PhraseOutput_js_1.PhraseOption.SNR) === -1) {
  21860. this.privContext.phraseOutput.detailed.options.push(PhraseOutput_js_1.PhraseOption.SNR);
  21861. }
  21862. if (!!contentAssessmentTopic) {
  21863. this.privContext.phraseDetection.enrichment.contentAssessment = {
  21864. topic: contentAssessmentTopic
  21865. };
  21866. this.privContext.phraseOutput.detailed.options.push(PhraseOutput_js_1.PhraseOption.ContentAssessment);
  21867. }
  21868. }
  21869. setDetailedOutputFormat() {
  21870. if (this.privContext.phraseOutput === undefined) {
  21871. this.privContext.phraseOutput = {
  21872. detailed: {
  21873. options: []
  21874. }
  21875. };
  21876. }
  21877. if (this.privContext.phraseOutput.detailed === undefined) {
  21878. this.privContext.phraseOutput.detailed = {
  21879. options: []
  21880. };
  21881. }
  21882. this.privContext.phraseOutput.format = PhraseOutput_js_1.OutputFormat.Detailed;
  21883. }
  21884. setWordLevelTimings() {
  21885. if (this.privContext.phraseOutput === undefined) {
  21886. this.privContext.phraseOutput = {
  21887. detailed: {
  21888. options: []
  21889. }
  21890. };
  21891. }
  21892. if (this.privContext.phraseOutput.detailed === undefined) {
  21893. this.privContext.phraseOutput.detailed = {
  21894. options: []
  21895. };
  21896. }
  21897. this.privContext.phraseOutput.format = PhraseOutput_js_1.OutputFormat.Detailed;
  21898. if (this.privContext.phraseOutput.detailed.options.indexOf(PhraseOutput_js_1.PhraseOption.WordTimings) === -1) {
  21899. this.privContext.phraseOutput.detailed.options.push(PhraseOutput_js_1.PhraseOption.WordTimings);
  21900. }
  21901. }
  21902. setSpeakerDiarizationAudioOffsetMs(audioOffsetMs) {
  21903. this.privContext.phraseDetection.speakerDiarization.audioOffsetMs = audioOffsetMs;
  21904. }
  21905. toJSON() {
  21906. const dgi = this.privDynamicGrammar.generateGrammarObject();
  21907. this.privContext.dgi = dgi;
  21908. const ret = JSON.stringify(this.privContext);
  21909. return ret;
  21910. }
  21911. }
  21912. exports.SpeechContext = SpeechContext;
  21913. /***/ }),
  21914. /* 247 */
  21915. /***/ ((__unused_webpack_module, exports) => {
  21916. "use strict";
  21917. //
  21918. // Copyright (c) Microsoft. All rights reserved.
  21919. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  21920. //
  21921. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21922. exports.TentativePhraseResultsOption = exports.OutputFormat = exports.PhraseExtension = exports.PhraseOption = void 0;
  21923. /**
  21924. * The detailed output options.
  21925. */
  21926. var PhraseOption;
  21927. (function (PhraseOption) {
  21928. PhraseOption["WordTimings"] = "WordTimings";
  21929. PhraseOption["SNR"] = "SNR";
  21930. PhraseOption["Pronunciation"] = "Pronunciation";
  21931. PhraseOption["WordPronunciation"] = "WordPronunciation";
  21932. PhraseOption["WordConfidence"] = "WordConfidence";
  21933. PhraseOption["Words"] = "Words";
  21934. PhraseOption["Sentiment"] = "Sentiment";
  21935. PhraseOption["PronunciationAssessment"] = "PronunciationAssessment";
  21936. PhraseOption["ContentAssessment"] = "ContentAssessment";
  21937. PhraseOption["PhraseAMScore"] = "PhraseAMScore";
  21938. PhraseOption["PhraseLMScore"] = "PhraseLMScore";
  21939. PhraseOption["WordAMScore"] = "WordAMScore";
  21940. PhraseOption["WordLMScore"] = "WordLMScore";
  21941. PhraseOption["RuleTree"] = "RuleTree";
  21942. PhraseOption["NBestTimings"] = "NBestTimings";
  21943. PhraseOption["DecoderDiagnostics"] = "DecoderDiagnostics";
  21944. PhraseOption["DisplayWordTimings"] = "DisplayWordTimings";
  21945. PhraseOption["DisplayWords"] = "DisplayWords";
  21946. })(PhraseOption = exports.PhraseOption || (exports.PhraseOption = {}));
  21947. /**
  21948. * The detailed output extensions.
  21949. */
  21950. var PhraseExtension;
  21951. (function (PhraseExtension) {
  21952. PhraseExtension["Graph"] = "Graph";
  21953. PhraseExtension["Corrections"] = "Corrections";
  21954. PhraseExtension["Sentiment"] = "Sentiment";
  21955. })(PhraseExtension = exports.PhraseExtension || (exports.PhraseExtension = {}));
  21956. /**
  21957. * The Recognition modes
  21958. */
  21959. var OutputFormat;
  21960. (function (OutputFormat) {
  21961. OutputFormat["Simple"] = "Simple";
  21962. OutputFormat["Detailed"] = "Detailed";
  21963. })(OutputFormat = exports.OutputFormat || (exports.OutputFormat = {}));
  21964. /**
  21965. * The Tentative Phrase Results option
  21966. */
  21967. var TentativePhraseResultsOption;
  21968. (function (TentativePhraseResultsOption) {
  21969. TentativePhraseResultsOption["None"] = "None";
  21970. TentativePhraseResultsOption["Always"] = "Always";
  21971. })(TentativePhraseResultsOption = exports.TentativePhraseResultsOption || (exports.TentativePhraseResultsOption = {}));
  21972. /***/ }),
  21973. /* 248 */
  21974. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21975. "use strict";
  21976. // Copyright (c) Microsoft Corporation. All rights reserved.
  21977. // Licensed under the MIT license.
  21978. Object.defineProperty(exports, "__esModule", ({ value: true }));
  21979. exports.DynamicGrammarBuilder = void 0;
  21980. const Group_js_1 = __webpack_require__(249);
  21981. /**
  21982. * Responsible for building the object to be sent to the speech service to support dynamic grammars.
  21983. * @class DynamicGrammarBuilder
  21984. */
  21985. class DynamicGrammarBuilder {
  21986. // Adds one more reference phrases to the dynamic grammar to send.
  21987. // All added phrases are generic phrases.
  21988. addPhrase(phrase) {
  21989. if (!this.privPhrases) {
  21990. this.privPhrases = [];
  21991. }
  21992. if (phrase instanceof Array) {
  21993. this.privPhrases = this.privPhrases.concat(phrase);
  21994. }
  21995. else {
  21996. this.privPhrases.push(phrase);
  21997. }
  21998. }
  21999. // Clears all phrases stored in the current object.
  22000. clearPhrases() {
  22001. this.privPhrases = undefined;
  22002. }
  22003. // Adds one or more reference grammars to the current grammar.
  22004. addReferenceGrammar(grammar) {
  22005. if (!this.privGrammars) {
  22006. this.privGrammars = [];
  22007. }
  22008. if (grammar instanceof Array) {
  22009. this.privGrammars = this.privGrammars.concat(grammar);
  22010. }
  22011. else {
  22012. this.privGrammars.push(grammar);
  22013. }
  22014. }
  22015. // clears all grammars stored on the recognizer.
  22016. clearGrammars() {
  22017. this.privGrammars = undefined;
  22018. }
  22019. // Generates an object that represents the dynamic grammar used by the Speech Service.
  22020. // This is done by building an object with the correct layout based on the phrases and reference grammars added to this instance
  22021. // of a DynamicGrammarBuilder
  22022. generateGrammarObject() {
  22023. if (this.privGrammars === undefined && this.privPhrases === undefined) {
  22024. return undefined;
  22025. }
  22026. const retObj = {};
  22027. retObj.referenceGrammars = this.privGrammars;
  22028. if (undefined !== this.privPhrases && 0 !== this.privPhrases.length) {
  22029. const retPhrases = [];
  22030. this.privPhrases.forEach((value) => {
  22031. retPhrases.push({
  22032. text: value,
  22033. });
  22034. });
  22035. retObj.groups = [{ type: Group_js_1.GroupType.Generic, items: retPhrases }];
  22036. }
  22037. return retObj;
  22038. }
  22039. }
  22040. exports.DynamicGrammarBuilder = DynamicGrammarBuilder;
  22041. /***/ }),
  22042. /* 249 */
  22043. /***/ ((__unused_webpack_module, exports) => {
  22044. "use strict";
  22045. //
  22046. // Copyright (c) Microsoft. All rights reserved.
  22047. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
  22048. //
  22049. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22050. exports.SubstringMatchType = exports.GroupType = void 0;
  22051. /**
  22052. * Represents the type of the Intent.
  22053. */
  22054. var GroupType;
  22055. (function (GroupType) {
  22056. GroupType["IntentText"] = "IntentText";
  22057. GroupType["IntentEntity"] = "IntentEntity";
  22058. GroupType["Generic"] = "Generic";
  22059. GroupType["People"] = "People";
  22060. GroupType["Place"] = "Place";
  22061. GroupType["DynamicEntity"] = "DynamicEntity";
  22062. })(GroupType = exports.GroupType || (exports.GroupType = {}));
  22063. /**
  22064. * Represents the type of the substring match.
  22065. */
  22066. var SubstringMatchType;
  22067. (function (SubstringMatchType) {
  22068. SubstringMatchType["None"] = "None";
  22069. SubstringMatchType["LeftRooted"] = "LeftRooted";
  22070. SubstringMatchType["PartialName"] = "PartialName";
  22071. SubstringMatchType["MiddleOfSentence"] = "MiddleOfSentence";
  22072. })(SubstringMatchType = exports.SubstringMatchType || (exports.SubstringMatchType = {}));
  22073. /***/ }),
  22074. /* 250 */
  22075. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22076. "use strict";
  22077. // Copyright (c) Microsoft Corporation. All rights reserved.
  22078. // Licensed under the MIT license.
  22079. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22080. exports.DialogServiceAdapter = void 0;
  22081. const Exports_js_1 = __webpack_require__(60);
  22082. const DialogEvents_js_1 = __webpack_require__(29);
  22083. const Exports_js_2 = __webpack_require__(4);
  22084. const AudioOutputFormat_js_1 = __webpack_require__(85);
  22085. const Exports_js_3 = __webpack_require__(79);
  22086. const DialogServiceTurnStateManager_js_1 = __webpack_require__(251);
  22087. const Exports_js_4 = __webpack_require__(2);
  22088. const ActivityResponsePayload_js_1 = __webpack_require__(253);
  22089. const InvocationSource_js_1 = __webpack_require__(254);
  22090. const KeywordDetection_js_1 = __webpack_require__(255);
  22091. const SpeechConnectionMessage_Internal_js_1 = __webpack_require__(207);
  22092. class DialogServiceAdapter extends Exports_js_4.ServiceRecognizerBase {
  22093. constructor(authentication, connectionFactory, audioSource, recognizerConfig, dialogServiceConnector) {
  22094. super(authentication, connectionFactory, audioSource, recognizerConfig, dialogServiceConnector);
  22095. this.privEvents = new Exports_js_2.EventSource();
  22096. this.privDialogServiceConnector = dialogServiceConnector;
  22097. this.receiveMessageOverride = () => this.receiveDialogMessageOverride();
  22098. this.privTurnStateManager = new DialogServiceTurnStateManager_js_1.DialogServiceTurnStateManager();
  22099. this.recognizeOverride =
  22100. (recoMode, successCallback, errorCallback) => this.listenOnce(recoMode, successCallback, errorCallback);
  22101. this.postConnectImplOverride = (connection) => this.dialogConnectImpl(connection);
  22102. this.configConnectionOverride = (connection) => this.configConnection(connection);
  22103. this.disconnectOverride = () => this.privDisconnect();
  22104. this.privDialogAudioSource = audioSource;
  22105. this.agentConfigSent = false;
  22106. this.privLastResult = null;
  22107. this.connectionEvents.attach((connectionEvent) => {
  22108. if (connectionEvent.name === "ConnectionClosedEvent") {
  22109. this.terminateMessageLoop = true;
  22110. }
  22111. });
  22112. }
  22113. async sendMessage(message) {
  22114. const interactionGuid = (0, Exports_js_2.createGuid)();
  22115. const requestId = (0, Exports_js_2.createNoDashGuid)();
  22116. const agentMessage = {
  22117. context: {
  22118. interactionId: interactionGuid
  22119. },
  22120. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  22121. messagePayload: JSON.parse(message),
  22122. version: 0.5
  22123. };
  22124. const agentMessageJson = JSON.stringify(agentMessage);
  22125. const connection = await this.fetchConnection();
  22126. await connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, "agent", requestId, "application/json", agentMessageJson));
  22127. }
  22128. async privDisconnect() {
  22129. await this.cancelRecognition(this.privRequestSession.sessionId, this.privRequestSession.requestId, Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.NoError, "Disconnecting");
  22130. this.terminateMessageLoop = true;
  22131. this.agentConfigSent = false;
  22132. return;
  22133. }
  22134. processTypeSpecificMessages(connectionMessage) {
  22135. const resultProps = new Exports_js_3.PropertyCollection();
  22136. if (connectionMessage.messageType === Exports_js_2.MessageType.Text) {
  22137. resultProps.setProperty(Exports_js_3.PropertyId.SpeechServiceResponse_JsonResult, connectionMessage.textBody);
  22138. }
  22139. let result;
  22140. let processed;
  22141. switch (connectionMessage.path.toLowerCase()) {
  22142. case "speech.phrase":
  22143. const speechPhrase = Exports_js_4.SimpleSpeechPhrase.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  22144. this.privRequestSession.onPhraseRecognized(speechPhrase.Offset + speechPhrase.Duration);
  22145. if (speechPhrase.RecognitionStatus !== Exports_js_4.RecognitionStatus.TooManyRequests && speechPhrase.RecognitionStatus !== Exports_js_4.RecognitionStatus.Error) {
  22146. const args = this.fireEventForResult(speechPhrase, resultProps);
  22147. this.privLastResult = args.result;
  22148. if (!!this.privDialogServiceConnector.recognized) {
  22149. try {
  22150. this.privDialogServiceConnector.recognized(this.privDialogServiceConnector, args);
  22151. /* eslint-disable no-empty */
  22152. }
  22153. catch (error) {
  22154. // Not going to let errors in the event handler
  22155. // trip things up.
  22156. }
  22157. }
  22158. }
  22159. processed = true;
  22160. break;
  22161. case "speech.hypothesis":
  22162. const hypothesis = Exports_js_4.SpeechHypothesis.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  22163. result = new Exports_js_3.SpeechRecognitionResult(this.privRequestSession.requestId, Exports_js_3.ResultReason.RecognizingSpeech, hypothesis.Text, hypothesis.Duration, hypothesis.Offset, hypothesis.Language, hypothesis.LanguageDetectionConfidence, undefined, undefined, hypothesis.asJson(), resultProps);
  22164. this.privRequestSession.onHypothesis(hypothesis.Offset);
  22165. const ev = new Exports_js_3.SpeechRecognitionEventArgs(result, hypothesis.Offset, this.privRequestSession.sessionId);
  22166. if (!!this.privDialogServiceConnector.recognizing) {
  22167. try {
  22168. this.privDialogServiceConnector.recognizing(this.privDialogServiceConnector, ev);
  22169. /* eslint-disable no-empty */
  22170. }
  22171. catch (error) {
  22172. // Not going to let errors in the event handler
  22173. // trip things up.
  22174. }
  22175. }
  22176. processed = true;
  22177. break;
  22178. case "speech.keyword":
  22179. const keyword = Exports_js_4.SpeechKeyword.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  22180. result = new Exports_js_3.SpeechRecognitionResult(this.privRequestSession.requestId, keyword.Status === "Accepted" ? Exports_js_3.ResultReason.RecognizedKeyword : Exports_js_3.ResultReason.NoMatch, keyword.Text, keyword.Duration, keyword.Offset, undefined, undefined, undefined, undefined, keyword.asJson(), resultProps);
  22181. if (keyword.Status !== "Accepted") {
  22182. this.privLastResult = result;
  22183. }
  22184. const event = new Exports_js_3.SpeechRecognitionEventArgs(result, result.duration, result.resultId);
  22185. if (!!this.privDialogServiceConnector.recognized) {
  22186. try {
  22187. this.privDialogServiceConnector.recognized(this.privDialogServiceConnector, event);
  22188. /* eslint-disable no-empty */
  22189. }
  22190. catch (error) {
  22191. // Not going to let errors in the event handler
  22192. // trip things up.
  22193. }
  22194. }
  22195. processed = true;
  22196. break;
  22197. case "audio":
  22198. {
  22199. const audioRequestId = connectionMessage.requestId.toUpperCase();
  22200. const turn = this.privTurnStateManager.GetTurn(audioRequestId);
  22201. try {
  22202. // Empty binary message signals end of stream.
  22203. if (!connectionMessage.binaryBody) {
  22204. turn.endAudioStream();
  22205. }
  22206. else {
  22207. turn.audioStream.write(connectionMessage.binaryBody);
  22208. }
  22209. }
  22210. catch (error) {
  22211. // Not going to let errors in the event handler
  22212. // trip things up.
  22213. }
  22214. }
  22215. processed = true;
  22216. break;
  22217. case "response":
  22218. {
  22219. this.handleResponseMessage(connectionMessage);
  22220. }
  22221. processed = true;
  22222. break;
  22223. default:
  22224. break;
  22225. }
  22226. const defferal = new Exports_js_2.Deferred();
  22227. defferal.resolve(processed);
  22228. return defferal.promise;
  22229. }
  22230. // Cancels recognition.
  22231. async cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  22232. this.terminateMessageLoop = true;
  22233. if (!!this.privRequestSession.isRecognizing) {
  22234. await this.privRequestSession.onStopRecognizing();
  22235. }
  22236. if (!!this.privDialogServiceConnector.canceled) {
  22237. const properties = new Exports_js_3.PropertyCollection();
  22238. properties.setProperty(Exports_js_4.CancellationErrorCodePropertyName, Exports_js_3.CancellationErrorCode[errorCode]);
  22239. const cancelEvent = new Exports_js_3.SpeechRecognitionCanceledEventArgs(cancellationReason, error, errorCode, undefined, sessionId);
  22240. try {
  22241. this.privDialogServiceConnector.canceled(this.privDialogServiceConnector, cancelEvent);
  22242. /* eslint-disable no-empty */
  22243. }
  22244. catch { }
  22245. if (!!this.privSuccessCallback) {
  22246. const result = new Exports_js_3.SpeechRecognitionResult(undefined, // ResultId
  22247. Exports_js_3.ResultReason.Canceled, undefined, // Text
  22248. undefined, // Duration
  22249. undefined, // Offset
  22250. undefined, // Language
  22251. undefined, // Language Detection Confidence
  22252. undefined, // Speaker Id
  22253. error, undefined, // Json
  22254. properties);
  22255. try {
  22256. this.privSuccessCallback(result);
  22257. this.privSuccessCallback = undefined;
  22258. /* eslint-disable no-empty */
  22259. }
  22260. catch { }
  22261. }
  22262. }
  22263. }
  22264. async listenOnce(recoMode, successCallback, errorCallback) {
  22265. this.privRecognizerConfig.recognitionMode = recoMode;
  22266. this.privSuccessCallback = successCallback;
  22267. this.privErrorCallback = errorCallback;
  22268. this.privRequestSession.startNewRecognition();
  22269. this.privRequestSession.listenForServiceTelemetry(this.privDialogAudioSource.events);
  22270. this.privRecognizerConfig.parameters.setProperty(Exports_js_3.PropertyId.Speech_SessionId, this.privRequestSession.sessionId);
  22271. // Start the connection to the service. The promise this will create is stored and will be used by configureConnection().
  22272. const conPromise = this.connectImpl();
  22273. const preAudioPromise = this.sendPreAudioMessages();
  22274. const node = await this.privDialogAudioSource.attach(this.privRequestSession.audioNodeId);
  22275. const format = await this.privDialogAudioSource.format;
  22276. const deviceInfo = await this.privDialogAudioSource.deviceInfo;
  22277. const audioNode = new Exports_js_1.ReplayableAudioNode(node, format.avgBytesPerSec);
  22278. await this.privRequestSession.onAudioSourceAttachCompleted(audioNode, false);
  22279. this.privRecognizerConfig.SpeechServiceConfig.Context.audio = { source: deviceInfo };
  22280. try {
  22281. await conPromise;
  22282. await preAudioPromise;
  22283. }
  22284. catch (error) {
  22285. await this.cancelRecognition(this.privRequestSession.sessionId, this.privRequestSession.requestId, Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.ConnectionFailure, error);
  22286. return Promise.resolve();
  22287. }
  22288. const sessionStartEventArgs = new Exports_js_3.SessionEventArgs(this.privRequestSession.sessionId);
  22289. if (!!this.privRecognizer.sessionStarted) {
  22290. this.privRecognizer.sessionStarted(this.privRecognizer, sessionStartEventArgs);
  22291. }
  22292. const audioSendPromise = this.sendAudio(audioNode);
  22293. // /* eslint-disable no-empty */
  22294. audioSendPromise.then(() => { }, async (error) => {
  22295. await this.cancelRecognition(this.privRequestSession.sessionId, this.privRequestSession.requestId, Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.RuntimeError, error);
  22296. });
  22297. }
  22298. // Establishes a websocket connection to the end point.
  22299. dialogConnectImpl(connection) {
  22300. this.privConnectionLoop = this.startMessageLoop();
  22301. return connection;
  22302. }
  22303. receiveDialogMessageOverride() {
  22304. // we won't rely on the cascading promises of the connection since we want to continually be available to receive messages
  22305. const communicationCustodian = new Exports_js_2.Deferred();
  22306. const loop = async () => {
  22307. try {
  22308. const isDisposed = this.isDisposed();
  22309. const terminateMessageLoop = (!this.isDisposed() && this.terminateMessageLoop);
  22310. if (isDisposed || terminateMessageLoop) {
  22311. // We're done.
  22312. communicationCustodian.resolve(undefined);
  22313. return;
  22314. }
  22315. const connection = await this.fetchConnection();
  22316. const message = await connection.read();
  22317. if (!message) {
  22318. return loop();
  22319. }
  22320. const connectionMessage = SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage.fromConnectionMessage(message);
  22321. switch (connectionMessage.path.toLowerCase()) {
  22322. case "turn.start":
  22323. {
  22324. const turnRequestId = connectionMessage.requestId.toUpperCase();
  22325. const audioSessionReqId = this.privRequestSession.requestId.toUpperCase();
  22326. // turn started by the service
  22327. if (turnRequestId !== audioSessionReqId) {
  22328. this.privTurnStateManager.StartTurn(turnRequestId);
  22329. }
  22330. else {
  22331. this.privRequestSession.onServiceTurnStartResponse();
  22332. }
  22333. }
  22334. break;
  22335. case "speech.startdetected":
  22336. const speechStartDetected = Exports_js_4.SpeechDetected.fromJSON(connectionMessage.textBody, this.privRequestSession.currentTurnAudioOffset);
  22337. const speechStartEventArgs = new Exports_js_3.RecognitionEventArgs(speechStartDetected.Offset, this.privRequestSession.sessionId);
  22338. if (!!this.privRecognizer.speechStartDetected) {
  22339. this.privRecognizer.speechStartDetected(this.privRecognizer, speechStartEventArgs);
  22340. }
  22341. break;
  22342. case "speech.enddetected":
  22343. let json;
  22344. if (connectionMessage.textBody.length > 0) {
  22345. json = connectionMessage.textBody;
  22346. }
  22347. else {
  22348. // If the request was empty, the JSON returned is empty.
  22349. json = "{ Offset: 0 }";
  22350. }
  22351. const speechStopDetected = Exports_js_4.SpeechDetected.fromJSON(json, this.privRequestSession.currentTurnAudioOffset);
  22352. this.privRequestSession.onServiceRecognized(speechStopDetected.Offset);
  22353. const speechStopEventArgs = new Exports_js_3.RecognitionEventArgs(speechStopDetected.Offset, this.privRequestSession.sessionId);
  22354. if (!!this.privRecognizer.speechEndDetected) {
  22355. this.privRecognizer.speechEndDetected(this.privRecognizer, speechStopEventArgs);
  22356. }
  22357. break;
  22358. case "turn.end":
  22359. {
  22360. const turnEndRequestId = connectionMessage.requestId.toUpperCase();
  22361. const audioSessionReqId = this.privRequestSession.requestId.toUpperCase();
  22362. // turn started by the service
  22363. if (turnEndRequestId !== audioSessionReqId) {
  22364. this.privTurnStateManager.CompleteTurn(turnEndRequestId);
  22365. }
  22366. else {
  22367. // Audio session turn
  22368. const sessionStopEventArgs = new Exports_js_3.SessionEventArgs(this.privRequestSession.sessionId);
  22369. await this.privRequestSession.onServiceTurnEndResponse(false);
  22370. if (!this.privRecognizerConfig.isContinuousRecognition || this.privRequestSession.isSpeechEnded || !this.privRequestSession.isRecognizing) {
  22371. if (!!this.privRecognizer.sessionStopped) {
  22372. this.privRecognizer.sessionStopped(this.privRecognizer, sessionStopEventArgs);
  22373. }
  22374. }
  22375. // report result to promise.
  22376. if (!!this.privSuccessCallback && this.privLastResult) {
  22377. try {
  22378. this.privSuccessCallback(this.privLastResult);
  22379. this.privLastResult = null;
  22380. }
  22381. catch (e) {
  22382. if (!!this.privErrorCallback) {
  22383. this.privErrorCallback(e);
  22384. }
  22385. }
  22386. // Only invoke the call back once.
  22387. // and if it's successful don't invoke the
  22388. // error after that.
  22389. this.privSuccessCallback = undefined;
  22390. this.privErrorCallback = undefined;
  22391. }
  22392. }
  22393. }
  22394. break;
  22395. default:
  22396. try {
  22397. const processed = await this.processTypeSpecificMessages(connectionMessage);
  22398. if (!processed) {
  22399. if (!!this.serviceEvents) {
  22400. this.serviceEvents.onEvent(new Exports_js_2.ServiceEvent(connectionMessage.path.toLowerCase(), connectionMessage.textBody));
  22401. }
  22402. }
  22403. }
  22404. catch (e) {
  22405. //
  22406. }
  22407. }
  22408. const ret = loop();
  22409. return ret;
  22410. }
  22411. catch (error) {
  22412. this.terminateMessageLoop = true;
  22413. communicationCustodian.resolve();
  22414. }
  22415. };
  22416. loop().catch((reason) => {
  22417. Exports_js_2.Events.instance.onEvent(new Exports_js_2.BackgroundEvent(reason));
  22418. });
  22419. return communicationCustodian.promise;
  22420. }
  22421. async startMessageLoop() {
  22422. this.terminateMessageLoop = false;
  22423. try {
  22424. await this.receiveDialogMessageOverride();
  22425. }
  22426. catch (error) {
  22427. await this.cancelRecognition(this.privRequestSession.sessionId, this.privRequestSession.requestId, Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.RuntimeError, error);
  22428. }
  22429. return Promise.resolve();
  22430. }
  22431. // Takes an established websocket connection to the endpoint and sends speech configuration information.
  22432. async configConnection(connection) {
  22433. if (this.terminateMessageLoop) {
  22434. this.terminateMessageLoop = false;
  22435. return Promise.reject("Connection to service terminated.");
  22436. }
  22437. await this.sendSpeechServiceConfig(connection, this.privRequestSession, this.privRecognizerConfig.SpeechServiceConfig.serialize());
  22438. await this.sendAgentConfig(connection);
  22439. return connection;
  22440. }
  22441. async sendPreAudioMessages() {
  22442. const connection = await this.fetchConnection();
  22443. this.addKeywordContextData();
  22444. await this.sendSpeechContext(connection, true);
  22445. await this.sendAgentContext(connection);
  22446. await this.sendWaveHeader(connection);
  22447. }
  22448. sendAgentConfig(connection) {
  22449. if (this.agentConfig && !this.agentConfigSent) {
  22450. if (this.privRecognizerConfig
  22451. .parameters
  22452. .getProperty(Exports_js_3.PropertyId.Conversation_DialogType) === Exports_js_3.DialogServiceConfig.DialogTypes.CustomCommands) {
  22453. const config = this.agentConfig.get();
  22454. config.botInfo.commandsCulture = this.privRecognizerConfig.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage, "en-us");
  22455. this.agentConfig.set(config);
  22456. }
  22457. this.onEvent(new DialogEvents_js_1.SendingAgentContextMessageEvent(this.agentConfig));
  22458. const agentConfigJson = this.agentConfig.toJsonString();
  22459. // guard against sending this multiple times on one connection
  22460. this.agentConfigSent = true;
  22461. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, "agent.config", this.privRequestSession.requestId, "application/json", agentConfigJson));
  22462. }
  22463. return;
  22464. }
  22465. sendAgentContext(connection) {
  22466. const guid = (0, Exports_js_2.createGuid)();
  22467. const speechActivityTemplate = this.privDialogServiceConnector.properties.getProperty(Exports_js_3.PropertyId.Conversation_Speech_Activity_Template);
  22468. const agentContext = {
  22469. channelData: "",
  22470. context: {
  22471. interactionId: guid
  22472. },
  22473. messagePayload: typeof speechActivityTemplate === undefined ? undefined : speechActivityTemplate,
  22474. version: 0.5
  22475. };
  22476. const agentContextJson = JSON.stringify(agentContext);
  22477. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, "speech.agent.context", this.privRequestSession.requestId, "application/json", agentContextJson));
  22478. }
  22479. fireEventForResult(serviceResult, properties) {
  22480. const resultReason = Exports_js_4.EnumTranslation.implTranslateRecognitionResult(serviceResult.RecognitionStatus);
  22481. const result = new Exports_js_3.SpeechRecognitionResult(this.privRequestSession.requestId, resultReason, serviceResult.DisplayText, serviceResult.Duration, serviceResult.Offset, serviceResult.Language, serviceResult.LanguageDetectionConfidence, undefined, undefined, serviceResult.asJson(), properties);
  22482. const ev = new Exports_js_3.SpeechRecognitionEventArgs(result, serviceResult.Offset, this.privRequestSession.sessionId);
  22483. return ev;
  22484. }
  22485. handleResponseMessage(responseMessage) {
  22486. // "response" messages can contain either "message" (activity) or "MessageStatus" data. Fire the appropriate
  22487. // event according to the message type that's specified.
  22488. const responsePayload = JSON.parse(responseMessage.textBody);
  22489. switch (responsePayload.messageType.toLowerCase()) {
  22490. case "message":
  22491. const responseRequestId = responseMessage.requestId.toUpperCase();
  22492. const activityPayload = ActivityResponsePayload_js_1.ActivityPayloadResponse.fromJSON(responseMessage.textBody);
  22493. const turn = this.privTurnStateManager.GetTurn(responseRequestId);
  22494. // update the conversation Id
  22495. if (activityPayload.conversationId) {
  22496. const updateAgentConfig = this.agentConfig.get();
  22497. updateAgentConfig.botInfo.conversationId = activityPayload.conversationId;
  22498. this.agentConfig.set(updateAgentConfig);
  22499. }
  22500. const pullAudioOutputStream = turn.processActivityPayload(activityPayload, AudioOutputFormat_js_1.AudioOutputFormatImpl.fromSpeechSynthesisOutputFormatString(this.privDialogServiceConnector.properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_SynthOutputFormat, undefined)));
  22501. const activity = new Exports_js_3.ActivityReceivedEventArgs(activityPayload.messagePayload, pullAudioOutputStream);
  22502. if (!!this.privDialogServiceConnector.activityReceived) {
  22503. try {
  22504. this.privDialogServiceConnector.activityReceived(this.privDialogServiceConnector, activity);
  22505. /* eslint-disable-next-line no-empty */
  22506. }
  22507. catch (error) {
  22508. // Not going to let errors in the event handler
  22509. // trip things up.
  22510. }
  22511. }
  22512. break;
  22513. case "messagestatus":
  22514. if (!!this.privDialogServiceConnector.turnStatusReceived) {
  22515. try {
  22516. this.privDialogServiceConnector.turnStatusReceived(this.privDialogServiceConnector, new Exports_js_3.TurnStatusReceivedEventArgs(responseMessage.textBody));
  22517. /* eslint-disable-next-line no-empty */
  22518. }
  22519. catch (error) {
  22520. // Not going to let errors in the event handler
  22521. // trip things up.
  22522. }
  22523. }
  22524. break;
  22525. default:
  22526. Exports_js_2.Events.instance.onEvent(new Exports_js_2.BackgroundEvent(`Unexpected response of type ${responsePayload.messageType}. Ignoring.`));
  22527. break;
  22528. }
  22529. }
  22530. onEvent(event) {
  22531. this.privEvents.onEvent(event);
  22532. Exports_js_2.Events.instance.onEvent(event);
  22533. }
  22534. addKeywordContextData() {
  22535. const keywordPropertyValue = this.privRecognizerConfig.parameters.getProperty("SPEECH-KeywordsToDetect");
  22536. if (keywordPropertyValue === undefined) {
  22537. return;
  22538. }
  22539. const keywordOffsetPropertyValue = this.privRecognizerConfig.parameters
  22540. .getProperty("SPEECH-KeywordsToDetect-Offsets");
  22541. const keywordDurationPropertyValue = this.privRecognizerConfig.parameters
  22542. .getProperty("SPEECH-KeywordsToDetect-Durations");
  22543. const keywords = keywordPropertyValue.split(";");
  22544. const keywordOffsets = keywordOffsetPropertyValue === undefined ? [] : keywordOffsetPropertyValue.split(";");
  22545. const keywordDurations = keywordDurationPropertyValue === undefined ? [] : keywordDurationPropertyValue.split(";");
  22546. const keywordDefinitionArray = [];
  22547. for (let i = 0; i < keywords.length; i++) {
  22548. const definition = {
  22549. text: keywords[i]
  22550. };
  22551. if (i < keywordOffsets.length) {
  22552. definition.startOffset = Number(keywordOffsets[i]);
  22553. }
  22554. if (i < keywordDurations.length) {
  22555. definition.duration = Number(keywordDurations[i]);
  22556. }
  22557. keywordDefinitionArray.push(definition);
  22558. }
  22559. this.speechContext.getContext().invocationSource = InvocationSource_js_1.InvocationSource.VoiceActivationWithKeyword;
  22560. this.speechContext.getContext().keywordDetection = [{
  22561. clientDetectedKeywords: keywordDefinitionArray,
  22562. onReject: { action: KeywordDetection_js_1.OnRejectAction.EndOfTurn },
  22563. type: KeywordDetection_js_1.KeywordDetectionType.StartTrigger
  22564. }];
  22565. }
  22566. }
  22567. exports.DialogServiceAdapter = DialogServiceAdapter;
  22568. /***/ }),
  22569. /* 251 */
  22570. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22571. "use strict";
  22572. // Copyright (c) Microsoft Corporation. All rights reserved.
  22573. // Licensed under the MIT license.
  22574. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22575. exports.DialogServiceTurnStateManager = void 0;
  22576. const Error_js_1 = __webpack_require__(26);
  22577. const DialogServiceTurnState_js_1 = __webpack_require__(252);
  22578. class DialogServiceTurnStateManager {
  22579. constructor() {
  22580. this.privTurnMap = new Map();
  22581. return;
  22582. }
  22583. StartTurn(id) {
  22584. if (this.privTurnMap.has(id)) {
  22585. throw new Error_js_1.InvalidOperationError("Service error: There is already a turn with id:" + id);
  22586. }
  22587. const turnState = new DialogServiceTurnState_js_1.DialogServiceTurnState(this, id);
  22588. this.privTurnMap.set(id, turnState);
  22589. return this.privTurnMap.get(id);
  22590. }
  22591. GetTurn(id) {
  22592. return this.privTurnMap.get(id);
  22593. }
  22594. CompleteTurn(id) {
  22595. if (!this.privTurnMap.has(id)) {
  22596. throw new Error_js_1.InvalidOperationError("Service error: Received turn end for an unknown turn id:" + id);
  22597. }
  22598. const turnState = this.privTurnMap.get(id);
  22599. turnState.complete();
  22600. this.privTurnMap.delete(id);
  22601. return turnState;
  22602. }
  22603. }
  22604. exports.DialogServiceTurnStateManager = DialogServiceTurnStateManager;
  22605. /***/ }),
  22606. /* 252 */
  22607. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22608. "use strict";
  22609. // Copyright (c) Microsoft Corporation. All rights reserved.
  22610. // Licensed under the MIT license.
  22611. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22612. exports.DialogServiceTurnState = void 0;
  22613. const AudioOutputFormat_js_1 = __webpack_require__(85);
  22614. const AudioOutputStream_js_1 = __webpack_require__(84);
  22615. const ActivityResponsePayload_js_1 = __webpack_require__(253);
  22616. class DialogServiceTurnState {
  22617. constructor(manager, requestId) {
  22618. this.privRequestId = requestId;
  22619. this.privIsCompleted = false;
  22620. this.privAudioStream = null;
  22621. this.privTurnManager = manager;
  22622. this.resetTurnEndTimeout();
  22623. }
  22624. get audioStream() {
  22625. // Called when is needed to stream.
  22626. this.resetTurnEndTimeout();
  22627. return this.privAudioStream;
  22628. }
  22629. processActivityPayload(payload, audioFormat) {
  22630. if (payload.messageDataStreamType === ActivityResponsePayload_js_1.MessageDataStreamType.TextToSpeechAudio) {
  22631. this.privAudioStream = AudioOutputStream_js_1.AudioOutputStream.createPullStream();
  22632. this.privAudioStream.format = (audioFormat !== undefined) ? audioFormat : AudioOutputFormat_js_1.AudioOutputFormatImpl.getDefaultOutputFormat();
  22633. }
  22634. return this.privAudioStream;
  22635. }
  22636. endAudioStream() {
  22637. if (this.privAudioStream !== null && !this.privAudioStream.isClosed) {
  22638. this.privAudioStream.close();
  22639. }
  22640. }
  22641. complete() {
  22642. if (this.privTimeoutToken !== undefined) {
  22643. // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  22644. clearTimeout(this.privTimeoutToken);
  22645. }
  22646. this.endAudioStream();
  22647. }
  22648. resetTurnEndTimeout() {
  22649. if (this.privTimeoutToken !== undefined) {
  22650. // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  22651. clearTimeout(this.privTimeoutToken);
  22652. }
  22653. this.privTimeoutToken = setTimeout(() => {
  22654. this.privTurnManager.CompleteTurn(this.privRequestId);
  22655. return;
  22656. }, 2000);
  22657. }
  22658. }
  22659. exports.DialogServiceTurnState = DialogServiceTurnState;
  22660. /***/ }),
  22661. /* 253 */
  22662. /***/ ((__unused_webpack_module, exports) => {
  22663. "use strict";
  22664. // Copyright (c) Microsoft Corporation. All rights reserved.
  22665. // Licensed under the MIT license.
  22666. // response
  22667. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22668. exports.MessageDataStreamType = exports.ActivityPayloadResponse = void 0;
  22669. class ActivityPayloadResponse {
  22670. constructor(json) {
  22671. this.privActivityResponse = JSON.parse(json);
  22672. }
  22673. static fromJSON(json) {
  22674. return new ActivityPayloadResponse(json);
  22675. }
  22676. get conversationId() {
  22677. return this.privActivityResponse.conversationId;
  22678. }
  22679. get messageDataStreamType() {
  22680. return this.privActivityResponse.messageDataStreamType;
  22681. }
  22682. get messagePayload() {
  22683. return this.privActivityResponse.messagePayload;
  22684. }
  22685. get version() {
  22686. return this.privActivityResponse.version;
  22687. }
  22688. }
  22689. exports.ActivityPayloadResponse = ActivityPayloadResponse;
  22690. var MessageDataStreamType;
  22691. (function (MessageDataStreamType) {
  22692. MessageDataStreamType[MessageDataStreamType["None"] = 0] = "None";
  22693. MessageDataStreamType[MessageDataStreamType["TextToSpeechAudio"] = 1] = "TextToSpeechAudio";
  22694. })(MessageDataStreamType = exports.MessageDataStreamType || (exports.MessageDataStreamType = {}));
  22695. /***/ }),
  22696. /* 254 */
  22697. /***/ ((__unused_webpack_module, exports) => {
  22698. "use strict";
  22699. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22700. exports.InvocationSource = void 0;
  22701. /**
  22702. * Represents the source of speech recognition invocation.
  22703. */
  22704. var InvocationSource;
  22705. (function (InvocationSource) {
  22706. /**
  22707. * No invocation source specified.
  22708. */
  22709. InvocationSource["None"] = "None";
  22710. /**
  22711. * Voice activation with a keyword.
  22712. */
  22713. InvocationSource["VoiceActivationWithKeyword"] = "VoiceActivationWithKeyword";
  22714. })(InvocationSource = exports.InvocationSource || (exports.InvocationSource = {}));
  22715. /***/ }),
  22716. /* 255 */
  22717. /***/ ((__unused_webpack_module, exports) => {
  22718. "use strict";
  22719. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22720. exports.OnRejectAction = exports.KeywordDetectionType = void 0;
  22721. /**
  22722. * Represents the type of keyword detection.
  22723. */
  22724. var KeywordDetectionType;
  22725. (function (KeywordDetectionType) {
  22726. /**
  22727. * Triggered at the start of input.
  22728. */
  22729. KeywordDetectionType["StartTrigger"] = "StartTrigger";
  22730. })(KeywordDetectionType = exports.KeywordDetectionType || (exports.KeywordDetectionType = {}));
  22731. /**
  22732. * The action to take when a keyword is rejected.
  22733. */
  22734. var OnRejectAction;
  22735. (function (OnRejectAction) {
  22736. /**
  22737. * End the current turn.
  22738. */
  22739. OnRejectAction["EndOfTurn"] = "EndOfTurn";
  22740. /**
  22741. * Continue processing.
  22742. */
  22743. OnRejectAction["Continue"] = "Continue";
  22744. })(OnRejectAction = exports.OnRejectAction || (exports.OnRejectAction = {}));
  22745. /***/ }),
  22746. /* 256 */
  22747. /***/ ((__unused_webpack_module, exports) => {
  22748. "use strict";
  22749. // Copyright (c) Microsoft Corporation. All rights reserved.
  22750. // Licensed under the MIT license.
  22751. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22752. exports.AgentConfig = void 0;
  22753. /**
  22754. * Represents the JSON used in the agent.config message sent to the speech service.
  22755. */
  22756. class AgentConfig {
  22757. toJsonString() {
  22758. return JSON.stringify(this.iPrivConfig);
  22759. }
  22760. get() {
  22761. return this.iPrivConfig;
  22762. }
  22763. /**
  22764. * Setter for the agent.config object.
  22765. * @param value a JSON serializable object.
  22766. */
  22767. set(value) {
  22768. this.iPrivConfig = value;
  22769. }
  22770. }
  22771. exports.AgentConfig = AgentConfig;
  22772. /***/ }),
  22773. /* 257 */
  22774. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22775. "use strict";
  22776. // Copyright (c) Microsoft Corporation. All rights reserved.
  22777. // Licensed under the MIT license.
  22778. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22779. exports.InternalParticipants = exports.ConversationTranslatorMessageTypes = exports.ConversationTranslatorCommandTypes = exports.ParticipantsListEventArgs = exports.ParticipantEventArgs = exports.ParticipantAttributeEventArgs = exports.MuteAllEventArgs = exports.LockRoomEventArgs = exports.ConversationReceivedTranslationEventArgs = exports.TranscriberRecognizer = exports.ConversationRecognizerFactory = exports.ConversationConnectionConfig = exports.ConversationManager = void 0;
  22780. var ConversationManager_js_1 = __webpack_require__(258);
  22781. Object.defineProperty(exports, "ConversationManager", ({ enumerable: true, get: function () { return ConversationManager_js_1.ConversationManager; } }));
  22782. var ConversationConnectionConfig_js_1 = __webpack_require__(259);
  22783. Object.defineProperty(exports, "ConversationConnectionConfig", ({ enumerable: true, get: function () { return ConversationConnectionConfig_js_1.ConversationConnectionConfig; } }));
  22784. var ConversationTranslatorRecognizer_js_1 = __webpack_require__(260);
  22785. Object.defineProperty(exports, "ConversationRecognizerFactory", ({ enumerable: true, get: function () { return ConversationTranslatorRecognizer_js_1.ConversationRecognizerFactory; } }));
  22786. var TranscriberRecognizer_js_1 = __webpack_require__(272);
  22787. Object.defineProperty(exports, "TranscriberRecognizer", ({ enumerable: true, get: function () { return TranscriberRecognizer_js_1.TranscriberRecognizer; } }));
  22788. var ConversationTranslatorEventArgs_js_1 = __webpack_require__(266);
  22789. Object.defineProperty(exports, "ConversationReceivedTranslationEventArgs", ({ enumerable: true, get: function () { return ConversationTranslatorEventArgs_js_1.ConversationReceivedTranslationEventArgs; } }));
  22790. Object.defineProperty(exports, "LockRoomEventArgs", ({ enumerable: true, get: function () { return ConversationTranslatorEventArgs_js_1.LockRoomEventArgs; } }));
  22791. Object.defineProperty(exports, "MuteAllEventArgs", ({ enumerable: true, get: function () { return ConversationTranslatorEventArgs_js_1.MuteAllEventArgs; } }));
  22792. Object.defineProperty(exports, "ParticipantAttributeEventArgs", ({ enumerable: true, get: function () { return ConversationTranslatorEventArgs_js_1.ParticipantAttributeEventArgs; } }));
  22793. Object.defineProperty(exports, "ParticipantEventArgs", ({ enumerable: true, get: function () { return ConversationTranslatorEventArgs_js_1.ParticipantEventArgs; } }));
  22794. Object.defineProperty(exports, "ParticipantsListEventArgs", ({ enumerable: true, get: function () { return ConversationTranslatorEventArgs_js_1.ParticipantsListEventArgs; } }));
  22795. var ConversationTranslatorInterfaces_js_1 = __webpack_require__(267);
  22796. Object.defineProperty(exports, "ConversationTranslatorCommandTypes", ({ enumerable: true, get: function () { return ConversationTranslatorInterfaces_js_1.ConversationTranslatorCommandTypes; } }));
  22797. Object.defineProperty(exports, "ConversationTranslatorMessageTypes", ({ enumerable: true, get: function () { return ConversationTranslatorInterfaces_js_1.ConversationTranslatorMessageTypes; } }));
  22798. Object.defineProperty(exports, "InternalParticipants", ({ enumerable: true, get: function () { return ConversationTranslatorInterfaces_js_1.InternalParticipants; } }));
  22799. /***/ }),
  22800. /* 258 */
  22801. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22802. "use strict";
  22803. // Copyright (c) Microsoft Corporation. All rights reserved.
  22804. // Licensed under the MIT license.
  22805. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22806. exports.ConversationManager = void 0;
  22807. const Exports_js_1 = __webpack_require__(60);
  22808. const Contracts_js_1 = __webpack_require__(64);
  22809. const Exports_js_2 = __webpack_require__(79);
  22810. const ConversationConnectionConfig_js_1 = __webpack_require__(259);
  22811. class ConversationManager {
  22812. constructor() {
  22813. //
  22814. this.privRequestParams = ConversationConnectionConfig_js_1.ConversationConnectionConfig.configParams;
  22815. this.privErrors = ConversationConnectionConfig_js_1.ConversationConnectionConfig.restErrors;
  22816. this.privHost = ConversationConnectionConfig_js_1.ConversationConnectionConfig.host;
  22817. this.privApiVersion = ConversationConnectionConfig_js_1.ConversationConnectionConfig.apiVersion;
  22818. this.privRestPath = ConversationConnectionConfig_js_1.ConversationConnectionConfig.restPath;
  22819. this.privRestAdapter = new Exports_js_1.RestMessageAdapter({});
  22820. }
  22821. /**
  22822. * Make a POST request to the Conversation Manager service endpoint to create or join a conversation.
  22823. * @param args
  22824. * @param conversationCode
  22825. * @param callback
  22826. * @param errorCallback
  22827. */
  22828. createOrJoin(args, conversationCode, cb, err) {
  22829. try {
  22830. Contracts_js_1.Contracts.throwIfNullOrUndefined(args, "args");
  22831. const languageCode = args.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage, ConversationConnectionConfig_js_1.ConversationConnectionConfig.defaultLanguageCode);
  22832. const nickname = args.getProperty(Exports_js_2.PropertyId.ConversationTranslator_Name, "conversation_host");
  22833. const endpointHost = args.getProperty(Exports_js_2.PropertyId.ConversationTranslator_Host, this.privHost);
  22834. const correlationId = args.getProperty(Exports_js_2.PropertyId.ConversationTranslator_CorrelationId);
  22835. const subscriptionKey = args.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Key);
  22836. const subscriptionRegion = args.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region);
  22837. const authToken = args.getProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token);
  22838. Contracts_js_1.Contracts.throwIfNullOrWhitespace(languageCode, "languageCode");
  22839. Contracts_js_1.Contracts.throwIfNullOrWhitespace(nickname, "nickname");
  22840. Contracts_js_1.Contracts.throwIfNullOrWhitespace(endpointHost, "endpointHost");
  22841. const queryParams = {};
  22842. queryParams[this.privRequestParams.apiVersion] = this.privApiVersion;
  22843. queryParams[this.privRequestParams.languageCode] = languageCode;
  22844. queryParams[this.privRequestParams.nickname] = nickname;
  22845. const headers = {};
  22846. if (correlationId) {
  22847. headers[this.privRequestParams.correlationId] = correlationId;
  22848. }
  22849. headers[this.privRequestParams.clientAppId] = ConversationConnectionConfig_js_1.ConversationConnectionConfig.clientAppId;
  22850. if (conversationCode !== undefined) {
  22851. queryParams[this.privRequestParams.roomId] = conversationCode;
  22852. }
  22853. else {
  22854. Contracts_js_1.Contracts.throwIfNullOrUndefined(subscriptionRegion, this.privErrors.authInvalidSubscriptionRegion);
  22855. headers[this.privRequestParams.subscriptionRegion] = subscriptionRegion;
  22856. if (subscriptionKey) {
  22857. headers[this.privRequestParams.subscriptionKey] = subscriptionKey;
  22858. }
  22859. else if (authToken) {
  22860. headers[this.privRequestParams.authorization] = `Bearer ${authToken}`;
  22861. }
  22862. else {
  22863. Contracts_js_1.Contracts.throwIfNullOrUndefined(subscriptionKey, this.privErrors.authInvalidSubscriptionKey);
  22864. }
  22865. }
  22866. const config = {};
  22867. config.headers = headers;
  22868. this.privRestAdapter.options = config;
  22869. const endpoint = `https://${endpointHost}${this.privRestPath}`;
  22870. // TODO: support a proxy and certificate validation
  22871. this.privRestAdapter.request(Exports_js_1.RestRequestType.Post, endpoint, queryParams, null).then((response) => {
  22872. const requestId = Exports_js_1.RestMessageAdapter.extractHeaderValue(this.privRequestParams.requestId, response.headers);
  22873. if (!response.ok) {
  22874. if (!!err) {
  22875. // get the error
  22876. let errorMessage = this.privErrors.invalidCreateJoinConversationResponse.replace("{status}", response.status.toString());
  22877. let errMessageRaw;
  22878. try {
  22879. errMessageRaw = JSON.parse(response.data);
  22880. errorMessage += ` [${errMessageRaw.error.code}: ${errMessageRaw.error.message}]`;
  22881. }
  22882. catch (e) {
  22883. errorMessage += ` [${response.data}]`;
  22884. }
  22885. if (requestId) {
  22886. errorMessage += ` ${requestId}`;
  22887. }
  22888. err(errorMessage);
  22889. }
  22890. return;
  22891. }
  22892. const conversation = JSON.parse(response.data);
  22893. if (conversation) {
  22894. conversation.requestId = requestId;
  22895. }
  22896. if (!!cb) {
  22897. try {
  22898. cb(conversation);
  22899. }
  22900. catch (e) {
  22901. if (!!err) {
  22902. err(e);
  22903. }
  22904. }
  22905. cb = undefined;
  22906. }
  22907. // eslint-disable-next-line @typescript-eslint/no-empty-function
  22908. }).catch(() => { });
  22909. }
  22910. catch (error) {
  22911. if (!!err) {
  22912. if (error instanceof Error) {
  22913. const typedError = error;
  22914. err(typedError.name + ": " + typedError.message);
  22915. }
  22916. else {
  22917. err(error);
  22918. }
  22919. }
  22920. }
  22921. }
  22922. /**
  22923. * Make a DELETE request to the Conversation Manager service endpoint to leave the conversation.
  22924. * @param args
  22925. * @param sessionToken
  22926. * @param callback
  22927. */
  22928. leave(args, sessionToken) {
  22929. return new Promise((resolve, reject) => {
  22930. try {
  22931. Contracts_js_1.Contracts.throwIfNullOrUndefined(args, this.privErrors.invalidArgs.replace("{arg}", "config"));
  22932. Contracts_js_1.Contracts.throwIfNullOrWhitespace(sessionToken, this.privErrors.invalidArgs.replace("{arg}", "token"));
  22933. const endpointHost = args.getProperty(Exports_js_2.PropertyId.ConversationTranslator_Host, this.privHost);
  22934. const correlationId = args.getProperty(Exports_js_2.PropertyId.ConversationTranslator_CorrelationId);
  22935. const queryParams = {};
  22936. queryParams[this.privRequestParams.apiVersion] = this.privApiVersion;
  22937. queryParams[this.privRequestParams.sessionToken] = sessionToken;
  22938. const headers = {};
  22939. if (correlationId) {
  22940. headers[this.privRequestParams.correlationId] = correlationId;
  22941. }
  22942. const config = {};
  22943. config.headers = headers;
  22944. this.privRestAdapter.options = config;
  22945. const endpoint = `https://${endpointHost}${this.privRestPath}`;
  22946. // TODO: support a proxy and certificate validation
  22947. this.privRestAdapter.request(Exports_js_1.RestRequestType.Delete, endpoint, queryParams, null).then((response) => {
  22948. if (!response.ok) {
  22949. // ignore errors on delete
  22950. }
  22951. resolve();
  22952. // eslint-disable-next-line @typescript-eslint/no-empty-function
  22953. }).catch(() => { });
  22954. }
  22955. catch (error) {
  22956. if (error instanceof Error) {
  22957. const typedError = error;
  22958. reject(typedError.name + ": " + typedError.message);
  22959. }
  22960. else {
  22961. reject(error);
  22962. }
  22963. }
  22964. });
  22965. }
  22966. }
  22967. exports.ConversationManager = ConversationManager;
  22968. /***/ }),
  22969. /* 259 */
  22970. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22971. "use strict";
  22972. // Copyright (c) Microsoft Corporation. All rights reserved.
  22973. // Licensed under the MIT license.
  22974. Object.defineProperty(exports, "__esModule", ({ value: true }));
  22975. exports.ConversationConnectionConfig = void 0;
  22976. const RestConfigBase_js_1 = __webpack_require__(203);
  22977. class ConversationConnectionConfig extends RestConfigBase_js_1.RestConfigBase {
  22978. static get host() {
  22979. return ConversationConnectionConfig.privHost;
  22980. }
  22981. static get apiVersion() {
  22982. return ConversationConnectionConfig.privApiVersion;
  22983. }
  22984. static get clientAppId() {
  22985. return ConversationConnectionConfig.privClientAppId;
  22986. }
  22987. static get defaultLanguageCode() {
  22988. return ConversationConnectionConfig.privDefaultLanguageCode;
  22989. }
  22990. static get restPath() {
  22991. return ConversationConnectionConfig.privRestPath;
  22992. }
  22993. static get webSocketPath() {
  22994. return ConversationConnectionConfig.privWebSocketPath;
  22995. }
  22996. static get transcriptionEventKeys() {
  22997. return ConversationConnectionConfig.privTranscriptionEventKeys;
  22998. }
  22999. }
  23000. exports.ConversationConnectionConfig = ConversationConnectionConfig;
  23001. ConversationConnectionConfig.privHost = "dev.microsofttranslator.com";
  23002. ConversationConnectionConfig.privRestPath = "/capito/room";
  23003. ConversationConnectionConfig.privApiVersion = "2.0";
  23004. ConversationConnectionConfig.privDefaultLanguageCode = "en-US";
  23005. ConversationConnectionConfig.privClientAppId = "FC539C22-1767-4F1F-84BC-B4D811114F15";
  23006. ConversationConnectionConfig.privWebSocketPath = "/capito/translate";
  23007. ConversationConnectionConfig.privTranscriptionEventKeys = ["iCalUid", "callId", "organizer", "FLAC", "MTUri", "DifferentiateGuestSpeakers", "audiorecording", "Threadid", "OrganizerMri", "OrganizerTenantId", "UserToken"];
  23008. /***/ }),
  23009. /* 260 */
  23010. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  23011. "use strict";
  23012. // Copyright (c) Microsoft Corporation. All rights reserved.
  23013. // Licensed under the MIT license.
  23014. Object.defineProperty(exports, "__esModule", ({ value: true }));
  23015. exports.ConversationTranslatorRecognizer = exports.ConversationRecognizerFactory = void 0;
  23016. // eslint-disable-next-line max-classes-per-file
  23017. const Exports_js_1 = __webpack_require__(2);
  23018. const Exports_js_2 = __webpack_require__(4);
  23019. const Contracts_js_1 = __webpack_require__(64);
  23020. const Exports_js_3 = __webpack_require__(79);
  23021. const ConversationConnectionFactory_js_1 = __webpack_require__(261);
  23022. const ConversationServiceAdapter_js_1 = __webpack_require__(264);
  23023. class ConversationRecognizerFactory {
  23024. static fromConfig(conversation, speechConfig, audioConfig) {
  23025. return new ConversationTranslatorRecognizer(conversation, speechConfig, audioConfig);
  23026. }
  23027. }
  23028. exports.ConversationRecognizerFactory = ConversationRecognizerFactory;
  23029. /**
  23030. * Sends messages to the Conversation Translator websocket and listens for incoming events containing websocket messages.
  23031. * Based off the recognizers in the SDK folder.
  23032. */
  23033. class ConversationTranslatorRecognizer extends Exports_js_3.Recognizer {
  23034. constructor(conversation, speechConfig, audioConfig) {
  23035. const serviceConfigImpl = speechConfig;
  23036. Contracts_js_1.Contracts.throwIfNull(serviceConfigImpl, "speechConfig");
  23037. const conversationImpl = conversation;
  23038. Contracts_js_1.Contracts.throwIfNull(conversationImpl, "conversationImpl");
  23039. super(audioConfig, serviceConfigImpl.properties, new ConversationConnectionFactory_js_1.ConversationConnectionFactory());
  23040. this.privConversation = conversationImpl;
  23041. this.privIsDisposed = false;
  23042. this.privProperties = serviceConfigImpl.properties.clone();
  23043. this.privConnection = Exports_js_3.Connection.fromRecognizer(this);
  23044. const webWorkerLoadType = this.privProperties.getProperty(Exports_js_3.PropertyId.WebWorkerLoadType, "on").toLowerCase();
  23045. if (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") {
  23046. this.privSetTimeout = Exports_js_2.Timeout.setTimeout;
  23047. this.privClearTimeout = Exports_js_2.Timeout.clearTimeout;
  23048. }
  23049. else {
  23050. if (typeof window !== "undefined") {
  23051. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  23052. this.privSetTimeout = window.setTimeout.bind(window);
  23053. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  23054. this.privClearTimeout = window.clearTimeout.bind(window);
  23055. }
  23056. else {
  23057. this.privSetTimeout = setTimeout;
  23058. this.privClearTimeout = clearTimeout;
  23059. }
  23060. }
  23061. }
  23062. set connected(cb) {
  23063. this.privConnection.connected = cb;
  23064. }
  23065. set disconnected(cb) {
  23066. this.privConnection.disconnected = cb;
  23067. }
  23068. /**
  23069. * Return the speech language used by the recognizer
  23070. */
  23071. get speechRecognitionLanguage() {
  23072. return this.privSpeechRecognitionLanguage;
  23073. }
  23074. /**
  23075. * Return the properties for the recognizer
  23076. */
  23077. get properties() {
  23078. return this.privProperties;
  23079. }
  23080. isDisposed() {
  23081. return this.privIsDisposed;
  23082. }
  23083. /**
  23084. * Connect to the recognizer
  23085. * @param token
  23086. */
  23087. connect(token, cb, err) {
  23088. try {
  23089. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  23090. Contracts_js_1.Contracts.throwIfNullOrWhitespace(token, "token");
  23091. this.privReco.conversationTranslatorToken = token;
  23092. this.resetConversationTimeout();
  23093. this.privReco.connectAsync(cb, err);
  23094. }
  23095. catch (error) {
  23096. if (!!err) {
  23097. if (error instanceof Error) {
  23098. const typedError = error;
  23099. err(typedError.name + ": " + typedError.message);
  23100. }
  23101. else {
  23102. err(error);
  23103. }
  23104. }
  23105. }
  23106. }
  23107. /**
  23108. * Disconnect from the recognizer
  23109. */
  23110. disconnect(cb, err) {
  23111. try {
  23112. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  23113. if (this.privTimeoutToken !== undefined) {
  23114. // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  23115. this.privClearTimeout(this.privTimeoutToken);
  23116. }
  23117. this.privReco.disconnect().then(() => {
  23118. if (!!cb) {
  23119. cb();
  23120. }
  23121. }, (error) => {
  23122. if (!!err) {
  23123. err(error);
  23124. }
  23125. });
  23126. }
  23127. catch (error) {
  23128. if (!!err) {
  23129. if (error instanceof Error) {
  23130. const typedError = error;
  23131. err(typedError.name + ": " + typedError.message);
  23132. }
  23133. else {
  23134. err(error);
  23135. }
  23136. }
  23137. // Destroy the recognizer.
  23138. this.dispose(true).catch((reason) => {
  23139. Exports_js_2.Events.instance.onEvent(new Exports_js_2.BackgroundEvent(reason));
  23140. });
  23141. }
  23142. }
  23143. /**
  23144. * Send the mute all participants command to the websocket
  23145. * @param conversationId
  23146. * @param participantId
  23147. * @param isMuted
  23148. */
  23149. sendRequest(command, cb, err) {
  23150. try {
  23151. Contracts_js_1.Contracts.throwIfDisposed(this.privIsDisposed);
  23152. this.sendMessage(command, cb, err);
  23153. }
  23154. catch (error) {
  23155. if (!!err) {
  23156. if (error instanceof Error) {
  23157. const typedError = error;
  23158. err(typedError.name + ": " + typedError.message);
  23159. }
  23160. else {
  23161. err(error);
  23162. }
  23163. }
  23164. // Destroy the recognizer.
  23165. this.dispose(true).catch((reason) => {
  23166. Exports_js_2.Events.instance.onEvent(new Exports_js_2.BackgroundEvent(reason));
  23167. });
  23168. }
  23169. }
  23170. /**
  23171. * Handle update of service auth token (#694)
  23172. */
  23173. onToken(token) {
  23174. this.privConversation.onToken(token);
  23175. }
  23176. /**
  23177. * Close and dispose the recognizer
  23178. */
  23179. async close() {
  23180. if (!this.privIsDisposed) {
  23181. if (!!this.privConnection) {
  23182. this.privConnection.closeConnection();
  23183. this.privConnection.close();
  23184. }
  23185. this.privConnection = undefined;
  23186. await this.dispose(true);
  23187. }
  23188. }
  23189. /**
  23190. * Dispose the recognizer
  23191. * @param disposing
  23192. */
  23193. async dispose(disposing) {
  23194. if (this.privIsDisposed) {
  23195. return;
  23196. }
  23197. if (disposing) {
  23198. if (this.privTimeoutToken !== undefined) {
  23199. // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  23200. this.privClearTimeout(this.privTimeoutToken);
  23201. }
  23202. this.privIsDisposed = true;
  23203. if (!!this.privConnection) {
  23204. this.privConnection.closeConnection();
  23205. this.privConnection.close();
  23206. this.privConnection = undefined;
  23207. }
  23208. await super.dispose(disposing);
  23209. }
  23210. }
  23211. /**
  23212. * Create the config for the recognizer
  23213. * @param speechConfig
  23214. */
  23215. createRecognizerConfig(speechConfig) {
  23216. return new Exports_js_1.RecognizerConfig(speechConfig, this.privProperties);
  23217. }
  23218. /**
  23219. * Create the service recognizer.
  23220. * The audio source is redundnant here but is required by the implementation.
  23221. * @param authentication
  23222. * @param connectionFactory
  23223. * @param audioConfig
  23224. * @param recognizerConfig
  23225. */
  23226. createServiceRecognizer(authentication, connectionFactory, audioConfig, recognizerConfig) {
  23227. const audioSource = audioConfig;
  23228. return new ConversationServiceAdapter_js_1.ConversationServiceAdapter(authentication, connectionFactory, audioSource, recognizerConfig, this);
  23229. }
  23230. sendMessage(msg, cb, err) {
  23231. const withAsync = this.privReco;
  23232. const PromiseToEmptyCallback = (promise, cb, err) => {
  23233. if (promise !== undefined) {
  23234. promise.then(() => {
  23235. try {
  23236. if (!!cb) {
  23237. cb();
  23238. }
  23239. }
  23240. catch (e) {
  23241. if (!!err) {
  23242. err(`'Unhandled error on promise callback: ${e}'`);
  23243. }
  23244. }
  23245. }, (reason) => {
  23246. try {
  23247. if (!!err) {
  23248. err(reason);
  23249. }
  23250. // eslint-disable-next-line no-empty
  23251. }
  23252. catch (error) { }
  23253. });
  23254. }
  23255. else {
  23256. if (!!err) {
  23257. err("Null promise");
  23258. }
  23259. }
  23260. };
  23261. PromiseToEmptyCallback(withAsync.sendMessageAsync(msg), cb, err);
  23262. this.resetConversationTimeout();
  23263. }
  23264. resetConversationTimeout() {
  23265. if (this.privTimeoutToken !== undefined) {
  23266. // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  23267. this.privClearTimeout(this.privTimeoutToken);
  23268. }
  23269. this.privTimeoutToken = this.privSetTimeout(() => {
  23270. this.sendRequest(this.privConversation.getKeepAlive());
  23271. }, 60000);
  23272. }
  23273. }
  23274. exports.ConversationTranslatorRecognizer = ConversationTranslatorRecognizer;
  23275. /***/ }),
  23276. /* 261 */
  23277. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  23278. "use strict";
  23279. // Copyright (c) Microsoft Corporation. All rights reserved.
  23280. // Licensed under the MIT license.
  23281. Object.defineProperty(exports, "__esModule", ({ value: true }));
  23282. exports.ConversationConnectionFactory = void 0;
  23283. const Exports_js_1 = __webpack_require__(60);
  23284. const Exports_js_2 = __webpack_require__(4);
  23285. const Contracts_js_1 = __webpack_require__(64);
  23286. const Exports_js_3 = __webpack_require__(79);
  23287. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  23288. const ConversationConnectionConfig_js_1 = __webpack_require__(259);
  23289. const ConversationWebsocketMessageFormatter_js_1 = __webpack_require__(262);
  23290. /**
  23291. * Create a connection to the Conversation Translator websocket for sending instant messages and commands, and for receiving translated messages.
  23292. * The conversation must already have been started or joined.
  23293. */
  23294. class ConversationConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {
  23295. create(config, authInfo, connectionId) {
  23296. const endpointHost = config.parameters.getProperty(Exports_js_3.PropertyId.ConversationTranslator_Host, ConversationConnectionConfig_js_1.ConversationConnectionConfig.host);
  23297. const correlationId = config.parameters.getProperty(Exports_js_3.PropertyId.ConversationTranslator_CorrelationId, (0, Exports_js_2.createGuid)());
  23298. const endpoint = `wss://${endpointHost}${ConversationConnectionConfig_js_1.ConversationConnectionConfig.webSocketPath}`;
  23299. const token = config.parameters.getProperty(Exports_js_3.PropertyId.ConversationTranslator_Token, undefined);
  23300. Contracts_js_1.Contracts.throwIfNullOrUndefined(token, "token");
  23301. const queryParams = {};
  23302. queryParams[ConversationConnectionConfig_js_1.ConversationConnectionConfig.configParams.apiVersion] = ConversationConnectionConfig_js_1.ConversationConnectionConfig.apiVersion;
  23303. queryParams[ConversationConnectionConfig_js_1.ConversationConnectionConfig.configParams.token] = token;
  23304. queryParams[ConversationConnectionConfig_js_1.ConversationConnectionConfig.configParams.correlationId] = correlationId;
  23305. const enableCompression = config.parameters.getProperty("SPEECH-EnableWebsocketCompression", "false") === "true";
  23306. return Promise.resolve(new Exports_js_1.WebsocketConnection(endpoint, queryParams, {}, new ConversationWebsocketMessageFormatter_js_1.ConversationWebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId));
  23307. }
  23308. }
  23309. exports.ConversationConnectionFactory = ConversationConnectionFactory;
  23310. /***/ }),
  23311. /* 262 */
  23312. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  23313. "use strict";
  23314. // Copyright (c) Microsoft Corporation. All rights reserved.
  23315. // Licensed under the MIT license.
  23316. Object.defineProperty(exports, "__esModule", ({ value: true }));
  23317. exports.ConversationWebsocketMessageFormatter = void 0;
  23318. const Exports_js_1 = __webpack_require__(4);
  23319. const ConversationConnectionMessage_js_1 = __webpack_require__(263);
  23320. /**
  23321. * Based off WebsocketMessageFormatter. The messages for Conversation Translator have some variations from the Speech messages.
  23322. */
  23323. class ConversationWebsocketMessageFormatter {
  23324. /**
  23325. * Format incoming messages: text (speech partial/final, IM) or binary (tts)
  23326. */
  23327. toConnectionMessage(message) {
  23328. const deferral = new Exports_js_1.Deferred();
  23329. try {
  23330. if (message.messageType === Exports_js_1.MessageType.Text) {
  23331. const incomingMessage = new ConversationConnectionMessage_js_1.ConversationConnectionMessage(message.messageType, message.textContent, {}, message.id);
  23332. deferral.resolve(incomingMessage);
  23333. }
  23334. else if (message.messageType === Exports_js_1.MessageType.Binary) {
  23335. deferral.resolve(new ConversationConnectionMessage_js_1.ConversationConnectionMessage(message.messageType, message.binaryContent, undefined, message.id));
  23336. }
  23337. }
  23338. catch (e) {
  23339. deferral.reject(`Error formatting the message. Error: ${e}`);
  23340. }
  23341. return deferral.promise;
  23342. }
  23343. /**
  23344. * Format outgoing messages: text (commands or IM)
  23345. */
  23346. fromConnectionMessage(message) {
  23347. const deferral = new Exports_js_1.Deferred();
  23348. try {
  23349. if (message.messageType === Exports_js_1.MessageType.Text) {
  23350. const payload = `${message.textBody ? message.textBody : ""}`;
  23351. deferral.resolve(new Exports_js_1.RawWebsocketMessage(Exports_js_1.MessageType.Text, payload, message.id));
  23352. }
  23353. }
  23354. catch (e) {
  23355. deferral.reject(`Error formatting the message. ${e}`);
  23356. }
  23357. return deferral.promise;
  23358. }
  23359. }
  23360. exports.ConversationWebsocketMessageFormatter = ConversationWebsocketMessageFormatter;
  23361. /***/ }),
  23362. /* 263 */
  23363. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  23364. "use strict";
  23365. // Copyright (c) Microsoft Corporation. All rights reserved.
  23366. // Licensed under the MIT license.
  23367. Object.defineProperty(exports, "__esModule", ({ value: true }));
  23368. exports.ConversationConnectionMessage = void 0;
  23369. const Exports_js_1 = __webpack_require__(4);
  23370. class ConversationConnectionMessage extends Exports_js_1.ConnectionMessage {
  23371. constructor(messageType, body, headers, id) {
  23372. super(messageType, body, headers, id);
  23373. const json = JSON.parse(this.textBody);
  23374. if (json.type !== undefined) {
  23375. this.privConversationMessageType = json.type;
  23376. }
  23377. }
  23378. get conversationMessageType() {
  23379. return this.privConversationMessageType;
  23380. }
  23381. }
  23382. exports.ConversationConnectionMessage = ConversationConnectionMessage;
  23383. /***/ }),
  23384. /* 264 */
  23385. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  23386. "use strict";
  23387. // Copyright (c) Microsoft Corporation. All rights reserved.
  23388. // Licensed under the MIT license.
  23389. Object.defineProperty(exports, "__esModule", ({ value: true }));
  23390. exports.ConversationServiceAdapter = void 0;
  23391. const Exports_js_1 = __webpack_require__(4);
  23392. const Exports_js_2 = __webpack_require__(79);
  23393. const Exports_js_3 = __webpack_require__(2);
  23394. const ConversationConnectionMessage_js_1 = __webpack_require__(263);
  23395. const ConversationRequestSession_js_1 = __webpack_require__(265);
  23396. const ConversationTranslatorEventArgs_js_1 = __webpack_require__(266);
  23397. const ConversationTranslatorInterfaces_js_1 = __webpack_require__(267);
  23398. const Exports_js_4 = __webpack_require__(268);
  23399. /**
  23400. * The service adapter handles sending and receiving messages to the Conversation Translator websocket.
  23401. */
  23402. class ConversationServiceAdapter extends Exports_js_3.ServiceRecognizerBase {
  23403. constructor(authentication, connectionFactory, audioSource, recognizerConfig, conversationServiceConnector) {
  23404. super(authentication, connectionFactory, audioSource, recognizerConfig, conversationServiceConnector);
  23405. this.privConnectionConfigPromise = undefined;
  23406. this.privLastPartialUtteranceId = "";
  23407. this.privConversationServiceConnector = conversationServiceConnector;
  23408. this.privConversationAuthentication = authentication;
  23409. this.receiveMessageOverride = () => this.receiveConversationMessageOverride();
  23410. this.recognizeOverride = () => this.noOp();
  23411. this.postConnectImplOverride = (connection) => this.conversationConnectImpl(connection);
  23412. this.configConnectionOverride = () => this.configConnection();
  23413. this.disconnectOverride = () => this.privDisconnect();
  23414. this.privConversationRequestSession = new ConversationRequestSession_js_1.ConversationRequestSession((0, Exports_js_1.createNoDashGuid)());
  23415. this.privConversationConnectionFactory = connectionFactory;
  23416. this.privConversationIsDisposed = false;
  23417. }
  23418. isDisposed() {
  23419. return super.isDisposed() || this.privConversationIsDisposed;
  23420. }
  23421. async dispose(reason) {
  23422. this.privConversationIsDisposed = true;
  23423. if (this.privConnectionConfigPromise !== undefined) {
  23424. const connection = await this.privConnectionConfigPromise;
  23425. await connection.dispose(reason);
  23426. }
  23427. await super.dispose(reason);
  23428. }
  23429. async sendMessage(message) {
  23430. const connection = await this.fetchConnection();
  23431. return connection.send(new ConversationConnectionMessage_js_1.ConversationConnectionMessage(Exports_js_1.MessageType.Text, message));
  23432. }
  23433. async sendMessageAsync(message) {
  23434. const connection = await this.fetchConnection();
  23435. await connection.send(new ConversationConnectionMessage_js_1.ConversationConnectionMessage(Exports_js_1.MessageType.Text, message));
  23436. }
  23437. privDisconnect() {
  23438. if (this.terminateMessageLoop) {
  23439. return;
  23440. }
  23441. this.cancelRecognition(this.privConversationRequestSession.sessionId, this.privConversationRequestSession.requestId, Exports_js_2.CancellationReason.Error, Exports_js_2.CancellationErrorCode.NoError, "Disconnecting");
  23442. this.terminateMessageLoop = true;
  23443. return Promise.resolve();
  23444. }
  23445. // eslint-disable-next-line @typescript-eslint/require-await
  23446. async processTypeSpecificMessages() {
  23447. return true;
  23448. }
  23449. // Cancels recognition.
  23450. cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  23451. this.terminateMessageLoop = true;
  23452. const cancelEvent = new Exports_js_2.ConversationTranslationCanceledEventArgs(cancellationReason, error, errorCode, undefined, sessionId);
  23453. try {
  23454. if (!!this.privConversationServiceConnector.canceled) {
  23455. this.privConversationServiceConnector.canceled(this.privConversationServiceConnector, cancelEvent);
  23456. }
  23457. }
  23458. catch {
  23459. // continue on error
  23460. }
  23461. }
  23462. /**
  23463. * Establishes a websocket connection to the end point.
  23464. */
  23465. async conversationConnectImpl(connection) {
  23466. this.privConnectionLoop = this.startMessageLoop();
  23467. return connection;
  23468. }
  23469. /**
  23470. * Process incoming websocket messages
  23471. */
  23472. async receiveConversationMessageOverride() {
  23473. if (this.isDisposed() || this.terminateMessageLoop) {
  23474. return Promise.resolve();
  23475. }
  23476. // we won't rely on the cascading promises of the connection since we want to continually be available to receive messages
  23477. const communicationCustodian = new Exports_js_1.Deferred();
  23478. try {
  23479. const connection = await this.fetchConnection();
  23480. const message = await connection.read();
  23481. if (this.isDisposed() || this.terminateMessageLoop) {
  23482. // We're done.
  23483. communicationCustodian.resolve();
  23484. return Promise.resolve();
  23485. }
  23486. if (!message) {
  23487. return this.receiveConversationMessageOverride();
  23488. }
  23489. const sessionId = this.privConversationRequestSession.sessionId;
  23490. const conversationMessageType = message.conversationMessageType.toLowerCase();
  23491. let sendFinal = false;
  23492. try {
  23493. switch (conversationMessageType) {
  23494. case "info":
  23495. case "participant_command":
  23496. case "command":
  23497. const commandPayload = Exports_js_4.CommandResponsePayload.fromJSON(message.textBody);
  23498. switch (commandPayload.command.toLowerCase()) {
  23499. /**
  23500. * 'ParticpantList' is the first message sent to the user after the websocket connection has opened.
  23501. * The consuming client must wait for this message to arrive
  23502. * before starting to send their own data.
  23503. */
  23504. case "participantlist":
  23505. const participantsPayload = Exports_js_4.ParticipantsListPayloadResponse.fromJSON(message.textBody);
  23506. const participantsResult = participantsPayload.participants.map((p) => {
  23507. const participant = {
  23508. avatar: p.avatar,
  23509. displayName: p.nickname,
  23510. id: p.participantId,
  23511. isHost: p.ishost,
  23512. isMuted: p.ismuted,
  23513. isUsingTts: p.usetts,
  23514. preferredLanguage: p.locale
  23515. };
  23516. return participant;
  23517. });
  23518. if (!!this.privConversationServiceConnector.participantsListReceived) {
  23519. this.privConversationServiceConnector.participantsListReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ParticipantsListEventArgs(participantsPayload.roomid, participantsPayload.token, participantsPayload.translateTo, participantsPayload.profanityFilter, participantsPayload.roomProfanityFilter, participantsPayload.roomLocked, participantsPayload.muteAll, participantsResult, sessionId));
  23520. }
  23521. break;
  23522. /**
  23523. * 'SetTranslateToLanguages' represents the list of languages being used in the Conversation by all users(?).
  23524. * This is sent at the start of the Conversation
  23525. */
  23526. case "settranslatetolanguages":
  23527. if (!!this.privConversationServiceConnector.participantUpdateCommandReceived) {
  23528. this.privConversationServiceConnector.participantUpdateCommandReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ParticipantAttributeEventArgs(commandPayload.participantId, ConversationTranslatorInterfaces_js_1.ConversationTranslatorCommandTypes.setTranslateToLanguages, commandPayload.value, sessionId));
  23529. }
  23530. break;
  23531. /**
  23532. * 'SetProfanityFiltering' lets the client set the level of profanity filtering.
  23533. * If sent by the participant the setting will effect only their own profanity level.
  23534. * If sent by the host, the setting will effect all participants including the host.
  23535. * Note: the profanity filters differ from Speech Service (?): 'marked', 'raw', 'removed', 'tagged'
  23536. */
  23537. case "setprofanityfiltering":
  23538. if (!!this.privConversationServiceConnector.participantUpdateCommandReceived) {
  23539. this.privConversationServiceConnector.participantUpdateCommandReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ParticipantAttributeEventArgs(commandPayload.participantId, ConversationTranslatorInterfaces_js_1.ConversationTranslatorCommandTypes.setProfanityFiltering, commandPayload.value, sessionId));
  23540. }
  23541. break;
  23542. /**
  23543. * 'SetMute' is sent if the participant has been muted by the host.
  23544. * Check the 'participantId' to determine if the current user has been muted.
  23545. */
  23546. case "setmute":
  23547. if (!!this.privConversationServiceConnector.participantUpdateCommandReceived) {
  23548. this.privConversationServiceConnector.participantUpdateCommandReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ParticipantAttributeEventArgs(commandPayload.participantId, ConversationTranslatorInterfaces_js_1.ConversationTranslatorCommandTypes.setMute, commandPayload.value, sessionId));
  23549. }
  23550. break;
  23551. /**
  23552. * 'SetMuteAll' is sent if the Conversation has been muted by the host.
  23553. */
  23554. case "setmuteall":
  23555. if (!!this.privConversationServiceConnector.muteAllCommandReceived) {
  23556. this.privConversationServiceConnector.muteAllCommandReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.MuteAllEventArgs(commandPayload.value, sessionId));
  23557. }
  23558. break;
  23559. /**
  23560. * 'RoomExpirationWarning' is sent towards the end of the Conversation session to give a timeout warning.
  23561. */
  23562. case "roomexpirationwarning":
  23563. if (!!this.privConversationServiceConnector.conversationExpiration) {
  23564. this.privConversationServiceConnector.conversationExpiration(this.privConversationServiceConnector, new Exports_js_2.ConversationExpirationEventArgs(commandPayload.value, this.privConversationRequestSession.sessionId));
  23565. }
  23566. break;
  23567. /**
  23568. * 'SetUseTts' is sent as a confirmation if the user requests TTS to be turned on or off.
  23569. */
  23570. case "setusetts":
  23571. if (!!this.privConversationServiceConnector.participantUpdateCommandReceived) {
  23572. this.privConversationServiceConnector.participantUpdateCommandReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ParticipantAttributeEventArgs(commandPayload.participantId, ConversationTranslatorInterfaces_js_1.ConversationTranslatorCommandTypes.setUseTTS, commandPayload.value, sessionId));
  23573. }
  23574. break;
  23575. /**
  23576. * 'SetLockState' is set if the host has locked or unlocked the Conversation.
  23577. */
  23578. case "setlockstate":
  23579. if (!!this.privConversationServiceConnector.lockRoomCommandReceived) {
  23580. this.privConversationServiceConnector.lockRoomCommandReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.LockRoomEventArgs(commandPayload.value, sessionId));
  23581. }
  23582. break;
  23583. /**
  23584. * 'ChangeNickname' is received if a user changes their display name.
  23585. * Any cached particpiants list should be updated to reflect the display name.
  23586. */
  23587. case "changenickname":
  23588. if (!!this.privConversationServiceConnector.participantUpdateCommandReceived) {
  23589. this.privConversationServiceConnector.participantUpdateCommandReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ParticipantAttributeEventArgs(commandPayload.participantId, ConversationTranslatorInterfaces_js_1.ConversationTranslatorCommandTypes.changeNickname, commandPayload.value, sessionId));
  23590. }
  23591. break;
  23592. /**
  23593. * 'JoinSession' is sent when a user joins the Conversation.
  23594. */
  23595. case "joinsession":
  23596. const joinParticipantPayload = Exports_js_4.ParticipantPayloadResponse.fromJSON(message.textBody);
  23597. const joiningParticipant = {
  23598. avatar: joinParticipantPayload.avatar,
  23599. displayName: joinParticipantPayload.nickname,
  23600. id: joinParticipantPayload.participantId,
  23601. isHost: joinParticipantPayload.ishost,
  23602. isMuted: joinParticipantPayload.ismuted,
  23603. isUsingTts: joinParticipantPayload.usetts,
  23604. preferredLanguage: joinParticipantPayload.locale,
  23605. };
  23606. if (!!this.privConversationServiceConnector.participantJoinCommandReceived) {
  23607. this.privConversationServiceConnector.participantJoinCommandReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ParticipantEventArgs(joiningParticipant, sessionId));
  23608. }
  23609. break;
  23610. /**
  23611. * 'LeaveSession' is sent when a user leaves the Conversation'.
  23612. */
  23613. case "leavesession":
  23614. const leavingParticipant = {
  23615. id: commandPayload.participantId
  23616. };
  23617. if (!!this.privConversationServiceConnector.participantLeaveCommandReceived) {
  23618. this.privConversationServiceConnector.participantLeaveCommandReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ParticipantEventArgs(leavingParticipant, sessionId));
  23619. }
  23620. break;
  23621. /**
  23622. * 'DisconnectSession' is sent when a user is disconnected from the session (e.g. network problem).
  23623. * Check the 'ParticipantId' to check whether the message is for the current user.
  23624. */
  23625. case "disconnectsession":
  23626. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  23627. const disconnectParticipant = {
  23628. id: commandPayload.participantId
  23629. };
  23630. break;
  23631. case "token":
  23632. const token = new Exports_js_3.CognitiveTokenAuthentication(() => {
  23633. const authorizationToken = commandPayload.token;
  23634. return Promise.resolve(authorizationToken);
  23635. }, () => {
  23636. const authorizationToken = commandPayload.token;
  23637. return Promise.resolve(authorizationToken);
  23638. });
  23639. this.authentication = token;
  23640. this.privConversationServiceConnector.onToken(token);
  23641. break;
  23642. /**
  23643. * Message not recognized.
  23644. */
  23645. default:
  23646. break;
  23647. }
  23648. break;
  23649. /**
  23650. * 'partial' (or 'hypothesis') represents a unfinalized speech message.
  23651. */
  23652. case "partial":
  23653. /**
  23654. * 'final' (or 'phrase') represents a finalized speech message.
  23655. */
  23656. case "final":
  23657. const speechPayload = Exports_js_4.SpeechResponsePayload.fromJSON(message.textBody);
  23658. const conversationResultReason = (conversationMessageType === "final") ? Exports_js_2.ResultReason.TranslatedParticipantSpeech : Exports_js_2.ResultReason.TranslatingParticipantSpeech;
  23659. const speechResult = new Exports_js_2.ConversationTranslationResult(speechPayload.participantId, this.getTranslations(speechPayload.translations), speechPayload.language, speechPayload.id, conversationResultReason, speechPayload.recognition, undefined, undefined, message.textBody, undefined);
  23660. if (speechPayload.isFinal) {
  23661. // check the length, sometimes empty finals are returned
  23662. if (speechResult.text !== undefined && speechResult.text.length > 0) {
  23663. sendFinal = true;
  23664. }
  23665. else if (speechPayload.id === this.privLastPartialUtteranceId) {
  23666. // send final as normal. We had a non-empty partial for this same utterance
  23667. // so sending the empty final is important
  23668. sendFinal = true;
  23669. }
  23670. else {
  23671. // suppress unneeded final
  23672. }
  23673. if (sendFinal) {
  23674. if (!!this.privConversationServiceConnector.translationReceived) {
  23675. this.privConversationServiceConnector.translationReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ConversationReceivedTranslationEventArgs(ConversationTranslatorInterfaces_js_1.ConversationTranslatorMessageTypes.final, speechResult, sessionId));
  23676. }
  23677. }
  23678. }
  23679. else if (speechResult.text !== undefined) {
  23680. this.privLastPartialUtteranceId = speechPayload.id;
  23681. if (!!this.privConversationServiceConnector.translationReceived) {
  23682. this.privConversationServiceConnector.translationReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ConversationReceivedTranslationEventArgs(ConversationTranslatorInterfaces_js_1.ConversationTranslatorMessageTypes.partial, speechResult, sessionId));
  23683. }
  23684. }
  23685. break;
  23686. /**
  23687. * "translated_message" is a text message or instant message (IM).
  23688. */
  23689. case "translated_message":
  23690. const textPayload = Exports_js_4.TextResponsePayload.fromJSON(message.textBody);
  23691. // TODO: (Native parity) a result reason should be set based whether the participantId is ours or not
  23692. const textResult = new Exports_js_2.ConversationTranslationResult(textPayload.participantId, this.getTranslations(textPayload.translations), textPayload.language, undefined, undefined, textPayload.originalText, undefined, undefined, undefined, message.textBody, undefined);
  23693. if (!!this.privConversationServiceConnector.translationReceived) {
  23694. this.privConversationServiceConnector.translationReceived(this.privConversationServiceConnector, new ConversationTranslatorEventArgs_js_1.ConversationReceivedTranslationEventArgs(ConversationTranslatorInterfaces_js_1.ConversationTranslatorMessageTypes.instantMessage, textResult, sessionId));
  23695. }
  23696. break;
  23697. default:
  23698. // ignore any unsupported message types
  23699. break;
  23700. }
  23701. }
  23702. catch (e) {
  23703. // continue
  23704. }
  23705. return this.receiveConversationMessageOverride();
  23706. }
  23707. catch (e) {
  23708. this.terminateMessageLoop = true;
  23709. }
  23710. return communicationCustodian.promise;
  23711. }
  23712. async startMessageLoop() {
  23713. if (this.isDisposed()) {
  23714. return Promise.resolve();
  23715. }
  23716. this.terminateMessageLoop = false;
  23717. const messageRetrievalPromise = this.receiveConversationMessageOverride();
  23718. try {
  23719. const r = await messageRetrievalPromise;
  23720. return r;
  23721. }
  23722. catch (error) {
  23723. this.cancelRecognition(this.privRequestSession ? this.privRequestSession.sessionId : "", this.privRequestSession ? this.privRequestSession.requestId : "", Exports_js_2.CancellationReason.Error, Exports_js_2.CancellationErrorCode.RuntimeError, error);
  23724. return null;
  23725. }
  23726. }
  23727. // Takes an established websocket connection to the endpoint
  23728. configConnection() {
  23729. if (this.isDisposed()) {
  23730. return Promise.resolve(undefined);
  23731. }
  23732. if (this.privConnectionConfigPromise !== undefined) {
  23733. return this.privConnectionConfigPromise.then((connection) => {
  23734. if (connection.state() === Exports_js_1.ConnectionState.Disconnected) {
  23735. this.privConnectionId = null;
  23736. this.privConnectionConfigPromise = undefined;
  23737. return this.configConnection();
  23738. }
  23739. return this.privConnectionConfigPromise;
  23740. }, () => {
  23741. this.privConnectionId = null;
  23742. this.privConnectionConfigPromise = undefined;
  23743. return this.configConnection();
  23744. });
  23745. }
  23746. if (this.terminateMessageLoop) {
  23747. return Promise.resolve(undefined);
  23748. }
  23749. this.privConnectionConfigPromise = this.connectImpl().then((connection) => connection);
  23750. return this.privConnectionConfigPromise;
  23751. }
  23752. getTranslations(serviceResultTranslations) {
  23753. let translations;
  23754. if (undefined !== serviceResultTranslations) {
  23755. translations = new Exports_js_2.Translations();
  23756. for (const translation of serviceResultTranslations) {
  23757. translations.set(translation.lang, translation.translation);
  23758. }
  23759. }
  23760. return translations;
  23761. }
  23762. }
  23763. exports.ConversationServiceAdapter = ConversationServiceAdapter;
  23764. /***/ }),
  23765. /* 265 */
  23766. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  23767. "use strict";
  23768. // Copyright (c) Microsoft Corporation. All rights reserved.
  23769. // Licensed under the MIT license.
  23770. Object.defineProperty(exports, "__esModule", ({ value: true }));
  23771. exports.ConversationRequestSession = void 0;
  23772. const Exports_js_1 = __webpack_require__(4);
  23773. /**
  23774. * Placeholder class for the Conversation Request Session. Based off RequestSession.
  23775. * TODO: define what telemetry is required.
  23776. */
  23777. class ConversationRequestSession {
  23778. constructor(sessionId) {
  23779. this.privIsDisposed = false;
  23780. this.privDetachables = new Array();
  23781. this.privSessionId = sessionId;
  23782. this.privRequestId = (0, Exports_js_1.createNoDashGuid)();
  23783. this.privRequestCompletionDeferral = new Exports_js_1.Deferred();
  23784. }
  23785. get sessionId() {
  23786. return this.privSessionId;
  23787. }
  23788. get requestId() {
  23789. return this.privRequestId;
  23790. }
  23791. get completionPromise() {
  23792. return this.privRequestCompletionDeferral.promise;
  23793. }
  23794. onPreConnectionStart(authFetchEventId, connectionId) {
  23795. this.privSessionId = connectionId;
  23796. }
  23797. onAuthCompleted(isError) {
  23798. if (isError) {
  23799. this.onComplete();
  23800. }
  23801. }
  23802. onConnectionEstablishCompleted(statusCode) {
  23803. if (statusCode === 200) {
  23804. return;
  23805. }
  23806. else if (statusCode === 403) {
  23807. this.onComplete();
  23808. }
  23809. }
  23810. onServiceTurnEndResponse(continuousRecognition) {
  23811. if (!continuousRecognition) {
  23812. this.onComplete();
  23813. }
  23814. else {
  23815. this.privRequestId = (0, Exports_js_1.createNoDashGuid)();
  23816. }
  23817. }
  23818. async dispose() {
  23819. if (!this.privIsDisposed) {
  23820. // we should have completed by now. If we did not its an unknown error.
  23821. this.privIsDisposed = true;
  23822. for (const detachable of this.privDetachables) {
  23823. await detachable.detach();
  23824. }
  23825. }
  23826. }
  23827. onComplete() {
  23828. //
  23829. }
  23830. }
  23831. exports.ConversationRequestSession = ConversationRequestSession;
  23832. /***/ }),
  23833. /* 266 */
  23834. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  23835. "use strict";
  23836. Object.defineProperty(exports, "__esModule", ({ value: true }));
  23837. exports.ConversationReceivedTranslationEventArgs = exports.ParticipantsListEventArgs = exports.ParticipantAttributeEventArgs = exports.ParticipantEventArgs = exports.LockRoomEventArgs = exports.MuteAllEventArgs = void 0;
  23838. // Copyright (c) Microsoft Corporation. All rights reserved.
  23839. // Licensed under the MIT license.
  23840. /* eslint-disable max-classes-per-file */
  23841. const Exports_js_1 = __webpack_require__(79);
  23842. class MuteAllEventArgs extends Exports_js_1.SessionEventArgs {
  23843. constructor(isMuted, sessionId) {
  23844. super(sessionId);
  23845. this.privIsMuted = isMuted;
  23846. }
  23847. get isMuted() {
  23848. return this.privIsMuted;
  23849. }
  23850. }
  23851. exports.MuteAllEventArgs = MuteAllEventArgs;
  23852. class LockRoomEventArgs extends Exports_js_1.SessionEventArgs {
  23853. constructor(isLocked, sessionId) {
  23854. super(sessionId);
  23855. this.privIsLocked = isLocked;
  23856. }
  23857. get isMuted() {
  23858. return this.privIsLocked;
  23859. }
  23860. }
  23861. exports.LockRoomEventArgs = LockRoomEventArgs;
  23862. class ParticipantEventArgs extends Exports_js_1.SessionEventArgs {
  23863. constructor(participant, sessionId) {
  23864. super(sessionId);
  23865. this.privParticipant = participant;
  23866. }
  23867. get participant() {
  23868. return this.privParticipant;
  23869. }
  23870. }
  23871. exports.ParticipantEventArgs = ParticipantEventArgs;
  23872. class ParticipantAttributeEventArgs extends Exports_js_1.SessionEventArgs {
  23873. constructor(participantId, key, value, sessionId) {
  23874. super(sessionId);
  23875. this.privKey = key;
  23876. this.privValue = value;
  23877. this.privParticipantId = participantId;
  23878. }
  23879. get value() {
  23880. return this.privValue;
  23881. }
  23882. get key() {
  23883. return this.privKey;
  23884. }
  23885. get id() {
  23886. return this.privParticipantId;
  23887. }
  23888. }
  23889. exports.ParticipantAttributeEventArgs = ParticipantAttributeEventArgs;
  23890. class ParticipantsListEventArgs extends Exports_js_1.SessionEventArgs {
  23891. constructor(conversationId, token, translateTo, profanityFilter, roomProfanityFilter, isRoomLocked, isMuteAll, participants, sessionId) {
  23892. super(sessionId);
  23893. this.privRoomId = conversationId;
  23894. this.privSessionToken = token;
  23895. this.privTranslateTo = translateTo;
  23896. this.privProfanityFilter = profanityFilter;
  23897. this.privRoomProfanityFilter = roomProfanityFilter;
  23898. this.privIsRoomLocked = isRoomLocked;
  23899. this.privIsRoomLocked = isMuteAll;
  23900. this.privParticipants = participants;
  23901. }
  23902. get sessionToken() {
  23903. return this.privSessionToken;
  23904. }
  23905. get conversationId() {
  23906. return this.privRoomId;
  23907. }
  23908. get translateTo() {
  23909. return this.privTranslateTo;
  23910. }
  23911. get profanityFilter() {
  23912. return this.privProfanityFilter;
  23913. }
  23914. get roomProfanityFilter() {
  23915. return this.privRoomProfanityFilter;
  23916. }
  23917. get isRoomLocked() {
  23918. return this.privIsRoomLocked;
  23919. }
  23920. get isMuteAll() {
  23921. return this.privIsMuteAll;
  23922. }
  23923. get participants() {
  23924. return this.privParticipants;
  23925. }
  23926. }
  23927. exports.ParticipantsListEventArgs = ParticipantsListEventArgs;
  23928. class ConversationReceivedTranslationEventArgs {
  23929. constructor(command, payload, sessionId) {
  23930. this.privPayload = payload;
  23931. this.privCommand = command;
  23932. this.privSessionId = sessionId;
  23933. }
  23934. get payload() {
  23935. return this.privPayload;
  23936. }
  23937. get command() {
  23938. return this.privCommand;
  23939. }
  23940. get sessionId() {
  23941. return this.privSessionId;
  23942. }
  23943. }
  23944. exports.ConversationReceivedTranslationEventArgs = ConversationReceivedTranslationEventArgs;
  23945. /***/ }),
  23946. /* 267 */
  23947. /***/ ((__unused_webpack_module, exports) => {
  23948. "use strict";
  23949. // Copyright (c) Microsoft Corporation. All rights reserved.
  23950. // Licensed under the MIT license.
  23951. Object.defineProperty(exports, "__esModule", ({ value: true }));
  23952. exports.ConversationTranslatorCommandTypes = exports.ConversationTranslatorMessageTypes = exports.InternalParticipants = void 0;
  23953. /** Users participating in the conversation */
  23954. class InternalParticipants {
  23955. constructor(participants = [], meId) {
  23956. this.participants = participants;
  23957. this.meId = meId;
  23958. }
  23959. /**
  23960. * Add or update a participant
  23961. * @param value
  23962. */
  23963. addOrUpdateParticipant(value) {
  23964. if (value === undefined) {
  23965. return;
  23966. }
  23967. const exists = this.getParticipantIndex(value.id);
  23968. if (exists > -1) {
  23969. this.participants.splice(exists, 1, value);
  23970. }
  23971. else {
  23972. this.participants.push(value);
  23973. }
  23974. // ensure it was added ok
  23975. return this.getParticipant(value.id);
  23976. }
  23977. /**
  23978. * Find the participant's position in the participants list.
  23979. * @param id
  23980. */
  23981. getParticipantIndex(id) {
  23982. return this.participants.findIndex((p) => p.id === id);
  23983. }
  23984. /**
  23985. * Find the participant by id.
  23986. * @param id
  23987. */
  23988. getParticipant(id) {
  23989. return this.participants.find((p) => p.id === id);
  23990. }
  23991. /**
  23992. * Remove a participant from the participants list.
  23993. */
  23994. deleteParticipant(id) {
  23995. this.participants = this.participants.filter((p) => p.id !== id);
  23996. }
  23997. /**
  23998. * Helper to return the conversation host.
  23999. */
  24000. get host() {
  24001. return this.participants.find((p) => p.isHost === true);
  24002. }
  24003. /**
  24004. * Helper to return the current user.
  24005. */
  24006. get me() {
  24007. return this.getParticipant(this.meId);
  24008. }
  24009. }
  24010. exports.InternalParticipants = InternalParticipants;
  24011. /**
  24012. * List of command message types
  24013. */
  24014. exports.ConversationTranslatorMessageTypes = {
  24015. command: "command",
  24016. final: "final",
  24017. info: "info",
  24018. instantMessage: "instant_message",
  24019. keepAlive: "keep_alive",
  24020. partial: "partial",
  24021. participantCommand: "participant_command",
  24022. translatedMessage: "translated_message"
  24023. };
  24024. /**
  24025. * List of command types
  24026. */
  24027. exports.ConversationTranslatorCommandTypes = {
  24028. changeNickname: "ChangeNickname",
  24029. disconnectSession: "DisconnectSession",
  24030. ejectParticipant: "EjectParticipant",
  24031. instant_message: "instant_message",
  24032. joinSession: "JoinSession",
  24033. leaveSession: "LeaveSession",
  24034. participantList: "ParticipantList",
  24035. roomExpirationWarning: "RoomExpirationWarning",
  24036. setLockState: "SetLockState",
  24037. setMute: "SetMute",
  24038. setMuteAll: "SetMuteAll",
  24039. setProfanityFiltering: "SetProfanityFiltering",
  24040. setTranslateToLanguages: "SetTranslateToLanguages",
  24041. setUseTTS: "SetUseTTS"
  24042. };
  24043. /***/ }),
  24044. /* 268 */
  24045. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  24046. "use strict";
  24047. Object.defineProperty(exports, "__esModule", ({ value: true }));
  24048. exports.TextResponsePayload = exports.SpeechResponsePayload = exports.ParticipantPayloadResponse = exports.ParticipantsListPayloadResponse = exports.CommandResponsePayload = void 0;
  24049. var CommandResponsePayload_js_1 = __webpack_require__(269);
  24050. Object.defineProperty(exports, "CommandResponsePayload", ({ enumerable: true, get: function () { return CommandResponsePayload_js_1.CommandResponsePayload; } }));
  24051. var ParticipantResponsePayload_js_1 = __webpack_require__(270);
  24052. Object.defineProperty(exports, "ParticipantsListPayloadResponse", ({ enumerable: true, get: function () { return ParticipantResponsePayload_js_1.ParticipantsListPayloadResponse; } }));
  24053. Object.defineProperty(exports, "ParticipantPayloadResponse", ({ enumerable: true, get: function () { return ParticipantResponsePayload_js_1.ParticipantPayloadResponse; } }));
  24054. var TranslationResponsePayload_js_1 = __webpack_require__(271);
  24055. Object.defineProperty(exports, "SpeechResponsePayload", ({ enumerable: true, get: function () { return TranslationResponsePayload_js_1.SpeechResponsePayload; } }));
  24056. Object.defineProperty(exports, "TextResponsePayload", ({ enumerable: true, get: function () { return TranslationResponsePayload_js_1.TextResponsePayload; } }));
  24057. /***/ }),
  24058. /* 269 */
  24059. /***/ ((__unused_webpack_module, exports) => {
  24060. "use strict";
  24061. // Copyright (c) Microsoft Corporation. All rights reserved.
  24062. // Licensed under the MIT license.
  24063. Object.defineProperty(exports, "__esModule", ({ value: true }));
  24064. exports.CommandResponsePayload = void 0;
  24065. const parseCommandResponse = (json) => JSON.parse(json);
  24066. class CommandResponsePayload {
  24067. constructor(json) {
  24068. this.privCommandResponse = parseCommandResponse(json);
  24069. }
  24070. get type() {
  24071. return this.privCommandResponse.type;
  24072. }
  24073. get command() {
  24074. return this.privCommandResponse.command;
  24075. }
  24076. get id() {
  24077. return this.privCommandResponse.id;
  24078. }
  24079. get nickname() {
  24080. return this.privCommandResponse.nickname;
  24081. }
  24082. get participantId() {
  24083. return this.privCommandResponse.participantId;
  24084. }
  24085. get roomid() {
  24086. return this.privCommandResponse.roomid;
  24087. }
  24088. get value() {
  24089. return this.privCommandResponse.value;
  24090. }
  24091. get token() {
  24092. return this.privCommandResponse.token;
  24093. }
  24094. static fromJSON(json) {
  24095. return new CommandResponsePayload(json);
  24096. }
  24097. }
  24098. exports.CommandResponsePayload = CommandResponsePayload;
  24099. /***/ }),
  24100. /* 270 */
  24101. /***/ ((__unused_webpack_module, exports) => {
  24102. "use strict";
  24103. // Copyright (c) Microsoft Corporation. All rights reserved.
  24104. // Licensed under the MIT license.
  24105. Object.defineProperty(exports, "__esModule", ({ value: true }));
  24106. exports.ParticipantPayloadResponse = exports.ParticipantsListPayloadResponse = void 0;
  24107. const parseListResponse = (json) => JSON.parse(json);
  24108. const parseParticipantResponse = (json) => JSON.parse(json);
  24109. class ParticipantsListPayloadResponse {
  24110. constructor(json) {
  24111. this.privParticipantsPayloadResponse = parseListResponse(json);
  24112. }
  24113. get roomid() {
  24114. return this.privParticipantsPayloadResponse.roomid;
  24115. }
  24116. get id() {
  24117. return this.privParticipantsPayloadResponse.id;
  24118. }
  24119. get command() {
  24120. return this.privParticipantsPayloadResponse.command;
  24121. }
  24122. get participants() {
  24123. return this.privParticipantsPayloadResponse.participants;
  24124. }
  24125. get token() {
  24126. return this.privParticipantsPayloadResponse.token;
  24127. }
  24128. get translateTo() {
  24129. return this.privParticipantsPayloadResponse.translateTo;
  24130. }
  24131. get profanityFilter() {
  24132. return this.privParticipantsPayloadResponse.profanityFilter;
  24133. }
  24134. get roomProfanityFilter() {
  24135. return this.privParticipantsPayloadResponse.roomProfanityFilter;
  24136. }
  24137. get roomLocked() {
  24138. return this.privParticipantsPayloadResponse.roomLocked;
  24139. }
  24140. get muteAll() {
  24141. return this.privParticipantsPayloadResponse.muteAll;
  24142. }
  24143. get type() {
  24144. return this.privParticipantsPayloadResponse.type;
  24145. }
  24146. static fromJSON(json) {
  24147. return new ParticipantsListPayloadResponse(json);
  24148. }
  24149. }
  24150. exports.ParticipantsListPayloadResponse = ParticipantsListPayloadResponse;
  24151. class ParticipantPayloadResponse {
  24152. constructor(json) {
  24153. this.privParticipantPayloadResponse = parseParticipantResponse(json);
  24154. }
  24155. get nickname() {
  24156. return this.privParticipantPayloadResponse.nickname;
  24157. }
  24158. get locale() {
  24159. return this.privParticipantPayloadResponse.locale;
  24160. }
  24161. get usetts() {
  24162. return this.privParticipantPayloadResponse.usetts;
  24163. }
  24164. get ismuted() {
  24165. return this.privParticipantPayloadResponse.ismuted;
  24166. }
  24167. get ishost() {
  24168. return this.privParticipantPayloadResponse.ishost;
  24169. }
  24170. get participantId() {
  24171. return this.privParticipantPayloadResponse.participantId;
  24172. }
  24173. get avatar() {
  24174. return this.privParticipantPayloadResponse.avatar;
  24175. }
  24176. static fromJSON(json) {
  24177. return new ParticipantPayloadResponse(json);
  24178. }
  24179. }
  24180. exports.ParticipantPayloadResponse = ParticipantPayloadResponse;
  24181. /***/ }),
  24182. /* 271 */
  24183. /***/ ((__unused_webpack_module, exports) => {
  24184. "use strict";
  24185. // Copyright (c) Microsoft Corporation. All rights reserved.
  24186. // Licensed under the MIT license.
  24187. Object.defineProperty(exports, "__esModule", ({ value: true }));
  24188. exports.TextResponsePayload = exports.SpeechResponsePayload = void 0;
  24189. const parseSpeechResponse = (json) => JSON.parse(json);
  24190. const parseTextResponse = (json) => JSON.parse(json);
  24191. class SpeechResponsePayload {
  24192. constructor(json) {
  24193. this.privSpeechResponse = parseSpeechResponse(json);
  24194. }
  24195. get recognition() {
  24196. return this.privSpeechResponse.recognition;
  24197. }
  24198. get translations() {
  24199. return this.privSpeechResponse.translations;
  24200. }
  24201. get id() {
  24202. return this.privSpeechResponse.id;
  24203. }
  24204. get language() {
  24205. return this.privSpeechResponse.language;
  24206. }
  24207. get nickname() {
  24208. return this.privSpeechResponse.nickname;
  24209. }
  24210. get participantId() {
  24211. return this.privSpeechResponse.participantId;
  24212. }
  24213. get roomid() {
  24214. return this.privSpeechResponse.roomid;
  24215. }
  24216. get timestamp() {
  24217. return this.privSpeechResponse.timestamp;
  24218. }
  24219. get type() {
  24220. return this.privSpeechResponse.type;
  24221. }
  24222. get isFinal() {
  24223. return this.privSpeechResponse.type === "final";
  24224. }
  24225. static fromJSON(json) {
  24226. return new SpeechResponsePayload(json);
  24227. }
  24228. }
  24229. exports.SpeechResponsePayload = SpeechResponsePayload;
  24230. class TextResponsePayload {
  24231. constructor(json) {
  24232. this.privTextResponse = parseTextResponse(json);
  24233. }
  24234. get originalText() {
  24235. return this.privTextResponse.originalText;
  24236. }
  24237. get translations() {
  24238. return this.privTextResponse.translations;
  24239. }
  24240. get id() {
  24241. return this.privTextResponse.id;
  24242. }
  24243. get language() {
  24244. return this.privTextResponse.language;
  24245. }
  24246. get nickname() {
  24247. return this.privTextResponse.nickname;
  24248. }
  24249. get participantId() {
  24250. return this.privTextResponse.participantId;
  24251. }
  24252. get roomid() {
  24253. return this.privTextResponse.roomid;
  24254. }
  24255. get timestamp() {
  24256. return this.privTextResponse.timestamp;
  24257. }
  24258. get type() {
  24259. return this.privTextResponse.type;
  24260. }
  24261. static fromJSON(json) {
  24262. return new TextResponsePayload(json);
  24263. }
  24264. }
  24265. exports.TextResponsePayload = TextResponsePayload;
  24266. /***/ }),
  24267. /* 272 */
  24268. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  24269. "use strict";
  24270. Object.defineProperty(exports, "__esModule", ({ value: true }));
  24271. exports.TranscriberRecognizer = void 0;
  24272. // Copyright (c) Microsoft Corporation. All rights reserved.
  24273. // Licensed under the MIT license.
  24274. const Exports_js_1 = __webpack_require__(4);
  24275. const Contracts_js_1 = __webpack_require__(64);
  24276. const Exports_js_2 = __webpack_require__(79);
  24277. const Exports_js_3 = __webpack_require__(2);
  24278. const PhraseDetectionContext_js_1 = __webpack_require__(113);
  24279. class TranscriberRecognizer extends Exports_js_2.Recognizer {
  24280. /**
  24281. * TranscriberRecognizer constructor.
  24282. * @constructor
  24283. * @param {SpeechTranslationConfig} speechTranslationConfig - Non-audio configuration associated with the recognizer
  24284. * @param {AudioConfig} audioConfig - An audio configuration associated with the recognizer
  24285. */
  24286. constructor(speechTranslationConfig, audioConfig) {
  24287. const speechTranslationConfigImpl = speechTranslationConfig;
  24288. Contracts_js_1.Contracts.throwIfNull(speechTranslationConfigImpl, "speechTranslationConfig");
  24289. const audioConfigImpl = audioConfig;
  24290. Contracts_js_1.Contracts.throwIfNull(audioConfigImpl, "audioConfigImpl");
  24291. Contracts_js_1.Contracts.throwIfNullOrWhitespace(speechTranslationConfigImpl.speechRecognitionLanguage, Exports_js_2.PropertyId[Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage]);
  24292. super(audioConfig, speechTranslationConfigImpl.properties, new Exports_js_3.TranscriberConnectionFactory());
  24293. this.privDisposedRecognizer = false;
  24294. this.isMeetingRecognizer = false;
  24295. }
  24296. get speechRecognitionLanguage() {
  24297. Contracts_js_1.Contracts.throwIfDisposed(this.privDisposedRecognizer);
  24298. return this.properties.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage);
  24299. }
  24300. get properties() {
  24301. return this.privProperties;
  24302. }
  24303. get authorizationToken() {
  24304. return this.properties.getProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token);
  24305. }
  24306. set authorizationToken(token) {
  24307. Contracts_js_1.Contracts.throwIfNullOrWhitespace(token, "token");
  24308. this.properties.setProperty(Exports_js_2.PropertyId.SpeechServiceAuthorization_Token, token);
  24309. }
  24310. set conversation(c) {
  24311. Contracts_js_1.Contracts.throwIfNullOrUndefined(c, "Conversation");
  24312. this.isMeetingRecognizer = false;
  24313. this.privConversation = c;
  24314. }
  24315. getConversationInfo() {
  24316. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privConversation, "Conversation");
  24317. return this.privConversation.conversationInfo;
  24318. }
  24319. set meeting(m) {
  24320. Contracts_js_1.Contracts.throwIfNullOrUndefined(m, "Meeting");
  24321. this.isMeetingRecognizer = true;
  24322. this.privMeeting = m;
  24323. }
  24324. getMeetingInfo() {
  24325. Contracts_js_1.Contracts.throwIfNullOrUndefined(this.privMeeting, "Meeting");
  24326. return this.privMeeting.meetingInfo;
  24327. }
  24328. IsMeetingRecognizer() {
  24329. return this.isMeetingRecognizer;
  24330. }
  24331. startContinuousRecognitionAsync(cb, err) {
  24332. (0, Exports_js_1.marshalPromiseToCallbacks)(this.startContinuousRecognitionAsyncImpl(PhraseDetectionContext_js_1.RecognitionMode.Conversation), cb, err);
  24333. }
  24334. stopContinuousRecognitionAsync(cb, err) {
  24335. (0, Exports_js_1.marshalPromiseToCallbacks)(this.stopContinuousRecognitionAsyncImpl(), cb, err);
  24336. }
  24337. async close() {
  24338. if (!this.privDisposedRecognizer) {
  24339. await this.dispose(true);
  24340. }
  24341. }
  24342. // Push async join/leave conversation message via serviceRecognizer
  24343. async pushConversationEvent(conversationInfo, command) {
  24344. const reco = (this.privReco);
  24345. Contracts_js_1.Contracts.throwIfNullOrUndefined(reco, "serviceRecognizer");
  24346. await reco.sendSpeechEventAsync(conversationInfo, command);
  24347. }
  24348. // Push async join/leave meeting message via serviceRecognizer
  24349. async pushMeetingEvent(meetingInfo, command) {
  24350. const reco = (this.privReco);
  24351. Contracts_js_1.Contracts.throwIfNullOrUndefined(reco, "serviceRecognizer");
  24352. await reco.sendMeetingSpeechEventAsync(meetingInfo, command);
  24353. }
  24354. async enforceAudioGating() {
  24355. const audioConfigImpl = this.audioConfig;
  24356. const format = await audioConfigImpl.format;
  24357. const channels = format.channels;
  24358. if (channels === 1) {
  24359. if (this.properties.getProperty("f0f5debc-f8c9-4892-ac4b-90a7ab359fd2", "false").toLowerCase() !== "true") {
  24360. throw new Error("Single channel audio configuration for MeetingTranscriber is currently under private preview, please contact diarizationrequest@microsoft.com for more details");
  24361. }
  24362. }
  24363. else if (channels !== 8) {
  24364. throw new Error(`Unsupported audio configuration: Detected ${channels}-channel audio`);
  24365. }
  24366. return;
  24367. }
  24368. connectMeetingCallbacks(transcriber) {
  24369. this.isMeetingRecognizer = true;
  24370. this.canceled = (s, e) => {
  24371. if (!!transcriber.canceled) {
  24372. transcriber.canceled(transcriber, e);
  24373. }
  24374. };
  24375. this.recognizing = (s, e) => {
  24376. if (!!transcriber.transcribing) {
  24377. transcriber.transcribing(transcriber, e);
  24378. }
  24379. };
  24380. this.recognized = (s, e) => {
  24381. if (!!transcriber.transcribed) {
  24382. transcriber.transcribed(transcriber, e);
  24383. }
  24384. };
  24385. this.sessionStarted = (s, e) => {
  24386. if (!!transcriber.sessionStarted) {
  24387. transcriber.sessionStarted(transcriber, e);
  24388. }
  24389. };
  24390. this.sessionStopped = (s, e) => {
  24391. if (!!transcriber.sessionStopped) {
  24392. transcriber.sessionStopped(transcriber, e);
  24393. }
  24394. };
  24395. }
  24396. disconnectCallbacks() {
  24397. this.canceled = undefined;
  24398. this.recognizing = undefined;
  24399. this.recognized = undefined;
  24400. this.sessionStarted = undefined;
  24401. this.sessionStopped = undefined;
  24402. }
  24403. /**
  24404. * Disposes any resources held by the object.
  24405. * @member ConversationTranscriber.prototype.dispose
  24406. * @function
  24407. * @public
  24408. * @param {boolean} disposing - true if disposing the object.
  24409. */
  24410. async dispose(disposing) {
  24411. if (this.privDisposedRecognizer) {
  24412. return;
  24413. }
  24414. if (disposing) {
  24415. this.privDisposedRecognizer = true;
  24416. await this.implRecognizerStop();
  24417. }
  24418. await super.dispose(disposing);
  24419. }
  24420. createRecognizerConfig(speechConfig) {
  24421. return new Exports_js_3.RecognizerConfig(speechConfig, this.properties);
  24422. }
  24423. createServiceRecognizer(authentication, connectionFactory, audioConfig, recognizerConfig) {
  24424. const configImpl = audioConfig;
  24425. return new Exports_js_3.TranscriptionServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);
  24426. }
  24427. }
  24428. exports.TranscriberRecognizer = TranscriberRecognizer;
  24429. /***/ }),
  24430. /* 273 */
  24431. /***/ ((__unused_webpack_module, exports) => {
  24432. "use strict";
  24433. // Copyright (c) Microsoft Corporation. All rights reserved.
  24434. // Licensed under the MIT license.
  24435. Object.defineProperty(exports, "__esModule", ({ value: true }));
  24436. exports.SynthesisAudioMetadata = exports.MetadataType = void 0;
  24437. var MetadataType;
  24438. (function (MetadataType) {
  24439. MetadataType["WordBoundary"] = "WordBoundary";
  24440. MetadataType["Bookmark"] = "Bookmark";
  24441. MetadataType["Viseme"] = "Viseme";
  24442. MetadataType["SentenceBoundary"] = "SentenceBoundary";
  24443. MetadataType["SessionEnd"] = "SessionEnd";
  24444. MetadataType["AvatarSignal"] = "TalkingAvatarSignal";
  24445. })(MetadataType = exports.MetadataType || (exports.MetadataType = {}));
  24446. class SynthesisAudioMetadata {
  24447. constructor(json) {
  24448. this.privSynthesisAudioMetadata = JSON.parse(json);
  24449. }
  24450. static fromJSON(json) {
  24451. return new SynthesisAudioMetadata(json);
  24452. }
  24453. get Metadata() {
  24454. return this.privSynthesisAudioMetadata.Metadata;
  24455. }
  24456. }
  24457. exports.SynthesisAudioMetadata = SynthesisAudioMetadata;
  24458. /***/ }),
  24459. /* 274 */
  24460. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  24461. "use strict";
  24462. // Copyright (c) Microsoft Corporation. All rights reserved.
  24463. // Licensed under the MIT license.
  24464. Object.defineProperty(exports, "__esModule", ({ value: true }));
  24465. exports.SynthesisTurn = void 0;
  24466. const Exports_js_1 = __webpack_require__(4);
  24467. const AudioOutputStream_js_1 = __webpack_require__(84);
  24468. const Exports_js_2 = __webpack_require__(79);
  24469. const SynthesisAudioMetadata_js_1 = __webpack_require__(273);
  24470. const SynthesisEvents_js_1 = __webpack_require__(275);
  24471. class SynthesisTurn {
  24472. constructor() {
  24473. this.privIsDisposed = false;
  24474. this.privIsSynthesizing = false;
  24475. this.privIsSynthesisEnded = false;
  24476. this.privBytesReceived = 0;
  24477. this.privInTurn = false;
  24478. this.privTextOffset = 0;
  24479. this.privNextSearchTextIndex = 0;
  24480. this.privSentenceOffset = 0;
  24481. this.privNextSearchSentenceIndex = 0;
  24482. this.privRequestId = (0, Exports_js_1.createNoDashGuid)();
  24483. this.privTurnDeferral = new Exports_js_1.Deferred();
  24484. // We're not in a turn, so resolve.
  24485. this.privTurnDeferral.resolve();
  24486. }
  24487. get requestId() {
  24488. return this.privRequestId;
  24489. }
  24490. get streamId() {
  24491. return this.privStreamId;
  24492. }
  24493. set streamId(value) {
  24494. this.privStreamId = value;
  24495. }
  24496. get audioOutputFormat() {
  24497. return this.privAudioOutputFormat;
  24498. }
  24499. set audioOutputFormat(format) {
  24500. this.privAudioOutputFormat = format;
  24501. }
  24502. get turnCompletionPromise() {
  24503. return this.privTurnDeferral.promise;
  24504. }
  24505. get isSynthesisEnded() {
  24506. return this.privIsSynthesisEnded;
  24507. }
  24508. get isSynthesizing() {
  24509. return this.privIsSynthesizing;
  24510. }
  24511. get currentTextOffset() {
  24512. return this.privTextOffset;
  24513. }
  24514. get currentSentenceOffset() {
  24515. return this.privSentenceOffset;
  24516. }
  24517. // The number of bytes received for current turn
  24518. get bytesReceived() {
  24519. return this.privBytesReceived;
  24520. }
  24521. get audioDuration() {
  24522. return this.privAudioDuration;
  24523. }
  24524. get extraProperties() {
  24525. if (!!this.privWebRTCSDP) {
  24526. const properties = new Exports_js_2.PropertyCollection();
  24527. properties.setProperty(Exports_js_2.PropertyId.TalkingAvatarService_WebRTC_SDP, this.privWebRTCSDP);
  24528. return properties;
  24529. }
  24530. return undefined;
  24531. }
  24532. async getAllReceivedAudio() {
  24533. if (!!this.privReceivedAudio) {
  24534. return Promise.resolve(this.privReceivedAudio);
  24535. }
  24536. if (!this.privIsSynthesisEnded) {
  24537. return null;
  24538. }
  24539. await this.readAllAudioFromStream();
  24540. return Promise.resolve(this.privReceivedAudio);
  24541. }
  24542. async getAllReceivedAudioWithHeader() {
  24543. if (!!this.privReceivedAudioWithHeader) {
  24544. return this.privReceivedAudioWithHeader;
  24545. }
  24546. if (!this.privIsSynthesisEnded) {
  24547. return null;
  24548. }
  24549. if (this.audioOutputFormat.hasHeader) {
  24550. const audio = await this.getAllReceivedAudio();
  24551. this.privReceivedAudioWithHeader = this.audioOutputFormat.addHeader(audio);
  24552. return this.privReceivedAudioWithHeader;
  24553. }
  24554. else {
  24555. return this.getAllReceivedAudio();
  24556. }
  24557. }
  24558. startNewSynthesis(requestId, rawText, isSSML, audioDestination) {
  24559. this.privIsSynthesisEnded = false;
  24560. this.privIsSynthesizing = true;
  24561. this.privRequestId = requestId;
  24562. this.privRawText = rawText;
  24563. this.privIsSSML = isSSML;
  24564. this.privAudioOutputStream = new AudioOutputStream_js_1.PullAudioOutputStreamImpl();
  24565. this.privAudioOutputStream.format = this.privAudioOutputFormat;
  24566. this.privReceivedAudio = null;
  24567. this.privReceivedAudioWithHeader = null;
  24568. this.privBytesReceived = 0;
  24569. this.privTextOffset = 0;
  24570. this.privNextSearchTextIndex = 0;
  24571. this.privSentenceOffset = 0;
  24572. this.privNextSearchSentenceIndex = 0;
  24573. this.privPartialVisemeAnimation = "";
  24574. this.privWebRTCSDP = "";
  24575. if (audioDestination !== undefined) {
  24576. this.privTurnAudioDestination = audioDestination;
  24577. this.privTurnAudioDestination.format = this.privAudioOutputFormat;
  24578. }
  24579. this.onEvent(new SynthesisEvents_js_1.SynthesisTriggeredEvent(this.requestId, undefined, audioDestination === undefined ? undefined : audioDestination.id()));
  24580. }
  24581. onPreConnectionStart(authFetchEventId) {
  24582. this.privAuthFetchEventId = authFetchEventId;
  24583. this.onEvent(new SynthesisEvents_js_1.ConnectingToSynthesisServiceEvent(this.privRequestId, this.privAuthFetchEventId));
  24584. }
  24585. onAuthCompleted(isError) {
  24586. if (isError) {
  24587. this.onComplete();
  24588. }
  24589. }
  24590. onConnectionEstablishCompleted(statusCode) {
  24591. if (statusCode === 200) {
  24592. this.onEvent(new SynthesisEvents_js_1.SynthesisStartedEvent(this.requestId, this.privAuthFetchEventId));
  24593. this.privBytesReceived = 0;
  24594. return;
  24595. }
  24596. else if (statusCode === 403) {
  24597. this.onComplete();
  24598. }
  24599. }
  24600. onServiceResponseMessage(responseJson) {
  24601. const response = JSON.parse(responseJson);
  24602. this.streamId = response.audio.streamId;
  24603. }
  24604. onServiceTurnEndResponse() {
  24605. this.privInTurn = false;
  24606. this.privTurnDeferral.resolve();
  24607. this.onComplete();
  24608. }
  24609. onServiceTurnStartResponse(responseJson) {
  24610. if (!!this.privTurnDeferral && !!this.privInTurn) {
  24611. // What? How are we starting a turn with another not done?
  24612. this.privTurnDeferral.reject("Another turn started before current completed.");
  24613. // Avoid UnhandledPromiseRejection if privTurnDeferral is not being awaited
  24614. // eslint-disable-next-line @typescript-eslint/no-empty-function
  24615. this.privTurnDeferral.promise.then().catch(() => { });
  24616. }
  24617. this.privInTurn = true;
  24618. this.privTurnDeferral = new Exports_js_1.Deferred();
  24619. const response = JSON.parse(responseJson);
  24620. if (!!response.webrtc) {
  24621. this.privWebRTCSDP = response.webrtc.connectionString;
  24622. }
  24623. }
  24624. onAudioChunkReceived(data) {
  24625. if (this.isSynthesizing) {
  24626. this.privAudioOutputStream.write(data);
  24627. this.privBytesReceived += data.byteLength;
  24628. if (this.privTurnAudioDestination !== undefined) {
  24629. this.privTurnAudioDestination.write(data);
  24630. }
  24631. }
  24632. }
  24633. onTextBoundaryEvent(metadata) {
  24634. this.updateTextOffset(metadata.Data.text.Text, metadata.Type);
  24635. }
  24636. onVisemeMetadataReceived(metadata) {
  24637. if (metadata.Data.AnimationChunk !== undefined) {
  24638. this.privPartialVisemeAnimation += metadata.Data.AnimationChunk;
  24639. }
  24640. }
  24641. onSessionEnd(metadata) {
  24642. this.privAudioDuration = metadata.Data.Offset;
  24643. }
  24644. async constructSynthesisResult() {
  24645. const audioBuffer = await this.getAllReceivedAudioWithHeader();
  24646. return new Exports_js_2.SpeechSynthesisResult(this.requestId, Exports_js_2.ResultReason.SynthesizingAudioCompleted, audioBuffer, undefined, this.extraProperties, this.audioDuration);
  24647. }
  24648. dispose() {
  24649. if (!this.privIsDisposed) {
  24650. // we should have completed by now. If we did not its an unknown error.
  24651. this.privIsDisposed = true;
  24652. }
  24653. }
  24654. onStopSynthesizing() {
  24655. this.onComplete();
  24656. }
  24657. /**
  24658. * Gets the viseme animation string (merged from animation chunk), and clears the internal
  24659. * partial animation.
  24660. */
  24661. getAndClearVisemeAnimation() {
  24662. const animation = this.privPartialVisemeAnimation;
  24663. this.privPartialVisemeAnimation = "";
  24664. return animation;
  24665. }
  24666. onEvent(event) {
  24667. Exports_js_1.Events.instance.onEvent(event);
  24668. }
  24669. /**
  24670. * Check if the text is an XML(SSML) tag
  24671. * @param text
  24672. * @private
  24673. */
  24674. static isXmlTag(text) {
  24675. return text.length >= 2 && text[0] === "<" && text[text.length - 1] === ">";
  24676. }
  24677. updateTextOffset(text, type) {
  24678. if (type === SynthesisAudioMetadata_js_1.MetadataType.WordBoundary) {
  24679. this.privTextOffset = this.privRawText.indexOf(text, this.privNextSearchTextIndex);
  24680. if (this.privTextOffset >= 0) {
  24681. this.privNextSearchTextIndex = this.privTextOffset + text.length;
  24682. if (this.privIsSSML) {
  24683. if (this.withinXmlTag(this.privTextOffset) && !SynthesisTurn.isXmlTag(text)) {
  24684. this.updateTextOffset(text, type);
  24685. }
  24686. }
  24687. }
  24688. }
  24689. else {
  24690. this.privSentenceOffset = this.privRawText.indexOf(text, this.privNextSearchSentenceIndex);
  24691. if (this.privSentenceOffset >= 0) {
  24692. this.privNextSearchSentenceIndex = this.privSentenceOffset + text.length;
  24693. if (this.privIsSSML) {
  24694. if (this.withinXmlTag(this.privSentenceOffset) && !SynthesisTurn.isXmlTag(text)) {
  24695. this.updateTextOffset(text, type);
  24696. }
  24697. }
  24698. }
  24699. }
  24700. }
  24701. onComplete() {
  24702. if (this.privIsSynthesizing) {
  24703. this.privIsSynthesizing = false;
  24704. this.privIsSynthesisEnded = true;
  24705. this.privAudioOutputStream.close();
  24706. this.privInTurn = false;
  24707. if (this.privTurnAudioDestination !== undefined) {
  24708. this.privTurnAudioDestination.close();
  24709. this.privTurnAudioDestination = undefined;
  24710. }
  24711. }
  24712. }
  24713. async readAllAudioFromStream() {
  24714. if (this.privIsSynthesisEnded) {
  24715. this.privReceivedAudio = new ArrayBuffer(this.bytesReceived);
  24716. try {
  24717. await this.privAudioOutputStream.read(this.privReceivedAudio);
  24718. }
  24719. catch (e) {
  24720. this.privReceivedAudio = new ArrayBuffer(0);
  24721. }
  24722. }
  24723. }
  24724. /**
  24725. * Check if current idx is in XML(SSML) tag
  24726. * @param idx
  24727. * @private
  24728. */
  24729. withinXmlTag(idx) {
  24730. return this.privRawText.indexOf("<", idx + 1) > this.privRawText.indexOf(">", idx + 1);
  24731. }
  24732. }
  24733. exports.SynthesisTurn = SynthesisTurn;
  24734. /***/ }),
  24735. /* 275 */
  24736. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  24737. "use strict";
  24738. // Copyright (c) Microsoft Corporation. All rights reserved.
  24739. // Licensed under the MIT license.
  24740. Object.defineProperty(exports, "__esModule", ({ value: true }));
  24741. exports.SynthesisStartedEvent = exports.ConnectingToSynthesisServiceEvent = exports.SynthesisTriggeredEvent = exports.SpeechSynthesisEvent = void 0;
  24742. /* eslint-disable max-classes-per-file */
  24743. const Exports_js_1 = __webpack_require__(4);
  24744. class SpeechSynthesisEvent extends Exports_js_1.PlatformEvent {
  24745. constructor(eventName, requestId, eventType = Exports_js_1.EventType.Info) {
  24746. super(eventName, eventType);
  24747. this.privRequestId = requestId;
  24748. }
  24749. get requestId() {
  24750. return this.privRequestId;
  24751. }
  24752. }
  24753. exports.SpeechSynthesisEvent = SpeechSynthesisEvent;
  24754. class SynthesisTriggeredEvent extends SpeechSynthesisEvent {
  24755. constructor(requestId, sessionAudioDestinationId, turnAudioDestinationId) {
  24756. super("SynthesisTriggeredEvent", requestId);
  24757. this.privSessionAudioDestinationId = sessionAudioDestinationId;
  24758. this.privTurnAudioDestinationId = turnAudioDestinationId;
  24759. }
  24760. get audioSessionDestinationId() {
  24761. return this.privSessionAudioDestinationId;
  24762. }
  24763. get audioTurnDestinationId() {
  24764. return this.privTurnAudioDestinationId;
  24765. }
  24766. }
  24767. exports.SynthesisTriggeredEvent = SynthesisTriggeredEvent;
  24768. class ConnectingToSynthesisServiceEvent extends SpeechSynthesisEvent {
  24769. constructor(requestId, authFetchEventId) {
  24770. super("ConnectingToSynthesisServiceEvent", requestId);
  24771. this.privAuthFetchEventId = authFetchEventId;
  24772. }
  24773. get authFetchEventId() {
  24774. return this.privAuthFetchEventId;
  24775. }
  24776. }
  24777. exports.ConnectingToSynthesisServiceEvent = ConnectingToSynthesisServiceEvent;
  24778. class SynthesisStartedEvent extends SpeechSynthesisEvent {
  24779. constructor(requestId, authFetchEventId) {
  24780. super("SynthesisStartedEvent", requestId);
  24781. this.privAuthFetchEventId = authFetchEventId;
  24782. }
  24783. get authFetchEventId() {
  24784. return this.privAuthFetchEventId;
  24785. }
  24786. }
  24787. exports.SynthesisStartedEvent = SynthesisStartedEvent;
  24788. /***/ }),
  24789. /* 276 */
  24790. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  24791. "use strict";
  24792. // Copyright (c) Microsoft Corporation. All rights reserved.
  24793. // Licensed under the MIT license.
  24794. Object.defineProperty(exports, "__esModule", ({ value: true }));
  24795. exports.SynthesisAdapterBase = void 0;
  24796. const Exports_js_1 = __webpack_require__(4);
  24797. const Exports_js_2 = __webpack_require__(79);
  24798. const Exports_js_3 = __webpack_require__(2);
  24799. const SpeechConnectionMessage_Internal_js_1 = __webpack_require__(207);
  24800. class SynthesisAdapterBase {
  24801. constructor(authentication, connectionFactory, synthesizerConfig, audioDestination) {
  24802. this.speakOverride = undefined;
  24803. this.receiveMessageOverride = undefined;
  24804. this.connectImplOverride = undefined;
  24805. this.configConnectionOverride = undefined;
  24806. // A promise for a configured connection.
  24807. // Do not consume directly, call fetchConnection instead.
  24808. this.privConnectionConfigurationPromise = undefined;
  24809. if (!authentication) {
  24810. throw new Exports_js_1.ArgumentNullError("authentication");
  24811. }
  24812. if (!connectionFactory) {
  24813. throw new Exports_js_1.ArgumentNullError("connectionFactory");
  24814. }
  24815. if (!synthesizerConfig) {
  24816. throw new Exports_js_1.ArgumentNullError("synthesizerConfig");
  24817. }
  24818. this.privAuthentication = authentication;
  24819. this.privConnectionFactory = connectionFactory;
  24820. this.privSynthesizerConfig = synthesizerConfig;
  24821. this.privIsDisposed = false;
  24822. this.privSessionAudioDestination = audioDestination;
  24823. this.privSynthesisTurn = new Exports_js_3.SynthesisTurn();
  24824. this.privConnectionEvents = new Exports_js_1.EventSource();
  24825. this.privServiceEvents = new Exports_js_1.EventSource();
  24826. this.privSynthesisContext = new Exports_js_3.SynthesisContext();
  24827. this.privAgentConfig = new Exports_js_3.AgentConfig();
  24828. this.connectionEvents.attach((connectionEvent) => {
  24829. if (connectionEvent.name === "ConnectionClosedEvent") {
  24830. const connectionClosedEvent = connectionEvent;
  24831. if (connectionClosedEvent.statusCode !== 1000) {
  24832. this.cancelSynthesisLocal(Exports_js_2.CancellationReason.Error, connectionClosedEvent.statusCode === 1007 ? Exports_js_2.CancellationErrorCode.BadRequestParameters : Exports_js_2.CancellationErrorCode.ConnectionFailure, `${connectionClosedEvent.reason} websocket error code: ${connectionClosedEvent.statusCode}`);
  24833. }
  24834. }
  24835. });
  24836. }
  24837. get synthesisContext() {
  24838. return this.privSynthesisContext;
  24839. }
  24840. get agentConfig() {
  24841. return this.privAgentConfig;
  24842. }
  24843. get connectionEvents() {
  24844. return this.privConnectionEvents;
  24845. }
  24846. get serviceEvents() {
  24847. return this.privServiceEvents;
  24848. }
  24849. set activityTemplate(messagePayload) {
  24850. this.privActivityTemplate = messagePayload;
  24851. }
  24852. get activityTemplate() {
  24853. return this.privActivityTemplate;
  24854. }
  24855. set audioOutputFormat(format) {
  24856. this.privAudioOutputFormat = format;
  24857. this.privSynthesisTurn.audioOutputFormat = format;
  24858. if (this.privSessionAudioDestination !== undefined) {
  24859. this.privSessionAudioDestination.format = format;
  24860. }
  24861. if (this.synthesisContext !== undefined) {
  24862. this.synthesisContext.audioOutputFormat = format;
  24863. }
  24864. }
  24865. isDisposed() {
  24866. return this.privIsDisposed;
  24867. }
  24868. async dispose(reason) {
  24869. this.privIsDisposed = true;
  24870. if (this.privSessionAudioDestination !== undefined) {
  24871. this.privSessionAudioDestination.close();
  24872. }
  24873. if (this.privConnectionConfigurationPromise !== undefined) {
  24874. const connection = await this.privConnectionConfigurationPromise;
  24875. await connection.dispose(reason);
  24876. }
  24877. }
  24878. async connect() {
  24879. await this.connectImpl();
  24880. }
  24881. async sendNetworkMessage(path, payload) {
  24882. const type = typeof payload === "string" ? Exports_js_1.MessageType.Text : Exports_js_1.MessageType.Binary;
  24883. const contentType = typeof payload === "string" ? "application/json" : "";
  24884. const connection = await this.fetchConnection();
  24885. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(type, path, this.privSynthesisTurn.requestId, contentType, payload));
  24886. }
  24887. async Speak(text, isSSML, requestId, successCallback, errorCallBack, audioDestination) {
  24888. let ssml;
  24889. if (isSSML) {
  24890. ssml = text;
  24891. }
  24892. else {
  24893. ssml = this.privSynthesizer.buildSsml(text);
  24894. }
  24895. if (this.speakOverride !== undefined) {
  24896. return this.speakOverride(ssml, requestId, successCallback, errorCallBack);
  24897. }
  24898. this.privSuccessCallback = successCallback;
  24899. this.privErrorCallback = errorCallBack;
  24900. this.privSynthesisTurn.startNewSynthesis(requestId, text, isSSML, audioDestination);
  24901. try {
  24902. await this.connectImpl();
  24903. const connection = await this.fetchConnection();
  24904. await this.sendSynthesisContext(connection);
  24905. await this.sendSsmlMessage(connection, ssml, requestId);
  24906. this.onSynthesisStarted(requestId);
  24907. void this.receiveMessage();
  24908. }
  24909. catch (e) {
  24910. this.cancelSynthesisLocal(Exports_js_2.CancellationReason.Error, Exports_js_2.CancellationErrorCode.ConnectionFailure, e);
  24911. return Promise.reject(e);
  24912. }
  24913. }
  24914. async stopSpeaking() {
  24915. await this.connectImpl();
  24916. const connection = await this.fetchConnection();
  24917. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_1.MessageType.Text, "synthesis.control", this.privSynthesisTurn.requestId, "application/json", JSON.stringify({
  24918. action: "stop"
  24919. })));
  24920. }
  24921. // Cancels synthesis.
  24922. cancelSynthesis(requestId, _cancellationReason, errorCode, error) {
  24923. const properties = new Exports_js_2.PropertyCollection();
  24924. properties.setProperty(Exports_js_3.CancellationErrorCodePropertyName, Exports_js_2.CancellationErrorCode[errorCode]);
  24925. const result = new Exports_js_2.SpeechSynthesisResult(requestId, Exports_js_2.ResultReason.Canceled, undefined, error, properties);
  24926. this.onSynthesisCancelled(result);
  24927. if (!!this.privSuccessCallback) {
  24928. try {
  24929. this.privSuccessCallback(result);
  24930. /* eslint-disable no-empty */
  24931. }
  24932. catch { }
  24933. }
  24934. }
  24935. // Cancels synthesis.
  24936. cancelSynthesisLocal(cancellationReason, errorCode, error) {
  24937. if (!!this.privSynthesisTurn.isSynthesizing) {
  24938. this.privSynthesisTurn.onStopSynthesizing();
  24939. this.cancelSynthesis(this.privSynthesisTurn.requestId, cancellationReason, errorCode, error);
  24940. }
  24941. }
  24942. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  24943. processTypeSpecificMessages(_connectionMessage) {
  24944. return true;
  24945. }
  24946. async receiveMessage() {
  24947. try {
  24948. const connection = await this.fetchConnection();
  24949. const message = await connection.read();
  24950. if (this.receiveMessageOverride !== undefined) {
  24951. return this.receiveMessageOverride();
  24952. }
  24953. if (this.privIsDisposed) {
  24954. // We're done.
  24955. return;
  24956. }
  24957. // indicates we are draining the queue and it came with no message;
  24958. if (!message) {
  24959. if (!this.privSynthesisTurn.isSynthesizing) {
  24960. return;
  24961. }
  24962. else {
  24963. return this.receiveMessage();
  24964. }
  24965. }
  24966. const connectionMessage = SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage.fromConnectionMessage(message);
  24967. if (connectionMessage.requestId.toLowerCase() === this.privSynthesisTurn.requestId.toLowerCase()) {
  24968. switch (connectionMessage.path.toLowerCase()) {
  24969. case "turn.start":
  24970. this.privSynthesisTurn.onServiceTurnStartResponse(connectionMessage.textBody);
  24971. break;
  24972. case "response":
  24973. this.privSynthesisTurn.onServiceResponseMessage(connectionMessage.textBody);
  24974. break;
  24975. case "audio":
  24976. if (this.privSynthesisTurn.streamId.toLowerCase() === connectionMessage.streamId.toLowerCase()
  24977. && !!connectionMessage.binaryBody) {
  24978. this.privSynthesisTurn.onAudioChunkReceived(connectionMessage.binaryBody);
  24979. this.onSynthesizing(connectionMessage.binaryBody);
  24980. if (this.privSessionAudioDestination !== undefined) {
  24981. this.privSessionAudioDestination.write(connectionMessage.binaryBody);
  24982. }
  24983. }
  24984. break;
  24985. case "audio.metadata":
  24986. const metadataList = Exports_js_3.SynthesisAudioMetadata.fromJSON(connectionMessage.textBody).Metadata;
  24987. for (const metadata of metadataList) {
  24988. switch (metadata.Type) {
  24989. case Exports_js_3.MetadataType.WordBoundary:
  24990. case Exports_js_3.MetadataType.SentenceBoundary:
  24991. this.privSynthesisTurn.onTextBoundaryEvent(metadata);
  24992. const wordBoundaryEventArgs = new Exports_js_2.SpeechSynthesisWordBoundaryEventArgs(metadata.Data.Offset, metadata.Data.Duration, metadata.Data.text.Text, metadata.Data.text.Length, metadata.Type === Exports_js_3.MetadataType.WordBoundary
  24993. ? this.privSynthesisTurn.currentTextOffset : this.privSynthesisTurn.currentSentenceOffset, metadata.Data.text.BoundaryType);
  24994. this.onWordBoundary(wordBoundaryEventArgs);
  24995. break;
  24996. case Exports_js_3.MetadataType.Bookmark:
  24997. const bookmarkEventArgs = new Exports_js_2.SpeechSynthesisBookmarkEventArgs(metadata.Data.Offset, metadata.Data.Bookmark);
  24998. this.onBookmarkReached(bookmarkEventArgs);
  24999. break;
  25000. case Exports_js_3.MetadataType.Viseme:
  25001. this.privSynthesisTurn.onVisemeMetadataReceived(metadata);
  25002. if (metadata.Data.IsLastAnimation) {
  25003. const visemeEventArgs = new Exports_js_2.SpeechSynthesisVisemeEventArgs(metadata.Data.Offset, metadata.Data.VisemeId, this.privSynthesisTurn.getAndClearVisemeAnimation());
  25004. this.onVisemeReceived(visemeEventArgs);
  25005. }
  25006. break;
  25007. case Exports_js_3.MetadataType.AvatarSignal:
  25008. this.onAvatarEvent(metadata);
  25009. break;
  25010. case Exports_js_3.MetadataType.SessionEnd:
  25011. this.privSynthesisTurn.onSessionEnd(metadata);
  25012. break;
  25013. }
  25014. }
  25015. break;
  25016. case "turn.end":
  25017. this.privSynthesisTurn.onServiceTurnEndResponse();
  25018. let result;
  25019. try {
  25020. result = await this.privSynthesisTurn.constructSynthesisResult();
  25021. if (!!this.privSuccessCallback) {
  25022. this.privSuccessCallback(result);
  25023. }
  25024. }
  25025. catch (error) {
  25026. if (!!this.privErrorCallback) {
  25027. this.privErrorCallback(error);
  25028. }
  25029. }
  25030. this.onSynthesisCompleted(result);
  25031. break;
  25032. default:
  25033. if (!this.processTypeSpecificMessages(connectionMessage)) {
  25034. // here are some messages that the derived class has not processed, dispatch them to connect class
  25035. if (!!this.privServiceEvents) {
  25036. this.serviceEvents.onEvent(new Exports_js_1.ServiceEvent(connectionMessage.path.toLowerCase(), connectionMessage.textBody));
  25037. }
  25038. }
  25039. }
  25040. }
  25041. return this.receiveMessage();
  25042. }
  25043. catch (e) {
  25044. // TODO: What goes here?
  25045. }
  25046. }
  25047. sendSynthesisContext(connection) {
  25048. this.setSynthesisContextSynthesisSection();
  25049. const synthesisContextJson = this.synthesisContext.toJSON();
  25050. if (synthesisContextJson) {
  25051. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_1.MessageType.Text, "synthesis.context", this.privSynthesisTurn.requestId, "application/json", synthesisContextJson));
  25052. }
  25053. return;
  25054. }
  25055. setSpeechConfigSynthesisSection() {
  25056. return;
  25057. }
  25058. connectImpl(isUnAuthorized = false) {
  25059. if (this.privConnectionPromise != null) {
  25060. return this.privConnectionPromise.then((connection) => {
  25061. if (connection.state() === Exports_js_1.ConnectionState.Disconnected) {
  25062. this.privConnectionId = null;
  25063. this.privConnectionPromise = null;
  25064. return this.connectImpl();
  25065. }
  25066. return this.privConnectionPromise;
  25067. }, () => {
  25068. this.privConnectionId = null;
  25069. this.privConnectionPromise = null;
  25070. return this.connectImpl();
  25071. });
  25072. }
  25073. this.privAuthFetchEventId = (0, Exports_js_1.createNoDashGuid)();
  25074. this.privConnectionId = (0, Exports_js_1.createNoDashGuid)();
  25075. this.privSynthesisTurn.onPreConnectionStart(this.privAuthFetchEventId);
  25076. const authPromise = isUnAuthorized ? this.privAuthentication.fetchOnExpiry(this.privAuthFetchEventId) : this.privAuthentication.fetch(this.privAuthFetchEventId);
  25077. this.privConnectionPromise = authPromise.then(async (result) => {
  25078. this.privSynthesisTurn.onAuthCompleted(false);
  25079. const connection = await this.privConnectionFactory.create(this.privSynthesizerConfig, result, this.privConnectionId);
  25080. // Attach to the underlying event. No need to hold onto the detach pointers as in the event the connection goes away,
  25081. // it'll stop sending events.
  25082. connection.events.attach((event) => {
  25083. this.connectionEvents.onEvent(event);
  25084. });
  25085. const response = await connection.open();
  25086. if (response.statusCode === 200) {
  25087. this.privSynthesisTurn.onConnectionEstablishCompleted(response.statusCode);
  25088. return Promise.resolve(connection);
  25089. }
  25090. else if (response.statusCode === 403 && !isUnAuthorized) {
  25091. return this.connectImpl(true);
  25092. }
  25093. else {
  25094. this.privSynthesisTurn.onConnectionEstablishCompleted(response.statusCode);
  25095. return Promise.reject(`Unable to contact server. StatusCode: ${response.statusCode},
  25096. ${this.privSynthesizerConfig.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Url)} Reason: ${response.reason}`);
  25097. }
  25098. }, (error) => {
  25099. this.privSynthesisTurn.onAuthCompleted(true);
  25100. throw new Error(error);
  25101. });
  25102. // Attach an empty handler to allow the promise to run in the background while
  25103. // other startup events happen. It'll eventually be awaited on.
  25104. // eslint-disable-next-line @typescript-eslint/no-empty-function
  25105. this.privConnectionPromise.catch(() => { });
  25106. return this.privConnectionPromise;
  25107. }
  25108. sendSpeechServiceConfig(connection, SpeechServiceConfigJson) {
  25109. if (SpeechServiceConfigJson) {
  25110. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_1.MessageType.Text, "speech.config", this.privSynthesisTurn.requestId, "application/json", SpeechServiceConfigJson));
  25111. }
  25112. }
  25113. sendSsmlMessage(connection, ssml, requestId) {
  25114. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_1.MessageType.Text, "ssml", requestId, "application/ssml+xml", ssml));
  25115. }
  25116. async fetchConnection() {
  25117. if (this.privConnectionConfigurationPromise !== undefined) {
  25118. return this.privConnectionConfigurationPromise.then((connection) => {
  25119. if (connection.state() === Exports_js_1.ConnectionState.Disconnected) {
  25120. this.privConnectionId = null;
  25121. this.privConnectionConfigurationPromise = undefined;
  25122. return this.fetchConnection();
  25123. }
  25124. return this.privConnectionConfigurationPromise;
  25125. }, () => {
  25126. this.privConnectionId = null;
  25127. this.privConnectionConfigurationPromise = undefined;
  25128. return this.fetchConnection();
  25129. });
  25130. }
  25131. this.privConnectionConfigurationPromise = this.configureConnection();
  25132. return await this.privConnectionConfigurationPromise;
  25133. }
  25134. // Takes an established websocket connection to the endpoint and sends speech configuration information.
  25135. async configureConnection() {
  25136. const connection = await this.connectImpl();
  25137. if (this.configConnectionOverride !== undefined) {
  25138. return this.configConnectionOverride(connection);
  25139. }
  25140. this.setSpeechConfigSynthesisSection();
  25141. await this.sendSpeechServiceConfig(connection, this.privSynthesizerConfig.SpeechServiceConfig.serialize());
  25142. return connection;
  25143. }
  25144. onAvatarEvent(_metadata) {
  25145. return;
  25146. }
  25147. onSynthesisStarted(_requestId) {
  25148. return;
  25149. }
  25150. onSynthesizing(_audio) {
  25151. return;
  25152. }
  25153. onSynthesisCancelled(_result) {
  25154. return;
  25155. }
  25156. onSynthesisCompleted(_result) {
  25157. return;
  25158. }
  25159. onWordBoundary(_wordBoundaryEventArgs) {
  25160. return;
  25161. }
  25162. onVisemeReceived(_visemeEventArgs) {
  25163. return;
  25164. }
  25165. onBookmarkReached(_bookmarkEventArgs) {
  25166. return;
  25167. }
  25168. }
  25169. exports.SynthesisAdapterBase = SynthesisAdapterBase;
  25170. SynthesisAdapterBase.telemetryDataEnabled = true;
  25171. /***/ }),
  25172. /* 277 */
  25173. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  25174. "use strict";
  25175. // Copyright (c) Microsoft Corporation. All rights reserved.
  25176. // Licensed under the MIT license.
  25177. Object.defineProperty(exports, "__esModule", ({ value: true }));
  25178. exports.AvatarSynthesisAdapter = void 0;
  25179. const Exports_js_1 = __webpack_require__(79);
  25180. const Exports_js_2 = __webpack_require__(2);
  25181. class AvatarSynthesisAdapter extends Exports_js_2.SynthesisAdapterBase {
  25182. constructor(authentication, connectionFactory, synthesizerConfig, avatarSynthesizer, avatarConfig) {
  25183. super(authentication, connectionFactory, synthesizerConfig, undefined);
  25184. this.privAvatarSynthesizer = avatarSynthesizer;
  25185. this.privSynthesizer = avatarSynthesizer;
  25186. this.privAvatarConfig = avatarConfig;
  25187. }
  25188. setSynthesisContextSynthesisSection() {
  25189. this.privSynthesisContext.setSynthesisSection(undefined);
  25190. }
  25191. setSpeechConfigSynthesisSection() {
  25192. this.privSynthesizerConfig.synthesisVideoSection = {
  25193. format: {
  25194. bitrate: this.privAvatarConfig.videoFormat?.bitrate,
  25195. codec: this.privAvatarConfig.videoFormat?.codec,
  25196. crop: {
  25197. bottomRight: {
  25198. x: this.privAvatarConfig.videoFormat?.cropRange?.bottomRight?.x,
  25199. y: this.privAvatarConfig.videoFormat?.cropRange?.bottomRight?.y,
  25200. },
  25201. topLeft: {
  25202. x: this.privAvatarConfig.videoFormat?.cropRange?.topLeft?.x,
  25203. y: this.privAvatarConfig.videoFormat?.cropRange?.topLeft?.y,
  25204. },
  25205. },
  25206. resolution: {
  25207. height: this.privAvatarConfig.videoFormat?.height,
  25208. width: this.privAvatarConfig.videoFormat?.width,
  25209. },
  25210. },
  25211. protocol: {
  25212. name: "WebRTC",
  25213. webrtcConfig: {
  25214. clientDescription: btoa(this.privSynthesizerConfig.parameters.getProperty(Exports_js_1.PropertyId.TalkingAvatarService_WebRTC_SDP)),
  25215. iceServers: this.privAvatarConfig.remoteIceServers ?? this.privAvatarSynthesizer.iceServers,
  25216. },
  25217. },
  25218. talkingAvatar: {
  25219. background: {
  25220. color: this.privAvatarConfig.backgroundColor,
  25221. image: {
  25222. url: this.privAvatarConfig.backgroundImage?.toString(),
  25223. }
  25224. },
  25225. character: this.privAvatarConfig.character,
  25226. customized: this.privAvatarConfig.customized,
  25227. style: this.privAvatarConfig.style,
  25228. useBuiltInVoice: this.privAvatarConfig.useBuiltInVoice,
  25229. }
  25230. };
  25231. }
  25232. onAvatarEvent(metadata) {
  25233. if (!!this.privAvatarSynthesizer.avatarEventReceived) {
  25234. const avatarEventArgs = new Exports_js_1.AvatarEventArgs(metadata.Data.Offset, metadata.Data.Name);
  25235. try {
  25236. this.privAvatarSynthesizer.avatarEventReceived(this.privAvatarSynthesizer, avatarEventArgs);
  25237. }
  25238. catch (error) {
  25239. // Not going to let errors in the event handler
  25240. // trip things up.
  25241. }
  25242. }
  25243. }
  25244. }
  25245. exports.AvatarSynthesisAdapter = AvatarSynthesisAdapter;
  25246. /***/ }),
  25247. /* 278 */
  25248. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  25249. "use strict";
  25250. // Copyright (c) Microsoft Corporation. All rights reserved.
  25251. // Licensed under the MIT license.
  25252. Object.defineProperty(exports, "__esModule", ({ value: true }));
  25253. exports.SpeechSynthesisAdapter = void 0;
  25254. const Exports_js_1 = __webpack_require__(79);
  25255. const Exports_js_2 = __webpack_require__(2);
  25256. class SpeechSynthesisAdapter extends Exports_js_2.SynthesisAdapterBase {
  25257. constructor(authentication, connectionFactory, synthesizerConfig, speechSynthesizer, audioDestination) {
  25258. super(authentication, connectionFactory, synthesizerConfig, audioDestination);
  25259. this.privSpeechSynthesizer = speechSynthesizer;
  25260. this.privSynthesizer = speechSynthesizer;
  25261. }
  25262. setSynthesisContextSynthesisSection() {
  25263. this.privSynthesisContext.setSynthesisSection(this.privSpeechSynthesizer);
  25264. }
  25265. onSynthesisStarted(requestId) {
  25266. const synthesisStartEventArgs = new Exports_js_1.SpeechSynthesisEventArgs(new Exports_js_1.SpeechSynthesisResult(requestId, Exports_js_1.ResultReason.SynthesizingAudioStarted));
  25267. if (!!this.privSpeechSynthesizer.synthesisStarted) {
  25268. this.privSpeechSynthesizer.synthesisStarted(this.privSpeechSynthesizer, synthesisStartEventArgs);
  25269. }
  25270. }
  25271. onSynthesizing(audio) {
  25272. if (!!this.privSpeechSynthesizer.synthesizing) {
  25273. try {
  25274. const audioWithHeader = this.privSynthesisTurn.audioOutputFormat.addHeader(audio);
  25275. const ev = new Exports_js_1.SpeechSynthesisEventArgs(new Exports_js_1.SpeechSynthesisResult(this.privSynthesisTurn.requestId, Exports_js_1.ResultReason.SynthesizingAudio, audioWithHeader));
  25276. this.privSpeechSynthesizer.synthesizing(this.privSpeechSynthesizer, ev);
  25277. }
  25278. catch (error) {
  25279. // Not going to let errors in the event handler
  25280. // trip things up.
  25281. }
  25282. }
  25283. }
  25284. onSynthesisCancelled(result) {
  25285. if (!!this.privSpeechSynthesizer.SynthesisCanceled) {
  25286. const cancelEvent = new Exports_js_1.SpeechSynthesisEventArgs(result);
  25287. try {
  25288. this.privSpeechSynthesizer.SynthesisCanceled(this.privSpeechSynthesizer, cancelEvent);
  25289. /* eslint-disable no-empty */
  25290. }
  25291. catch { }
  25292. }
  25293. }
  25294. onSynthesisCompleted(result) {
  25295. if (this.privSpeechSynthesizer.synthesisCompleted) {
  25296. try {
  25297. this.privSpeechSynthesizer.synthesisCompleted(this.privSpeechSynthesizer, new Exports_js_1.SpeechSynthesisEventArgs(result));
  25298. }
  25299. catch (e) {
  25300. // Not going to let errors in the event handler
  25301. // trip things up.
  25302. }
  25303. }
  25304. }
  25305. onWordBoundary(wordBoundaryEventArgs) {
  25306. if (!!this.privSpeechSynthesizer.wordBoundary) {
  25307. try {
  25308. this.privSpeechSynthesizer.wordBoundary(this.privSpeechSynthesizer, wordBoundaryEventArgs);
  25309. }
  25310. catch (error) {
  25311. // Not going to let errors in the event handler
  25312. // trip things up.
  25313. }
  25314. }
  25315. }
  25316. onVisemeReceived(visemeEventArgs) {
  25317. if (!!this.privSpeechSynthesizer.visemeReceived) {
  25318. try {
  25319. this.privSpeechSynthesizer.visemeReceived(this.privSpeechSynthesizer, visemeEventArgs);
  25320. }
  25321. catch (error) {
  25322. // Not going to let errors in the event handler
  25323. // trip things up.
  25324. }
  25325. }
  25326. }
  25327. onBookmarkReached(bookmarkEventArgs) {
  25328. if (!!this.privSpeechSynthesizer.bookmarkReached) {
  25329. try {
  25330. this.privSpeechSynthesizer.bookmarkReached(this.privSpeechSynthesizer, bookmarkEventArgs);
  25331. }
  25332. catch (error) {
  25333. // Not going to let errors in the event handler
  25334. // trip things up.
  25335. }
  25336. }
  25337. }
  25338. }
  25339. exports.SpeechSynthesisAdapter = SpeechSynthesisAdapter;
  25340. /***/ }),
  25341. /* 279 */
  25342. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  25343. "use strict";
  25344. Object.defineProperty(exports, "__esModule", ({ value: true }));
  25345. exports.SynthesisRestAdapter = void 0;
  25346. const Exports_js_1 = __webpack_require__(60);
  25347. const Exports_js_2 = __webpack_require__(79);
  25348. const ConnectionFactoryBase_js_1 = __webpack_require__(135);
  25349. const HeaderNames_js_1 = __webpack_require__(54);
  25350. /**
  25351. * Implements methods for speaker recognition classes, sending requests to endpoint
  25352. * and parsing response into expected format
  25353. * @class SynthesisRestAdapter
  25354. */
  25355. class SynthesisRestAdapter {
  25356. constructor(config, authentication) {
  25357. let endpoint = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint, undefined);
  25358. if (!endpoint) {
  25359. const region = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region, "westus");
  25360. const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);
  25361. endpoint = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, `https://${region}.tts.speech${hostSuffix}`);
  25362. }
  25363. this.privUri = `${endpoint}/cognitiveservices/voices/list`;
  25364. const options = Exports_js_1.RestConfigBase.requestOptions;
  25365. this.privRestAdapter = new Exports_js_1.RestMessageAdapter(options);
  25366. this.privAuthentication = authentication;
  25367. }
  25368. /**
  25369. * Sends list voices request to endpoint.
  25370. * @function
  25371. * @public
  25372. * @param connectionId - guid for connectionId
  25373. * @returns {Promise<IRestResponse>} rest response to status request
  25374. */
  25375. getVoicesList(connectionId) {
  25376. this.privRestAdapter.setHeaders(HeaderNames_js_1.HeaderNames.ConnectionId, connectionId);
  25377. return this.privAuthentication.fetch(connectionId).then((authInfo) => {
  25378. this.privRestAdapter.setHeaders(authInfo.headerName, authInfo.token);
  25379. return this.privRestAdapter.request(Exports_js_1.RestRequestType.Get, this.privUri);
  25380. });
  25381. }
  25382. }
  25383. exports.SynthesisRestAdapter = SynthesisRestAdapter;
  25384. /***/ }),
  25385. /* 280 */
  25386. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  25387. "use strict";
  25388. // Copyright (c) Microsoft Corporation. All rights reserved.
  25389. // Licensed under the MIT license.
  25390. Object.defineProperty(exports, "__esModule", ({ value: true }));
  25391. exports.SynthesizerConfig = exports.SynthesisServiceType = void 0;
  25392. const Exports_js_1 = __webpack_require__(2);
  25393. var SynthesisServiceType;
  25394. (function (SynthesisServiceType) {
  25395. SynthesisServiceType[SynthesisServiceType["Standard"] = 0] = "Standard";
  25396. SynthesisServiceType[SynthesisServiceType["Custom"] = 1] = "Custom";
  25397. })(SynthesisServiceType = exports.SynthesisServiceType || (exports.SynthesisServiceType = {}));
  25398. class SynthesizerConfig {
  25399. constructor(speechServiceConfig, parameters) {
  25400. this.privSynthesisServiceType = SynthesisServiceType.Standard;
  25401. this.avatarEnabled = false;
  25402. this.privSpeechServiceConfig = speechServiceConfig ? speechServiceConfig : new Exports_js_1.SpeechServiceConfig(new Exports_js_1.Context(null));
  25403. this.privParameters = parameters;
  25404. }
  25405. get parameters() {
  25406. return this.privParameters;
  25407. }
  25408. get synthesisServiceType() {
  25409. return this.privSynthesisServiceType;
  25410. }
  25411. set synthesisServiceType(value) {
  25412. this.privSynthesisServiceType = value;
  25413. }
  25414. set synthesisVideoSection(value) {
  25415. this.privSpeechServiceConfig.Context.synthesis = {
  25416. video: value
  25417. };
  25418. }
  25419. get SpeechServiceConfig() {
  25420. return this.privSpeechServiceConfig;
  25421. }
  25422. }
  25423. exports.SynthesizerConfig = SynthesizerConfig;
  25424. /***/ }),
  25425. /* 281 */
  25426. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  25427. "use strict";
  25428. // Copyright (c) Microsoft Corporation. All rights reserved.
  25429. // Licensed under the MIT license.
  25430. Object.defineProperty(exports, "__esModule", ({ value: true }));
  25431. exports.SynthesisContext = void 0;
  25432. const Exports_js_1 = __webpack_require__(79);
  25433. /**
  25434. * Represents the JSON used in the synthesis.context message sent to the speech service.
  25435. * The dynamic grammar is always refreshed from the encapsulated dynamic grammar object.
  25436. */
  25437. class SynthesisContext {
  25438. constructor() {
  25439. this.privContext = {};
  25440. }
  25441. /**
  25442. * Adds a section to the synthesis.context object.
  25443. * @param sectionName Name of the section to add.
  25444. * @param value JSON serializable object that represents the value.
  25445. */
  25446. setSection(sectionName, value) {
  25447. this.privContext[sectionName] = value;
  25448. }
  25449. /**
  25450. * Sets the audio output format for synthesis context generation.
  25451. * @param format {AudioOutputFormatImpl} the output format
  25452. */
  25453. set audioOutputFormat(format) {
  25454. this.privAudioOutputFormat = format;
  25455. }
  25456. toJSON() {
  25457. return JSON.stringify(this.privContext);
  25458. }
  25459. setSynthesisSection(speechSynthesizer) {
  25460. const synthesisSection = this.buildSynthesisContext(speechSynthesizer);
  25461. this.setSection("synthesis", synthesisSection);
  25462. }
  25463. buildSynthesisContext(speechSynthesizer) {
  25464. return {
  25465. audio: {
  25466. metadataOptions: {
  25467. bookmarkEnabled: (!!speechSynthesizer?.bookmarkReached),
  25468. punctuationBoundaryEnabled: speechSynthesizer?.properties.getProperty(Exports_js_1.PropertyId.SpeechServiceResponse_RequestPunctuationBoundary, (!!speechSynthesizer?.wordBoundary)),
  25469. sentenceBoundaryEnabled: speechSynthesizer?.properties.getProperty(Exports_js_1.PropertyId.SpeechServiceResponse_RequestSentenceBoundary, false),
  25470. sessionEndEnabled: true,
  25471. visemeEnabled: (!!speechSynthesizer?.visemeReceived),
  25472. wordBoundaryEnabled: speechSynthesizer?.properties.getProperty(Exports_js_1.PropertyId.SpeechServiceResponse_RequestWordBoundary, (!!speechSynthesizer?.wordBoundary)),
  25473. },
  25474. outputFormat: this.privAudioOutputFormat.requestAudioFormatString,
  25475. },
  25476. language: {
  25477. autoDetection: speechSynthesizer?.autoDetectSourceLanguage
  25478. }
  25479. };
  25480. }
  25481. }
  25482. exports.SynthesisContext = SynthesisContext;
  25483. /***/ }),
  25484. /* 282 */
  25485. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  25486. "use strict";
  25487. // Copyright (c) Microsoft Corporation. All rights reserved.
  25488. // Licensed under the MIT license.
  25489. Object.defineProperty(exports, "__esModule", ({ value: true }));
  25490. exports.SpeakerRecognitionConfig = void 0;
  25491. const Exports_js_1 = __webpack_require__(2);
  25492. class SpeakerRecognitionConfig {
  25493. constructor(context, parameters) {
  25494. this.privContext = context ? context : new Exports_js_1.Context(null);
  25495. this.privParameters = parameters;
  25496. }
  25497. get parameters() {
  25498. return this.privParameters;
  25499. }
  25500. get Context() {
  25501. return this.privContext;
  25502. }
  25503. }
  25504. exports.SpeakerRecognitionConfig = SpeakerRecognitionConfig;
  25505. /***/ }),
  25506. /* 283 */
  25507. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  25508. "use strict";
  25509. // Copyright (c) Microsoft Corporation. All rights reserved.
  25510. // Licensed under the MIT license.
  25511. Object.defineProperty(exports, "__esModule", ({ value: true }));
  25512. exports.SpeakerServiceRecognizer = void 0;
  25513. const Exports_js_1 = __webpack_require__(60);
  25514. const Exports_js_2 = __webpack_require__(4);
  25515. const Exports_js_3 = __webpack_require__(79);
  25516. const Exports_js_4 = __webpack_require__(2);
  25517. const SpeechConnectionMessage_Internal_js_1 = __webpack_require__(207);
  25518. // eslint-disable-next-line max-classes-per-file
  25519. class SpeakerServiceRecognizer extends Exports_js_4.ServiceRecognizerBase {
  25520. constructor(authentication, connectionFactory, audioSource, recognizerConfig, recognizer) {
  25521. super(authentication, connectionFactory, audioSource, recognizerConfig, recognizer);
  25522. this.privSpeakerRecognizer = recognizer;
  25523. this.privSpeakerAudioSource = audioSource;
  25524. this.recognizeSpeaker = (model) => this.recognizeSpeakerOnce(model);
  25525. this.sendPrePayloadJSONOverride = () => this.noOp();
  25526. }
  25527. processTypeSpecificMessages(connectionMessage) {
  25528. let processed = false;
  25529. const resultProps = new Exports_js_3.PropertyCollection();
  25530. if (connectionMessage.messageType === Exports_js_2.MessageType.Text) {
  25531. resultProps.setProperty(Exports_js_3.PropertyId.SpeechServiceResponse_JsonResult, connectionMessage.textBody);
  25532. }
  25533. switch (connectionMessage.path.toLowerCase()) {
  25534. case "speaker.response":
  25535. const response = JSON.parse(connectionMessage.textBody);
  25536. let result;
  25537. if (response.status.statusCode.toLowerCase() !== "success") {
  25538. result = new Exports_js_3.SpeakerRecognitionResult(response, Exports_js_3.ResultReason.Canceled, Exports_js_3.CancellationErrorCode.ServiceError, response.status.reason);
  25539. }
  25540. else {
  25541. result = new Exports_js_3.SpeakerRecognitionResult(response, Exports_js_3.ResultReason.RecognizedSpeaker);
  25542. }
  25543. if (!!this.privResultDeferral) {
  25544. this.privResultDeferral.resolve(result);
  25545. }
  25546. processed = true;
  25547. break;
  25548. default:
  25549. break;
  25550. }
  25551. const defferal = new Exports_js_2.Deferred();
  25552. defferal.resolve(processed);
  25553. return defferal.promise;
  25554. }
  25555. // Cancels recognition.
  25556. cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  25557. const properties = new Exports_js_3.PropertyCollection();
  25558. properties.setProperty(Exports_js_4.CancellationErrorCodePropertyName, Exports_js_3.CancellationErrorCode[errorCode]);
  25559. if (!!this.privResultDeferral) {
  25560. const result = new Exports_js_3.SpeakerRecognitionResult({
  25561. scenario: this.privSpeakerModel.scenario,
  25562. status: { statusCode: error, reason: error }
  25563. }, Exports_js_3.ResultReason.Canceled, errorCode, error);
  25564. try {
  25565. this.privResultDeferral.resolve(result);
  25566. }
  25567. catch (error) {
  25568. this.privResultDeferral.reject(error);
  25569. }
  25570. }
  25571. }
  25572. async recognizeSpeakerOnce(model) {
  25573. this.privSpeakerModel = model;
  25574. this.voiceProfileType = model.scenario;
  25575. if (!this.privResultDeferral) {
  25576. this.privResultDeferral = new Exports_js_2.Deferred();
  25577. }
  25578. this.privRequestSession.startNewRecognition();
  25579. this.privRequestSession.listenForServiceTelemetry(this.privSpeakerAudioSource.events);
  25580. this.privRecognizerConfig.parameters.setProperty(Exports_js_3.PropertyId.Speech_SessionId, this.privRequestSession.sessionId);
  25581. // Start the connection to the service. The promise this will create is stored and will be used by configureConnection().
  25582. const conPromise = this.connectImpl();
  25583. const preAudioPromise = this.sendPreAudioMessages(this.extractSpeakerContext(model));
  25584. const node = await this.privSpeakerAudioSource.attach(this.privRequestSession.audioNodeId);
  25585. const format = await this.privSpeakerAudioSource.format;
  25586. const deviceInfo = await this.privSpeakerAudioSource.deviceInfo;
  25587. const audioNode = new Exports_js_1.ReplayableAudioNode(node, format.avgBytesPerSec);
  25588. await this.privRequestSession.onAudioSourceAttachCompleted(audioNode, false);
  25589. this.privRecognizerConfig.SpeechServiceConfig.Context.audio = { source: deviceInfo };
  25590. try {
  25591. await conPromise;
  25592. await preAudioPromise;
  25593. }
  25594. catch (err) {
  25595. this.cancelRecognition(this.privRequestSession.sessionId, this.privRequestSession.requestId, Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.ConnectionFailure, err);
  25596. }
  25597. const sessionStartEventArgs = new Exports_js_3.SessionEventArgs(this.privRequestSession.sessionId);
  25598. if (!!this.privRecognizer.sessionStarted) {
  25599. this.privRecognizer.sessionStarted(this.privRecognizer, sessionStartEventArgs);
  25600. }
  25601. void this.receiveMessage();
  25602. const audioSendPromise = this.sendAudio(audioNode);
  25603. // /* eslint-disable no-empty */
  25604. audioSendPromise.then(() => { }, (error) => {
  25605. this.cancelRecognition(this.privRequestSession.sessionId, this.privRequestSession.requestId, Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.RuntimeError, error);
  25606. });
  25607. return this.privResultDeferral.promise;
  25608. }
  25609. async sendPreAudioMessages(context) {
  25610. const connection = await this.fetchConnection();
  25611. await this.sendSpeakerRecognition(connection, context);
  25612. // await this.sendWaveHeader(connection);
  25613. }
  25614. async sendSpeakerRecognition(connection, context) {
  25615. const speakerContextJson = JSON.stringify(context);
  25616. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, "speaker.context", this.privRequestSession.requestId, "application/json; charset=utf-8", speakerContextJson));
  25617. }
  25618. extractSpeakerContext(model) {
  25619. return {
  25620. features: {
  25621. interimResult: "enabled",
  25622. progressiveDetection: "disabled",
  25623. },
  25624. profileIds: model.profileIds,
  25625. scenario: model.scenario,
  25626. };
  25627. }
  25628. }
  25629. exports.SpeakerServiceRecognizer = SpeakerServiceRecognizer;
  25630. /***/ }),
  25631. /* 284 */
  25632. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  25633. "use strict";
  25634. // Copyright (c) Microsoft Corporation. All rights reserved.
  25635. // Licensed under the MIT license.
  25636. Object.defineProperty(exports, "__esModule", ({ value: true }));
  25637. exports.VoiceServiceRecognizer = void 0;
  25638. const Exports_js_1 = __webpack_require__(60);
  25639. const Exports_js_2 = __webpack_require__(4);
  25640. const Exports_js_3 = __webpack_require__(79);
  25641. const Exports_js_4 = __webpack_require__(2);
  25642. const SpeechConnectionMessage_Internal_js_1 = __webpack_require__(207);
  25643. // eslint-disable-next-line max-classes-per-file
  25644. class VoiceServiceRecognizer extends Exports_js_4.ServiceRecognizerBase {
  25645. constructor(authentication, connectionFactory, audioSource, recognizerConfig, recognizer) {
  25646. super(authentication, connectionFactory, audioSource, recognizerConfig, recognizer);
  25647. this.privDeferralMap = new Exports_js_2.DeferralMap();
  25648. this.privSpeakerAudioSource = audioSource;
  25649. this.sendPrePayloadJSONOverride = () => this.noOp();
  25650. }
  25651. set SpeakerAudioSource(audioSource) {
  25652. this.privSpeakerAudioSource = audioSource;
  25653. }
  25654. processTypeSpecificMessages(connectionMessage) {
  25655. let processed = false;
  25656. const resultProps = new Exports_js_3.PropertyCollection();
  25657. if (connectionMessage.messageType === Exports_js_2.MessageType.Text) {
  25658. resultProps.setProperty(Exports_js_3.PropertyId.SpeechServiceResponse_JsonResult, connectionMessage.textBody);
  25659. }
  25660. switch (connectionMessage.path.toLowerCase()) {
  25661. // Profile management response for create, fetch, delete, reset
  25662. case "speaker.profiles":
  25663. const response = JSON.parse(connectionMessage.textBody);
  25664. switch (response.operation.toLowerCase()) {
  25665. case "create":
  25666. this.handleCreateResponse(response, connectionMessage.requestId);
  25667. break;
  25668. case "delete":
  25669. case "reset":
  25670. this.handleResultResponse(response, connectionMessage.requestId);
  25671. break;
  25672. case "fetch":
  25673. const enrollmentResponse = JSON.parse(connectionMessage.textBody);
  25674. this.handleFetchResponse(enrollmentResponse, connectionMessage.requestId);
  25675. break;
  25676. default:
  25677. break;
  25678. }
  25679. processed = true;
  25680. break;
  25681. // Activation and authorization phrase response
  25682. case "speaker.phrases":
  25683. const phraseResponse = JSON.parse(connectionMessage.textBody);
  25684. this.handlePhrasesResponse(phraseResponse, connectionMessage.requestId);
  25685. processed = true;
  25686. break;
  25687. // Enrollment response
  25688. case "speaker.profile.enrollment":
  25689. const enrollmentResponse = JSON.parse(connectionMessage.textBody);
  25690. const result = new Exports_js_3.VoiceProfileEnrollmentResult(this.enrollmentReasonFrom(!!enrollmentResponse.enrollment ? enrollmentResponse.enrollment.enrollmentStatus : enrollmentResponse.status.statusCode), !!enrollmentResponse.enrollment ? JSON.stringify(enrollmentResponse.enrollment) : undefined, enrollmentResponse.status.reason);
  25691. if (!!this.privDeferralMap.getId(connectionMessage.requestId)) {
  25692. this.privDeferralMap.complete(connectionMessage.requestId, result);
  25693. }
  25694. this.privRequestSession.onSpeechEnded();
  25695. processed = true;
  25696. break;
  25697. default:
  25698. break;
  25699. }
  25700. const defferal = new Exports_js_2.Deferred();
  25701. defferal.resolve(processed);
  25702. return defferal.promise;
  25703. }
  25704. // Cancels recognition.
  25705. cancelRecognition(sessionId, requestId, cancellationReason, errorCode, error) {
  25706. const properties = new Exports_js_3.PropertyCollection();
  25707. // const enrollmentResponse: EnrollmentResponse = JSON.parse(connectionMessage.textBody) as EnrollmentResponse;
  25708. properties.setProperty(Exports_js_4.CancellationErrorCodePropertyName, Exports_js_3.CancellationErrorCode[errorCode]);
  25709. const result = new Exports_js_3.VoiceProfileEnrollmentResult(Exports_js_3.ResultReason.Canceled, error, error);
  25710. if (!!this.privDeferralMap.getId(requestId)) {
  25711. this.privDeferralMap.complete(requestId, result);
  25712. }
  25713. }
  25714. async createProfile(profileType, locale) {
  25715. // Start the connection to the service. The promise this will create is stored and will be used by configureConnection().
  25716. this.voiceProfileType = profileType.toString();
  25717. const conPromise = this.connectImpl();
  25718. try {
  25719. const createProfileDeferral = new Exports_js_2.Deferred();
  25720. await conPromise;
  25721. await this.sendCreateProfile(createProfileDeferral, profileType, locale);
  25722. void this.receiveMessage();
  25723. return createProfileDeferral.promise;
  25724. }
  25725. catch (err) {
  25726. throw err;
  25727. }
  25728. }
  25729. async resetProfile(profile) {
  25730. this.voiceProfileType = profile.profileType.toString();
  25731. return this.sendCommonRequest("reset", profile.profileType, profile);
  25732. }
  25733. async deleteProfile(profile) {
  25734. this.voiceProfileType = profile.profileType.toString();
  25735. return this.sendCommonRequest("delete", profile.profileType, profile);
  25736. }
  25737. async retrieveEnrollmentResult(profile) {
  25738. this.voiceProfileType = profile.profileType.toString();
  25739. this.privExpectedProfileId = profile.profileId;
  25740. return this.sendCommonRequest("fetch", profile.profileType, profile);
  25741. }
  25742. async getAllProfiles(profileType) {
  25743. this.voiceProfileType = profileType.toString();
  25744. return this.sendCommonRequest("fetch", profileType);
  25745. }
  25746. async getActivationPhrases(profileType, lang) {
  25747. this.voiceProfileType = profileType.toString();
  25748. // Start the connection to the service. The promise this will create is stored and will be used by configureConnection().
  25749. const conPromise = this.connectImpl();
  25750. try {
  25751. const getPhrasesDeferral = new Exports_js_2.Deferred();
  25752. await conPromise;
  25753. await this.sendPhrasesRequest(getPhrasesDeferral, profileType, lang);
  25754. void this.receiveMessage();
  25755. return getPhrasesDeferral.promise;
  25756. }
  25757. catch (err) {
  25758. throw err;
  25759. }
  25760. }
  25761. async enrollProfile(profile) {
  25762. this.voiceProfileType = profile.profileType.toString();
  25763. const enrollmentDeferral = new Exports_js_2.Deferred();
  25764. this.privRequestSession.startNewRecognition();
  25765. this.privRequestSession.listenForServiceTelemetry(this.privSpeakerAudioSource.events);
  25766. this.privRecognizerConfig.parameters.setProperty(Exports_js_3.PropertyId.Speech_SessionId, this.privRequestSession.sessionId);
  25767. // Start the connection to the service. The promise this will create is stored and will be used by configureConnection().
  25768. const conPromise = this.connectImpl();
  25769. const preAudioPromise = this.sendPreAudioMessages(profile, enrollmentDeferral);
  25770. const node = await this.privSpeakerAudioSource.attach(this.privRequestSession.audioNodeId);
  25771. const format = await this.privSpeakerAudioSource.format;
  25772. const deviceInfo = await this.privSpeakerAudioSource.deviceInfo;
  25773. const audioNode = new Exports_js_1.ReplayableAudioNode(node, format.avgBytesPerSec);
  25774. await this.privRequestSession.onAudioSourceAttachCompleted(audioNode, false);
  25775. this.privRecognizerConfig.SpeechServiceConfig.Context.audio = { source: deviceInfo };
  25776. try {
  25777. await conPromise;
  25778. await preAudioPromise;
  25779. }
  25780. catch (err) {
  25781. this.cancelRecognition(this.privRequestSession.sessionId, this.privRequestSession.requestId, Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.ConnectionFailure, err);
  25782. }
  25783. const sessionStartEventArgs = new Exports_js_3.SessionEventArgs(this.privRequestSession.sessionId);
  25784. if (!!this.privRecognizer.sessionStarted) {
  25785. this.privRecognizer.sessionStarted(this.privRecognizer, sessionStartEventArgs);
  25786. }
  25787. void this.receiveMessage();
  25788. const audioSendPromise = this.sendAudio(audioNode);
  25789. // /* eslint-disable no-empty */
  25790. audioSendPromise.then(() => { }, (error) => {
  25791. this.cancelRecognition(this.privRequestSession.sessionId, this.privRequestSession.requestId, Exports_js_3.CancellationReason.Error, Exports_js_3.CancellationErrorCode.RuntimeError, error);
  25792. });
  25793. return enrollmentDeferral.promise;
  25794. }
  25795. async sendPreAudioMessages(profile, enrollmentDeferral) {
  25796. const connection = await this.fetchConnection();
  25797. this.privRequestSession.onSpeechContext();
  25798. this.privDeferralMap.add(this.privRequestSession.requestId, enrollmentDeferral);
  25799. await this.sendBaseRequest(connection, "enroll", this.scenarioFrom(profile.profileType), profile);
  25800. }
  25801. async sendPhrasesRequest(getPhrasesDeferral, profileType, locale) {
  25802. const connection = await this.fetchConnection();
  25803. this.privRequestSession.onSpeechContext();
  25804. this.privDeferralMap.add(this.privRequestSession.requestId, getPhrasesDeferral);
  25805. const scenario = this.scenarioFrom(profileType);
  25806. const profileCreateRequest = {
  25807. locale,
  25808. scenario,
  25809. };
  25810. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, "speaker.profile.phrases", this.privRequestSession.requestId, "application/json; charset=utf-8", JSON.stringify(profileCreateRequest)));
  25811. }
  25812. async sendCreateProfile(createProfileDeferral, profileType, locale) {
  25813. const connection = await this.fetchConnection();
  25814. this.privRequestSession.onSpeechContext();
  25815. this.privDeferralMap.add(this.privRequestSession.requestId, createProfileDeferral);
  25816. const scenario = profileType === Exports_js_3.VoiceProfileType.TextIndependentIdentification ? "TextIndependentIdentification" :
  25817. profileType === Exports_js_3.VoiceProfileType.TextIndependentVerification ? "TextIndependentVerification" : "TextDependentVerification";
  25818. const profileCreateRequest = {
  25819. locale,
  25820. number: "1",
  25821. scenario,
  25822. };
  25823. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, "speaker.profile.create", this.privRequestSession.requestId, "application/json; charset=utf-8", JSON.stringify(profileCreateRequest)));
  25824. }
  25825. async sendCommonRequest(operation, profileType, profile = undefined) {
  25826. // Start the connection to the service. The promise this will create is stored and will be used by configureConnection().
  25827. const conPromise = this.connectImpl();
  25828. try {
  25829. const deferral = new Exports_js_2.Deferred();
  25830. this.privRequestSession.onSpeechContext();
  25831. await conPromise;
  25832. const connection = await this.fetchConnection();
  25833. this.privDeferralMap.add(this.privRequestSession.requestId, deferral);
  25834. await this.sendBaseRequest(connection, operation, this.scenarioFrom(profileType), profile);
  25835. void this.receiveMessage();
  25836. return deferral.promise;
  25837. }
  25838. catch (err) {
  25839. throw err;
  25840. }
  25841. }
  25842. async sendBaseRequest(connection, operation, scenario, profile) {
  25843. const profileRequest = {
  25844. scenario
  25845. };
  25846. if (!!profile) {
  25847. profileRequest.profileIds = [profile.profileId];
  25848. }
  25849. else {
  25850. profileRequest.maxPageSize = -1;
  25851. }
  25852. return connection.send(new SpeechConnectionMessage_Internal_js_1.SpeechConnectionMessage(Exports_js_2.MessageType.Text, `speaker.profile.${operation}`, this.privRequestSession.requestId, "application/json; charset=utf-8", JSON.stringify(profileRequest)));
  25853. }
  25854. extractSpeakerContext(model) {
  25855. return {
  25856. features: {
  25857. interimResult: "enabled",
  25858. progressiveDetection: "disabled",
  25859. },
  25860. profileIds: model.profileIds,
  25861. scenario: model.scenario,
  25862. };
  25863. }
  25864. handlePhrasesResponse(response, requestId) {
  25865. if (!!this.privDeferralMap.getId(requestId)) {
  25866. if (response.status.statusCode.toLowerCase() !== "success") {
  25867. const reason = Exports_js_3.ResultReason.Canceled;
  25868. const result = new Exports_js_3.VoiceProfilePhraseResult(reason, response.status.statusCode, response.passPhraseType, []);
  25869. this.privDeferralMap.complete(requestId, result);
  25870. }
  25871. else if (!!response.phrases && response.phrases.length > 0) {
  25872. const reason = Exports_js_3.ResultReason.EnrollingVoiceProfile;
  25873. const result = new Exports_js_3.VoiceProfilePhraseResult(reason, response.status.statusCode, response.passPhraseType, response.phrases);
  25874. this.privDeferralMap.complete(requestId, result);
  25875. }
  25876. else {
  25877. throw new Error("Voice Profile get activation phrases failed, no phrases received");
  25878. }
  25879. }
  25880. else {
  25881. throw new Error(`Voice Profile get activation phrases request for requestID ${requestId} not found`);
  25882. }
  25883. }
  25884. handleCreateResponse(response, requestId) {
  25885. if (!!response.profiles && response.profiles.length > 0) {
  25886. if (!!this.privDeferralMap.getId(requestId)) {
  25887. const profileIds = response.profiles.map((profile) => profile.profileId);
  25888. this.privDeferralMap.complete(requestId, profileIds);
  25889. }
  25890. else {
  25891. throw new Error(`Voice Profile create request for requestID ${requestId} not found`);
  25892. }
  25893. }
  25894. else {
  25895. throw new Error("Voice Profile create failed, no profile id received");
  25896. }
  25897. }
  25898. handleResultResponse(response, requestId) {
  25899. if (!!this.privDeferralMap.getId(requestId)) {
  25900. const successReason = response.operation.toLowerCase() === "delete" ? Exports_js_3.ResultReason.DeletedVoiceProfile : Exports_js_3.ResultReason.ResetVoiceProfile;
  25901. const reason = response.status.statusCode.toLowerCase() === "success" ? successReason : Exports_js_3.ResultReason.Canceled;
  25902. const result = new Exports_js_3.VoiceProfileResult(reason, `statusCode: ${response.status.statusCode}, errorDetails: ${response.status.reason}`);
  25903. this.privDeferralMap.complete(requestId, result);
  25904. }
  25905. else {
  25906. throw new Error(`Voice Profile create request for requestID ${requestId} not found`);
  25907. }
  25908. }
  25909. handleFetchResponse(enrollmentResponse, requestId) {
  25910. if (!!this.privDeferralMap.getId(requestId) && !!enrollmentResponse.profiles[0]) {
  25911. if (!!this.privExpectedProfileId && enrollmentResponse.profiles.length === 1 && enrollmentResponse.profiles[0].profileId === this.privExpectedProfileId) {
  25912. this.privExpectedProfileId = undefined;
  25913. const profileInfo = enrollmentResponse.profiles[0];
  25914. const result = new Exports_js_3.VoiceProfileEnrollmentResult(this.enrollmentReasonFrom(profileInfo.enrollmentStatus), JSON.stringify(profileInfo), enrollmentResponse.status.reason);
  25915. this.privDeferralMap.complete(requestId, result);
  25916. }
  25917. else if (enrollmentResponse.profiles.length > 0) {
  25918. const iProfiles = enrollmentResponse.profiles;
  25919. const profileResults = [];
  25920. for (const profile of iProfiles) {
  25921. profileResults.push(new Exports_js_3.VoiceProfileEnrollmentResult(this.enrollmentReasonFrom(profile.enrollmentStatus), JSON.stringify(profile), enrollmentResponse.status.reason));
  25922. }
  25923. this.privDeferralMap.complete(requestId, profileResults);
  25924. }
  25925. }
  25926. else {
  25927. throw new Error(`Voice Profile fetch request for requestID ${requestId} not found`);
  25928. }
  25929. }
  25930. enrollmentReasonFrom(statusCode) {
  25931. switch (statusCode.toLowerCase()) {
  25932. case "enrolled":
  25933. return Exports_js_3.ResultReason.EnrolledVoiceProfile;
  25934. case "invalidlocale":
  25935. case "invalidphrase":
  25936. case "invalidaudioformat":
  25937. case "invalidscenario":
  25938. case "invalidprofilecount":
  25939. case "invalidoperation":
  25940. case "audiotooshort":
  25941. case "audiotoolong":
  25942. case "toomanyenrollments":
  25943. case "storageconflict":
  25944. case "profilenotfound":
  25945. case "incompatibleprofiles":
  25946. case "incompleteenrollment":
  25947. return Exports_js_3.ResultReason.Canceled;
  25948. default:
  25949. return Exports_js_3.ResultReason.EnrollingVoiceProfile;
  25950. }
  25951. }
  25952. scenarioFrom(profileType) {
  25953. return profileType === Exports_js_3.VoiceProfileType.TextIndependentIdentification ? "TextIndependentIdentification" :
  25954. profileType === Exports_js_3.VoiceProfileType.TextIndependentVerification ? "TextIndependentVerification" : "TextDependentVerification";
  25955. }
  25956. }
  25957. exports.VoiceServiceRecognizer = VoiceServiceRecognizer;
  25958. /***/ }),
  25959. /* 285 */
  25960. /***/ ((__unused_webpack_module, exports) => {
  25961. "use strict";
  25962. // Copyright (c) Microsoft Corporation. All rights reserved.
  25963. // Licensed under the MIT license.
  25964. Object.defineProperty(exports, "__esModule", ({ value: true }));
  25965. exports.type = exports.connectivity = exports.Device = exports.OS = exports.System = exports.Context = exports.SpeechServiceConfig = void 0;
  25966. /* eslint-disable max-classes-per-file */
  25967. // The config is serialized and sent as the Speech.Config
  25968. class SpeechServiceConfig {
  25969. constructor(context) {
  25970. this.context = context;
  25971. }
  25972. serialize() {
  25973. return JSON.stringify(this, (key, value) => {
  25974. if (value && typeof value === "object" && !Array.isArray(value)) {
  25975. const replacement = {};
  25976. for (const k in value) {
  25977. if (Object.hasOwnProperty.call(value, k)) {
  25978. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  25979. replacement[k && k.charAt(0).toLowerCase() + k.substring(1)] = value[k];
  25980. }
  25981. }
  25982. return replacement;
  25983. }
  25984. return value;
  25985. });
  25986. }
  25987. get Context() {
  25988. return this.context;
  25989. }
  25990. get Recognition() {
  25991. return this.recognition;
  25992. }
  25993. set Recognition(value) {
  25994. this.recognition = value.toLowerCase();
  25995. }
  25996. }
  25997. exports.SpeechServiceConfig = SpeechServiceConfig;
  25998. class Context {
  25999. constructor(os) {
  26000. this.system = new System();
  26001. this.os = os;
  26002. }
  26003. }
  26004. exports.Context = Context;
  26005. class System {
  26006. constructor() {
  26007. // Note: below will be patched for official builds.
  26008. const SPEECHSDK_CLIENTSDK_VERSION = "1.44.0";
  26009. this.name = "SpeechSDK";
  26010. this.version = SPEECHSDK_CLIENTSDK_VERSION;
  26011. this.build = "JavaScript";
  26012. this.lang = "JavaScript";
  26013. }
  26014. }
  26015. exports.System = System;
  26016. class OS {
  26017. constructor(platform, name, version) {
  26018. this.platform = platform;
  26019. this.name = name;
  26020. this.version = version;
  26021. }
  26022. }
  26023. exports.OS = OS;
  26024. class Device {
  26025. constructor(manufacturer, model, version) {
  26026. this.manufacturer = manufacturer;
  26027. this.model = model;
  26028. this.version = version;
  26029. }
  26030. }
  26031. exports.Device = Device;
  26032. var connectivity;
  26033. (function (connectivity) {
  26034. connectivity["Bluetooth"] = "Bluetooth";
  26035. connectivity["Wired"] = "Wired";
  26036. connectivity["WiFi"] = "WiFi";
  26037. connectivity["Cellular"] = "Cellular";
  26038. connectivity["InBuilt"] = "InBuilt";
  26039. connectivity["Unknown"] = "Unknown";
  26040. })(connectivity = exports.connectivity || (exports.connectivity = {}));
  26041. var type;
  26042. (function (type) {
  26043. type["Phone"] = "Phone";
  26044. type["Speaker"] = "Speaker";
  26045. type["Car"] = "Car";
  26046. type["Headset"] = "Headset";
  26047. type["Thermostat"] = "Thermostat";
  26048. type["Microphones"] = "Microphones";
  26049. type["Deskphone"] = "Deskphone";
  26050. type["RemoteControl"] = "RemoteControl";
  26051. type["Unknown"] = "Unknown";
  26052. type["File"] = "File";
  26053. type["Stream"] = "Stream";
  26054. })(type = exports.type || (exports.type = {}));
  26055. /***/ })
  26056. /******/ ]);
  26057. /************************************************************************/
  26058. /******/ // The module cache
  26059. /******/ var __webpack_module_cache__ = {};
  26060. /******/
  26061. /******/ // The require function
  26062. /******/ function __webpack_require__(moduleId) {
  26063. /******/ // Check if module is in cache
  26064. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  26065. /******/ if (cachedModule !== undefined) {
  26066. /******/ return cachedModule.exports;
  26067. /******/ }
  26068. /******/ // Create a new module (and put it into the cache)
  26069. /******/ var module = __webpack_module_cache__[moduleId] = {
  26070. /******/ // no module.id needed
  26071. /******/ // no module.loaded needed
  26072. /******/ exports: {}
  26073. /******/ };
  26074. /******/
  26075. /******/ // Execute the module function
  26076. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  26077. /******/
  26078. /******/ // Return the exports of the module
  26079. /******/ return module.exports;
  26080. /******/ }
  26081. /******/
  26082. /************************************************************************/
  26083. /******/ /* webpack/runtime/compat get default export */
  26084. /******/ (() => {
  26085. /******/ // getDefaultExport function for compatibility with non-harmony modules
  26086. /******/ __webpack_require__.n = (module) => {
  26087. /******/ var getter = module && module.__esModule ?
  26088. /******/ () => (module['default']) :
  26089. /******/ () => (module);
  26090. /******/ __webpack_require__.d(getter, { a: getter });
  26091. /******/ return getter;
  26092. /******/ };
  26093. /******/ })();
  26094. /******/
  26095. /******/ /* webpack/runtime/define property getters */
  26096. /******/ (() => {
  26097. /******/ // define getter functions for harmony exports
  26098. /******/ __webpack_require__.d = (exports, definition) => {
  26099. /******/ for(var key in definition) {
  26100. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  26101. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  26102. /******/ }
  26103. /******/ }
  26104. /******/ };
  26105. /******/ })();
  26106. /******/
  26107. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  26108. /******/ (() => {
  26109. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  26110. /******/ })();
  26111. /******/
  26112. /******/ /* webpack/runtime/make namespace object */
  26113. /******/ (() => {
  26114. /******/ // define __esModule on exports
  26115. /******/ __webpack_require__.r = (exports) => {
  26116. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  26117. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  26118. /******/ }
  26119. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  26120. /******/ };
  26121. /******/ })();
  26122. /******/
  26123. /************************************************************************/
  26124. var __webpack_exports__ = {};
  26125. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  26126. (() => {
  26127. "use strict";
  26128. __webpack_require__.r(__webpack_exports__);
  26129. /* harmony import */ var _distrib_lib_microsoft_cognitiveservices_speech_sdk_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
  26130. /* harmony import */ var _distrib_lib_microsoft_cognitiveservices_speech_sdk_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_distrib_lib_microsoft_cognitiveservices_speech_sdk_js__WEBPACK_IMPORTED_MODULE_0__);
  26131. // Copyright (c) Microsoft Corporation. All rights reserved.
  26132. // Licensed under the MIT license.
  26133. window.SpeechSDK = _distrib_lib_microsoft_cognitiveservices_speech_sdk_js__WEBPACK_IMPORTED_MODULE_0__;
  26134. })();
  26135. /******/ })()
  26136. ;
  26137. //# sourceMappingURL=microsoft.cognitiveservices.speech.sdk.bundle.js.map