interview-question.js 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_config = require("../../common/config.js");
  4. const _sfc_main = {
  5. name: "IdentityVerify",
  6. data() {
  7. return {
  8. loading: false,
  9. responses: [],
  10. processedResponses: [],
  11. assistantResponse: "",
  12. audioTranscript: "",
  13. videoPlaying: false,
  14. showDebugInfo: false,
  15. // 设置为true可以显示调试信息
  16. videoUrl: "https://data.qicai321.com/minlong/1809457d-30c5-40bb-b6d8-a8c2e8e1e9e2.mp4",
  17. //'http://121.36.251.245:9000/minlong/tenant_1/general_uploads/abdaa6fda8494e3a8613304743ed0433.mp4', // 用于存储AI数字人视频URL
  18. showReplayButton: false,
  19. cameraStream: null,
  20. // 存储摄像头流
  21. cameraError: null,
  22. // 存储摄像头错误信息
  23. useMiniProgramCameraComponent: false,
  24. // 添加小程序相机组件标志
  25. cameraContext: null,
  26. // 添加相机上下文
  27. currentSubtitle: "",
  28. subtitles: [
  29. {
  30. startTime: 0,
  31. // 开始时间(秒)
  32. endTime: 6,
  33. // 结束时间(秒)
  34. text: "您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?"
  35. }
  36. ],
  37. // secondVideoSubtitles: [
  38. // {
  39. // startTime: 0,
  40. // endTime: 10,
  41. // text: '请结合您的基本信息与过往履历进行简单的自我介绍,并讲一讲您有哪些优势胜任本岗位:'
  42. // }
  43. // ],
  44. // thirdVideoSubtitles: [
  45. // {
  46. // startTime: 0,
  47. // endTime: 4,
  48. // text: '在工作中,你如何确保个人防护装备的正确使用?'
  49. // }
  50. // ],
  51. // fourthVideoSubtitles: [
  52. // {
  53. // startTime: 0,
  54. // endTime: 4,
  55. // text: '描述一次你与团队合作改善生产流程的经历。'
  56. // }
  57. // ],
  58. // fifthVideoSubtitles: [
  59. // {
  60. // startTime: 0,
  61. // endTime: 6,
  62. // text: '你在团队合作中曾遇到过哪些挑战?如何解决团队内部的分歧?'
  63. // }
  64. // ],
  65. // sixthVideoSubtitles: [
  66. // {
  67. // startTime: 0,
  68. // endTime: 5,
  69. // text: '您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?'
  70. // }
  71. // ],
  72. showAnswerButton: false,
  73. // 控制答题按钮显示
  74. currentVideoIndex: 0,
  75. // 当前播放的视频索引
  76. videoList: [
  77. "https://data.qicai321.com/minlong/1809457d-30c5-40bb-b6d8-a8c2e8e1e9e2.mp4"
  78. //结束
  79. ],
  80. isRecording: false,
  81. recordingTimer: null,
  82. showStopRecordingButton: false,
  83. mediaRecorder: null,
  84. recordedChunks: [],
  85. recorder: null,
  86. lastUploadedVideoUrl: "",
  87. showStartRecordingButton: false,
  88. showRetryButton: false,
  89. // 控制重试按钮显示
  90. lastVideoToRetry: null,
  91. // 存储上次失败的视频URL,用于重试
  92. recordingStartTime: null,
  93. // 录制开始时间
  94. recordingTimerCount: 0,
  95. // 录制计时器计数
  96. recordingTimeDisplay: "00:00",
  97. // 格式化的录制时间显示
  98. // 添加上传队列相关数据
  99. uploadQueue: [],
  100. // 存储待上传的视频
  101. isUploading: false,
  102. // 标记是否正在上传
  103. uploadProgress: {},
  104. // 存储每个视频的上传进度
  105. uploadStatus: {},
  106. // 存储每个视频的上传状态
  107. showUploadStatus: false,
  108. // 是否显示上传状态指示器
  109. uploadStatusText: "",
  110. // 上传状态文本
  111. mediaRecorderTimeout: null,
  112. // 用于存储MediaRecorder的超时机制
  113. maxRecordingTime: 300,
  114. // 最大录制时间(秒)- 从60秒改为300秒(5分钟)
  115. remainingTime: 300,
  116. // 剩余录制时间(秒)- 从60秒改为300秒
  117. // 修改初始视频索引,添加参数控制
  118. startFromLastVideo: false,
  119. // 是否从最后一个视频开始播放
  120. countdownValue: 10,
  121. // 倒计时数值
  122. showCountdown: false,
  123. // 是否显示倒计时蒙层
  124. countdownTimer: null,
  125. showGif: false,
  126. // 控制是否显示GIF
  127. gifUrl: "",
  128. // GIF图片的URL
  129. // 添加AI语音交互相关属性
  130. aiVoiceUrl: "",
  131. // AI语音URL
  132. aiText: "",
  133. // AI回复文本
  134. transcribedText: "",
  135. // 转写文本
  136. isPlayingAiVoice: false,
  137. // 是否正在播放AI语音
  138. aiAudioPlayer: null,
  139. // AI语音播放器
  140. // 添加新的状态变量
  141. showContinueQuestionButton: false,
  142. // 控制"继续提问"按钮显示
  143. showEndInterviewButton: false,
  144. // 控制"结束面试"按钮显示
  145. questionRound: 0,
  146. // 当前提问轮次
  147. maxQuestionRounds: 1,
  148. // 最大提问轮次(可配置)
  149. conversationHistory: [],
  150. // 对话历史记录
  151. pendingAutoNavigation: false,
  152. // 标记是否有待处理的自动跳转
  153. hasTriedFallbackMethod: false,
  154. // 标记是否尝试过备选方法播放音频
  155. hasShownTextFallbackToast: false,
  156. // 标记是否已显示文本回退提示
  157. showNextButton: false,
  158. // 添加一个变量控制按钮显示
  159. isSubtitleExpanded: false,
  160. // 控制字幕是否展开
  161. subtitleHeight: 0
  162. // 记录字幕内容高度
  163. };
  164. },
  165. onLoad(options) {
  166. if (options && options.startFromLast === "true") {
  167. this.startFromLastVideo = true;
  168. this.currentVideoIndex = this.videoList.length - 1;
  169. }
  170. },
  171. mounted() {
  172. if (this.startFromLastVideo) {
  173. console.log("从最后一个视频开始播放");
  174. this.currentVideoIndex = this.videoList.length - 1;
  175. this.videoUrl = this.videoList[this.currentVideoIndex];
  176. }
  177. this.playDigitalHumanVideo();
  178. this.checkAudioPermission();
  179. this.initCamera();
  180. this.checkIOSCameraRecordPermission();
  181. this.checkAndFixRenderingIssues();
  182. setTimeout(() => {
  183. if (this.cameraStream && !this.useMiniProgramCameraComponent) {
  184. this.testAudioInput();
  185. }
  186. }, 3e3);
  187. common_vendor.index.setKeepScreenOn({
  188. keepScreenOn: true
  189. });
  190. },
  191. beforeDestroy() {
  192. this.stopUserCamera();
  193. if (this.aiAudioPlayer) {
  194. try {
  195. this.aiAudioPlayer.destroy();
  196. } catch (e) {
  197. console.error("销毁音频播放器失败:", e);
  198. }
  199. this.aiAudioPlayer = null;
  200. }
  201. if (this.recordingTimer) {
  202. clearInterval(this.recordingTimer);
  203. this.recordingTimer = null;
  204. }
  205. if (this.countdownTimer) {
  206. clearInterval(this.countdownTimer);
  207. this.countdownTimer = null;
  208. }
  209. if (this.mediaRecorderTimeout) {
  210. clearTimeout(this.mediaRecorderTimeout);
  211. this.mediaRecorderTimeout = null;
  212. }
  213. if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
  214. try {
  215. this.mediaRecorder.stop();
  216. } catch (e) {
  217. console.error("停止MediaRecorder失败:", e);
  218. }
  219. }
  220. if (this.recorder) {
  221. try {
  222. this.cameraContext.stopRecord();
  223. } catch (e) {
  224. console.error("停止小程序录制失败:", e);
  225. }
  226. }
  227. common_vendor.index.setKeepScreenOn({
  228. keepScreenOn: false
  229. });
  230. },
  231. methods: {
  232. // 初始化相机
  233. async initCamera() {
  234. const systemInfo = common_vendor.index.getSystemInfoSync();
  235. const isMiniProgram = systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay" || systemInfo.uniPlatform === "mp-baidu";
  236. if (isMiniProgram) {
  237. this.useMiniProgramCameraComponent = true;
  238. this.cameraContext = common_vendor.index.createCameraContext();
  239. common_vendor.index.getSetting({
  240. success: (res) => {
  241. if (!res.authSetting["scope.record"]) {
  242. common_vendor.index.authorize({
  243. scope: "scope.record",
  244. success: () => {
  245. console.log("录音权限已获取");
  246. },
  247. fail: (err) => {
  248. console.error("录音权限获取失败:", err);
  249. this.showPermissionDialog("录音");
  250. }
  251. });
  252. }
  253. if (!res.authSetting["scope.camera"]) {
  254. common_vendor.index.authorize({
  255. scope: "scope.camera",
  256. success: () => {
  257. console.log("相机权限已获取");
  258. },
  259. fail: (err) => {
  260. console.error("相机权限获取失败:", err);
  261. this.showPermissionDialog("相机");
  262. }
  263. });
  264. }
  265. const systemInfo2 = common_vendor.index.getSystemInfoSync();
  266. if (systemInfo2.platform === "ios") {
  267. if (!res.authSetting["scope.camera"] || !res.authSetting["scope.record"]) {
  268. console.log("iOS需要同时获取相机和录音权限");
  269. }
  270. }
  271. }
  272. });
  273. } else {
  274. try {
  275. const constraints = {
  276. audio: {
  277. echoCancellation: true,
  278. noiseSuppression: true,
  279. autoGainControl: true
  280. },
  281. video: {
  282. width: { ideal: 640, max: 1280 },
  283. // 控制视频宽度
  284. height: { ideal: 480, max: 720 },
  285. // 控制视频高度
  286. frameRate: { ideal: 15, max: 24 },
  287. // 控制帧率
  288. facingMode: "user"
  289. }
  290. };
  291. const stream = await navigator.mediaDevices.getUserMedia(constraints);
  292. this.cameraStream = stream;
  293. const audioTracks = stream.getAudioTracks();
  294. console.log("音频轨道数量:", audioTracks.length);
  295. if (audioTracks.length > 0) {
  296. console.log("音频轨道已获取:", audioTracks[0].label);
  297. audioTracks[0].enabled = true;
  298. } else {
  299. console.warn("未检测到音频轨道,尝试单独获取音频");
  300. this.tryGetAudioOnly();
  301. }
  302. const videoElement = this.$refs.userCameraVideo;
  303. if (videoElement) {
  304. videoElement.srcObject = stream;
  305. videoElement.muted = true;
  306. }
  307. } catch (error) {
  308. console.error("获取摄像头失败:", error);
  309. this.cameraError = error.message || "无法访问摄像头";
  310. common_vendor.index.showToast({
  311. title: "无法访问摄像头,请检查权限设置",
  312. icon: "none"
  313. });
  314. }
  315. }
  316. },
  317. // 停止用户摄像头
  318. stopUserCamera() {
  319. if (this.cameraStream) {
  320. this.cameraStream.getTracks().forEach((track) => {
  321. track.stop();
  322. });
  323. this.cameraStream = null;
  324. }
  325. },
  326. async fetchData() {
  327. this.loading = true;
  328. this.assistantResponse = "";
  329. this.audioTranscript = "";
  330. this.processedResponses = [];
  331. try {
  332. const requestTask = common_vendor.index.request({
  333. url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
  334. method: "POST",
  335. header: {
  336. "Content-Type": "application/json",
  337. "Authorization": "Bearer sk-9e1ec73a7d97493b8613c63f06b6110c"
  338. },
  339. data: {
  340. "model": "qwen-omni-turbo",
  341. "messages": [
  342. {
  343. "role": "user",
  344. "content": [
  345. {
  346. "type": "input_audio",
  347. "input_audio": {
  348. "data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
  349. "format": "wav"
  350. }
  351. },
  352. {
  353. "type": "text",
  354. "text": "这段音频在说什么"
  355. }
  356. ]
  357. }
  358. ],
  359. "stream": true,
  360. "stream_options": {
  361. "include_usage": true
  362. },
  363. "modalities": ["text", "audio"],
  364. "audio": { "voice": "Cherry", "format": "wav" }
  365. },
  366. success: (res) => {
  367. console.log("请求成功,响应数据:", res.data);
  368. if (typeof res.data === "string" && res.data.includes("data: {")) {
  369. const chunks = res.data.split("data: ").filter((chunk) => chunk.trim() !== "");
  370. chunks.forEach((chunk) => {
  371. this.handleStreamResponse(chunk);
  372. });
  373. } else {
  374. this.handleStreamResponse(res.data);
  375. }
  376. this.playDigitalHumanVideo();
  377. },
  378. fail: (err) => {
  379. console.error("请求失败:", err);
  380. },
  381. complete: () => {
  382. this.loading = false;
  383. }
  384. });
  385. } catch (error) {
  386. console.error("获取数据失败:", error);
  387. this.loading = false;
  388. }
  389. },
  390. handleStreamResponse(data) {
  391. if (typeof data === "string") {
  392. if (data === "[DONE]")
  393. return;
  394. try {
  395. const cleanData = data.trim();
  396. if (cleanData.startsWith("{") && cleanData.endsWith("}")) {
  397. const jsonData = JSON.parse(cleanData);
  398. this.processStreamChunk(jsonData);
  399. }
  400. } catch (e) {
  401. console.error("解析JSON失败:", e, "原始数据:", data);
  402. }
  403. } else {
  404. this.processStreamChunk(data);
  405. }
  406. },
  407. processStreamChunk(chunk) {
  408. if (chunk.choices && chunk.choices.length > 0) {
  409. const choice = chunk.choices[0];
  410. if (choice.delta && choice.delta.content) {
  411. this.assistantResponse += choice.delta.content;
  412. }
  413. if (choice.delta && choice.delta.audio && choice.delta.audio.transcript) {
  414. this.audioTranscript += choice.delta.audio.transcript;
  415. }
  416. if (choice.delta) {
  417. const result = {};
  418. if (choice.delta.role) {
  419. result.role = choice.delta.role;
  420. }
  421. if (choice.delta.audio && choice.delta.audio.transcript) {
  422. result.transcript = choice.delta.audio.transcript;
  423. }
  424. if (Object.keys(result).length > 0) {
  425. this.processedResponses.push(result);
  426. }
  427. }
  428. }
  429. },
  430. processResponseData() {
  431. this.processedResponses = this.responses.map((item) => {
  432. const result = {};
  433. if (item.delta && item.delta.role) {
  434. result.role = item.delta.role;
  435. }
  436. if (item.delta && item.delta.audio && item.delta.audio.transcript) {
  437. result.transcript = item.delta.audio.transcript;
  438. }
  439. return result;
  440. }).filter((item) => Object.keys(item).length > 0);
  441. },
  442. // 播放数字人视频
  443. playDigitalHumanVideo() {
  444. var _a;
  445. if (JSON.parse(common_vendor.index.getStorageSync("configData")) == null) {
  446. this.videoUrl = this.videoList[this.currentVideoIndex];
  447. } else {
  448. this.videoUrl = ((_a = JSON.parse(common_vendor.index.getStorageSync("configData")).digital_human) == null ? void 0 : _a.ending_video_url) || this.videoList[this.currentVideoIndex];
  449. }
  450. this.videoPlaying = true;
  451. console.log(`播放视频 ${this.currentVideoIndex + 1}/${this.videoList.length}: ${this.videoUrl}`);
  452. this.$nextTick(() => {
  453. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  454. if (videoContext) {
  455. videoContext.play();
  456. setTimeout(() => {
  457. if (this.videoPlaying && this.$refs.videoPlayer) {
  458. console.log("视频应该正在播放");
  459. } else {
  460. console.log("视频可能未成功播放,尝试替代方案");
  461. this.tryAlternativeVideoPath();
  462. }
  463. }, 1e3);
  464. } else {
  465. console.error("无法创建视频上下文");
  466. this.tryAlternativeVideoPath();
  467. }
  468. });
  469. },
  470. // 修改 tryAlternativeVideoPath 方法
  471. tryAlternativeVideoPath() {
  472. console.log("尝试使用替代路径");
  473. const alternativePaths = [
  474. "./static/demo.mp4",
  475. "../static/demo.mp4",
  476. "static/demo.mp4",
  477. "/static/demo.mp4",
  478. // 添加绝对路径
  479. `${window.location.origin}/static/demo.mp4`
  480. ];
  481. const currentPathIndex = alternativePaths.indexOf(this.videoUrl);
  482. const nextPathIndex = (currentPathIndex + 1) % alternativePaths.length;
  483. this.videoUrl = alternativePaths[nextPathIndex];
  484. console.log("尝试新路径:", this.videoUrl);
  485. this.$nextTick(() => {
  486. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  487. if (videoContext) {
  488. videoContext.stop();
  489. videoContext.play();
  490. setTimeout(() => {
  491. if (nextPathIndex === alternativePaths.length - 1 && !this.videoPlaying) {
  492. console.log("所有路径均失败,尝试使用uni.getVideoInfo检查视频");
  493. this.checkVideoWithAPI();
  494. }
  495. }, 1e3);
  496. }
  497. });
  498. },
  499. // 添加新方法:使用uni API检查视频
  500. checkVideoWithAPI() {
  501. common_vendor.index.getVideoInfo({
  502. src: "/static/demo.mp4",
  503. success: (res) => {
  504. console.log("视频信息获取成功:", res);
  505. this.videoUrl = "/static/demo.mp4";
  506. this.$nextTick(() => {
  507. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  508. if (videoContext) {
  509. videoContext.play();
  510. }
  511. });
  512. },
  513. fail: (err) => {
  514. console.error("视频信息获取失败:", err);
  515. this.fallbackToLocalVideo();
  516. }
  517. });
  518. },
  519. // 添加新方法:回退到本地视频
  520. fallbackToLocalVideo() {
  521. console.log("尝试使用本地视频资源");
  522. const platform = common_vendor.index.getSystemInfoSync().platform;
  523. if (platform === "android" || platform === "ios") {
  524. this.videoUrl = platform === "android" ? "android.resource://package_name/raw/demo" : "file:///assets/demo.mp4";
  525. this.$nextTick(() => {
  526. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  527. if (videoContext) {
  528. videoContext.play();
  529. }
  530. });
  531. } else {
  532. this.videoPlaying = false;
  533. common_vendor.index.showToast({
  534. title: "视频加载失败,显示静态图片",
  535. icon: "none"
  536. });
  537. }
  538. },
  539. // 修改 handleVideoError 方法
  540. handleVideoError(e) {
  541. console.error("视频加载错误:", e);
  542. if (e && e.detail) {
  543. console.error("详细错误信息:", e.detail);
  544. }
  545. common_vendor.index.getFileInfo({
  546. filePath: this.videoUrl.startsWith("/") ? this.videoUrl.substring(1) : this.videoUrl,
  547. success: (res) => {
  548. console.log("文件存在,大小:", res.size);
  549. this.tryDifferentFormat();
  550. },
  551. fail: (err) => {
  552. console.error("文件不存在或无法访问:", err);
  553. this.tryAlternativeVideoPath();
  554. }
  555. });
  556. common_vendor.index.showToast({
  557. title: "视频加载失败,请检查文件是否存在",
  558. icon: "none",
  559. duration: 2e3
  560. });
  561. },
  562. // 添加新方法:尝试不同格式
  563. tryDifferentFormat() {
  564. console.log("尝试不同的视频格式");
  565. const formats = [
  566. { ext: "mp4", mime: "video/mp4" },
  567. { ext: "webm", mime: "video/webm" },
  568. { ext: "ogg", mime: "video/ogg" },
  569. { ext: "mov", mime: "video/quicktime" }
  570. ];
  571. const currentPath = this.videoUrl;
  572. const basePath = currentPath.substring(0, currentPath.lastIndexOf(".")) || "/static/demo";
  573. let nextFormat = formats.find((f) => !currentPath.endsWith(f.ext));
  574. if (nextFormat) {
  575. this.videoUrl = `${basePath}.${nextFormat.ext}`;
  576. console.log("尝试新格式:", this.videoUrl);
  577. this.$nextTick(() => {
  578. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  579. if (videoContext) {
  580. videoContext.stop();
  581. videoContext.play();
  582. }
  583. });
  584. } else {
  585. this.useBuiltInResource();
  586. }
  587. },
  588. // 添加新方法:使用内置资源
  589. useBuiltInResource() {
  590. console.log("尝试使用内置资源");
  591. const platform = common_vendor.index.getSystemInfoSync().platform;
  592. if (platform === "windows") {
  593. process.env.UNI_INPUT_DIR || "";
  594. this.videoUrl = `./static/demo.mp4`;
  595. console.log("Windows平台尝试路径:", this.videoUrl);
  596. } else if (platform === "android" || platform === "ios") {
  597. this.useNativeVideo();
  598. } else {
  599. const baseUrl = window.location.origin;
  600. this.videoUrl = `${baseUrl}/static/demo.mp4`;
  601. console.log("Web平台尝试URL:", this.videoUrl);
  602. }
  603. this.$nextTick(() => {
  604. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  605. if (videoContext) {
  606. videoContext.play();
  607. }
  608. });
  609. },
  610. // 添加新方法:使用原生视频能力
  611. useNativeVideo() {
  612. console.log("尝试使用原生视频能力");
  613. common_vendor.index.chooseVideo({
  614. sourceType: ["album"],
  615. success: (res) => {
  616. this.videoUrl = res.tempFilePath;
  617. this.$nextTick(() => {
  618. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  619. if (videoContext) {
  620. videoContext.play();
  621. }
  622. });
  623. },
  624. fail: () => {
  625. this.videoPlaying = false;
  626. common_vendor.index.showToast({
  627. title: "无法加载视频,显示静态图片",
  628. icon: "none"
  629. });
  630. }
  631. });
  632. },
  633. // 处理视频结束事件
  634. handleVideoEnded() {
  635. console.log("视频播放结束,当前视频索引:", this.currentVideoIndex);
  636. this.videoPlaying = false;
  637. this.showStartRecordingButton = true;
  638. this.startCountdown();
  639. this.showAnswerButton = false;
  640. },
  641. // 添加新方法:开始倒计时
  642. startCountdown() {
  643. this.showCountdown = true;
  644. this.countdownValue = 10;
  645. this.countdownTimer = setInterval(() => {
  646. this.countdownValue--;
  647. if (this.countdownValue <= 0) {
  648. this.clearCountdown();
  649. this.showStartRecordingButton = false;
  650. this.startRecordingAnswer();
  651. }
  652. }, 1e3);
  653. },
  654. // 添加新方法:清除倒计时
  655. clearCountdown() {
  656. if (this.countdownTimer) {
  657. clearInterval(this.countdownTimer);
  658. this.countdownTimer = null;
  659. }
  660. this.showCountdown = false;
  661. },
  662. // 修改 handleStartRecordingClick 方法,使其可以终止倒计时
  663. handleStartRecordingClick() {
  664. this.showStartRecordingButton = false;
  665. this.clearCountdown();
  666. this.startRecordingAnswer();
  667. },
  668. // 修复 stopRecordingAnswer 方法,确保录制正确停止并上传
  669. stopRecordingAnswer() {
  670. this.clearCountdown();
  671. const recordingDuration = this.getRecordingDuration();
  672. const minimumDuration = 5;
  673. if (recordingDuration < minimumDuration) {
  674. common_vendor.index.showToast({
  675. title: "录制时间过短,请至少录制5秒",
  676. icon: "none",
  677. duration: 2e3
  678. });
  679. return;
  680. }
  681. this.showStopRecordingButton = false;
  682. if (this.recordingTimer) {
  683. clearInterval(this.recordingTimer);
  684. this.recordingTimer = null;
  685. }
  686. const systemInfo = common_vendor.index.getSystemInfoSync();
  687. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  688. if (isMiniProgram) {
  689. this.stopMiniProgramRecording();
  690. } else {
  691. this.stopBrowserRecording();
  692. }
  693. this.isRecording = false;
  694. },
  695. // 添加新方法:开始录制用户回答
  696. startRecordingAnswer() {
  697. console.log("开始录制用户回答");
  698. this.isRecording = true;
  699. this.recordingStartTime = Date.now();
  700. this.recordingTimerCount = 0;
  701. this.remainingTime = this.maxRecordingTime;
  702. this.recordingTimer = setInterval(() => {
  703. this.recordingTimerCount++;
  704. this.remainingTime = Math.max(0, this.maxRecordingTime - this.recordingTimerCount);
  705. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount) + " / " + this.formatTime(this.maxRecordingTime);
  706. if (this.recordingTimerCount >= this.maxRecordingTime) {
  707. console.log("已达到最大录制时间(60秒),自动停止录制");
  708. this.stopRecordingAnswer();
  709. }
  710. }, 1e3);
  711. const systemInfo = common_vendor.index.getSystemInfoSync();
  712. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  713. if (isMiniProgram) {
  714. this.startMiniProgramRecording();
  715. } else {
  716. this.startBrowserRecording();
  717. }
  718. this.showStopRecordingButton = true;
  719. },
  720. // 添加一个新方法:重置相机组件
  721. resetCamera() {
  722. console.log("重置相机组件");
  723. this.useMiniProgramCameraComponent = false;
  724. if (this.cameraContext) {
  725. this.cameraContext = null;
  726. }
  727. setTimeout(() => {
  728. this.useMiniProgramCameraComponent = true;
  729. setTimeout(() => {
  730. this.cameraContext = common_vendor.index.createCameraContext();
  731. console.log("相机组件已重置");
  732. }, 500);
  733. }, 500);
  734. },
  735. // 修改 startMiniProgramRecording 方法
  736. startMiniProgramRecording() {
  737. console.log("开始小程序录制方法");
  738. const systemInfo = common_vendor.index.getSystemInfoSync();
  739. const isIOS = systemInfo.platform === "ios";
  740. if (isIOS) {
  741. this.resetCamera();
  742. setTimeout(() => {
  743. this.actualStartRecording(isIOS);
  744. }, 1e3);
  745. } else {
  746. this.actualStartRecording(isIOS);
  747. }
  748. },
  749. // 添加新方法:实际开始录制
  750. actualStartRecording(isIOS) {
  751. if (!this.cameraContext) {
  752. this.cameraContext = common_vendor.index.createCameraContext();
  753. console.log("创建新的相机上下文");
  754. }
  755. common_vendor.index.getSetting({
  756. success: (res) => {
  757. const hasRecordAuth = res.authSetting["scope.record"];
  758. const hasCameraAuth = res.authSetting["scope.camera"];
  759. if (!hasRecordAuth || !hasCameraAuth) {
  760. console.warn("缺少必要权限,请求权限");
  761. this.requestMiniProgramPermissions();
  762. return;
  763. }
  764. if (isIOS) {
  765. console.log("iOS: 检查相机状态");
  766. const options = {
  767. timeout: 3e5,
  768. // 300秒超时 (5分钟)
  769. quality: "low",
  770. // 降低质量
  771. compressed: true,
  772. success: () => {
  773. console.log("iOS录制开始成功");
  774. },
  775. fail: (err) => {
  776. console.error("iOS录制失败:", err);
  777. this.useAlternativeRecordingMethod();
  778. }
  779. };
  780. try {
  781. console.log("尝试开始录制");
  782. this.recorder = this.cameraContext.startRecord(options);
  783. } catch (e) {
  784. console.error("开始录制异常:", e);
  785. this.useAlternativeRecordingMethod();
  786. }
  787. } else {
  788. const options = {
  789. timeout: 3e5,
  790. // 300秒超时 (5分钟)
  791. quality: "medium",
  792. compressed: true,
  793. success: () => {
  794. console.log("Android录制开始成功");
  795. },
  796. fail: (err) => {
  797. console.error("Android录制失败:", err);
  798. common_vendor.index.showToast({
  799. title: "录制失败,请检查相机权限",
  800. icon: "none"
  801. });
  802. this.proceedToNextQuestion();
  803. }
  804. };
  805. this.recorder = this.cameraContext.startRecord(options);
  806. }
  807. }
  808. });
  809. },
  810. // 添加新方法:使用替代录制方法
  811. useAlternativeRecordingMethod() {
  812. console.log("使用替代录制方法");
  813. common_vendor.index.showActionSheet({
  814. itemList: ["使用相册中的视频", "跳过此问题"],
  815. success: (res) => {
  816. if (res.tapIndex === 0) {
  817. common_vendor.index.chooseVideo({
  818. sourceType: ["album"],
  819. maxDuration: 300,
  820. // 从60秒改为300秒
  821. camera: "front",
  822. success: (res2) => {
  823. console.log("选择视频成功:", res2.tempFilePath);
  824. this.isRecording = false;
  825. this.showStopRecordingButton = false;
  826. this.uploadRecordedVideo(res2.tempFilePath);
  827. },
  828. fail: () => {
  829. console.log("用户取消选择视频");
  830. this.proceedToNextQuestion();
  831. }
  832. });
  833. } else {
  834. console.log("用户选择跳过问题");
  835. this.proceedToNextQuestion();
  836. }
  837. },
  838. fail: () => {
  839. console.log("操作取消");
  840. this.proceedToNextQuestion();
  841. }
  842. });
  843. },
  844. // 添加新方法:请求小程序权限
  845. requestMiniProgramPermissions() {
  846. common_vendor.index.authorize({
  847. scope: "scope.record",
  848. success: () => {
  849. console.log("录音权限已获取");
  850. common_vendor.index.authorize({
  851. scope: "scope.camera",
  852. success: () => {
  853. console.log("相机权限已获取");
  854. this.startMiniProgramRecording();
  855. },
  856. fail: (err) => {
  857. console.error("相机权限获取失败:", err);
  858. this.showPermissionDialog("相机");
  859. }
  860. });
  861. },
  862. fail: (err) => {
  863. console.error("录音权限获取失败:", err);
  864. this.showPermissionDialog("录音");
  865. }
  866. });
  867. },
  868. // 修改浏览器环境下的录制方法
  869. startBrowserRecording() {
  870. if (!this.cameraStream) {
  871. console.error("没有可用的摄像头流");
  872. common_vendor.index.showToast({
  873. title: "录制失败,摄像头未就绪",
  874. icon: "none"
  875. });
  876. this.proceedToNextQuestion();
  877. return;
  878. }
  879. try {
  880. const hasAudio = this.cameraStream.getAudioTracks().length > 0;
  881. if (!hasAudio) {
  882. console.warn("警告:媒体流中没有音频轨道,尝试重新获取带音频的媒体流");
  883. navigator.mediaDevices.getUserMedia({
  884. audio: {
  885. echoCancellation: true,
  886. noiseSuppression: true,
  887. autoGainControl: true
  888. },
  889. video: true
  890. }).then((newStream) => {
  891. const audioTracks = newStream.getAudioTracks();
  892. if (audioTracks.length > 0) {
  893. console.log("成功获取音频轨道:", audioTracks[0].label);
  894. const videoTrack = this.cameraStream.getVideoTracks()[0];
  895. const audioTrack = newStream.getAudioTracks()[0];
  896. const combinedStream = new MediaStream();
  897. if (videoTrack)
  898. combinedStream.addTrack(videoTrack);
  899. if (audioTrack)
  900. combinedStream.addTrack(audioTrack);
  901. this.cameraStream = combinedStream;
  902. const videoElement = this.$refs.userCameraVideo;
  903. if (videoElement) {
  904. videoElement.srcObject = combinedStream;
  905. videoElement.muted = true;
  906. }
  907. this.setupMediaRecorder(combinedStream);
  908. } else {
  909. console.warn("仍然无法获取音频轨道");
  910. this.setupMediaRecorder(this.cameraStream);
  911. }
  912. }).catch((err) => {
  913. console.error("获取音频失败:", err);
  914. this.setupMediaRecorder(this.cameraStream);
  915. });
  916. } else {
  917. console.log("检测到音频轨道,直接使用");
  918. this.setupMediaRecorder(this.cameraStream);
  919. }
  920. } catch (error) {
  921. console.error("浏览器录制失败:", error);
  922. common_vendor.index.showToast({
  923. title: "录制失败,浏览器可能不支持此功能",
  924. icon: "none"
  925. });
  926. this.proceedToNextQuestion();
  927. }
  928. },
  929. // 修改 setupMediaRecorder 方法
  930. setupMediaRecorder(stream) {
  931. const videoTracks = stream.getVideoTracks();
  932. const audioTracks = stream.getAudioTracks();
  933. console.log("设置MediaRecorder - 视频轨道:", videoTracks.length, "音频轨道:", audioTracks.length);
  934. let mimeType = "";
  935. const supportedTypes = [
  936. "video/webm;codecs=vp9,opus",
  937. "video/webm;codecs=vp8,opus",
  938. "video/webm;codecs=h264,opus",
  939. "video/mp4;codecs=h264,aac",
  940. "video/webm",
  941. "video/mp4"
  942. ];
  943. for (const type of supportedTypes) {
  944. if (MediaRecorder.isTypeSupported(type)) {
  945. mimeType = type;
  946. console.log("使用支持的MIME类型:", mimeType);
  947. break;
  948. }
  949. }
  950. const options = {
  951. mimeType: mimeType || "",
  952. audioBitsPerSecond: 64e3,
  953. // 降低音频比特率
  954. videoBitsPerSecond: 1e6
  955. // 降低视频比特率到1Mbps
  956. };
  957. try {
  958. this.mediaRecorder = new MediaRecorder(stream, options);
  959. console.log("MediaRecorder创建成功,使用选项:", options);
  960. } catch (e) {
  961. console.warn("使用指定选项创建MediaRecorder失败,尝试使用默认选项");
  962. this.mediaRecorder = new MediaRecorder(stream);
  963. }
  964. this.recordedChunks = [];
  965. this.mediaRecorder.ondataavailable = (event) => {
  966. if (event.data && event.data.size > 0) {
  967. this.recordedChunks.push(event.data);
  968. console.log(`收到数据块: ${event.data.size} 字节`);
  969. }
  970. };
  971. this.mediaRecorder.onstop = async () => {
  972. console.log("MediaRecorder停止,数据块数量:", this.recordedChunks.length);
  973. if (this.recordedChunks.length === 0) {
  974. console.error("没有录制到数据");
  975. common_vendor.index.showToast({
  976. title: "录制失败,未捕获到数据",
  977. icon: "none"
  978. });
  979. this.proceedToNextQuestion();
  980. return;
  981. }
  982. const mimeType2 = this.mediaRecorder.mimeType || "video/webm";
  983. const blob = new Blob(this.recordedChunks, { type: mimeType2 });
  984. console.log("创建Blob,原始大小:", blob.size, "类型:", mimeType2);
  985. common_vendor.index.showLoading({
  986. title: "正在处理视频...",
  987. mask: true
  988. });
  989. try {
  990. const compressedBlob = await this.compressVideo(blob);
  991. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  992. const file = new File([compressedBlob], fileName, { type: mimeType2 });
  993. common_vendor.index.hideLoading();
  994. this.uploadRecordedVideo(file);
  995. } catch (error) {
  996. console.error("视频处理失败:", error);
  997. common_vendor.index.hideLoading();
  998. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  999. const file = new File([blob], fileName, { type: mimeType2 });
  1000. this.uploadRecordedVideo(file);
  1001. }
  1002. };
  1003. this.mediaRecorder.onerror = (event) => {
  1004. console.error("MediaRecorder错误:", event.error);
  1005. };
  1006. try {
  1007. this.mediaRecorder.start(1e3);
  1008. console.log("MediaRecorder开始录制");
  1009. this.mediaRecorderTimeout = setTimeout(() => {
  1010. if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
  1011. console.log("MediaRecorder备份超时机制触发,停止录制");
  1012. this.mediaRecorder.stop();
  1013. }
  1014. }, 3e5);
  1015. } catch (e) {
  1016. console.error("开始录制失败:", e);
  1017. }
  1018. },
  1019. // 添加新方法:停止录制用户回答
  1020. stopRecordingAnswer() {
  1021. console.log("停止录制用户回答");
  1022. if (this.countdownTimer) {
  1023. clearInterval(this.countdownTimer);
  1024. this.countdownTimer = null;
  1025. this.showCountdown = false;
  1026. }
  1027. const recordingDuration = this.getRecordingDuration();
  1028. const minimumDuration = 5;
  1029. if (recordingDuration < minimumDuration) {
  1030. common_vendor.index.showToast({
  1031. title: "录制时间过短,请至少录制5秒",
  1032. icon: "none",
  1033. duration: 2e3
  1034. });
  1035. return;
  1036. }
  1037. this.showStopRecordingButton = false;
  1038. if (this.recordingTimer) {
  1039. clearInterval(this.recordingTimer);
  1040. this.recordingTimer = null;
  1041. }
  1042. const systemInfo = common_vendor.index.getSystemInfoSync();
  1043. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1044. if (isMiniProgram) {
  1045. this.stopMiniProgramRecording();
  1046. } else {
  1047. this.stopBrowserRecording();
  1048. }
  1049. this.isRecording = false;
  1050. },
  1051. // 添加新方法:获取录制时长
  1052. getRecordingDuration() {
  1053. if (this.recordingStartTime) {
  1054. return (Date.now() - this.recordingStartTime) / 1e3;
  1055. }
  1056. if (this.mediaRecorder && this.$refs.userCameraVideo) {
  1057. return this.$refs.userCameraVideo.currentTime || 0;
  1058. }
  1059. if (this.recordingTimerCount) {
  1060. return this.recordingTimerCount;
  1061. }
  1062. return 0;
  1063. },
  1064. // 添加新方法:重置录制
  1065. resetRecording() {
  1066. if (this.recordingTimer) {
  1067. clearTimeout(this.recordingTimer);
  1068. }
  1069. this.recordingStartTime = Date.now();
  1070. this.recordingTimerCount = 0;
  1071. if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
  1072. this.mediaRecorder.stop();
  1073. this.recordedChunks = [];
  1074. setTimeout(() => {
  1075. this.startBrowserRecording();
  1076. }, 500);
  1077. } else if (this.cameraContext) {
  1078. this.cameraContext.stopRecord({
  1079. success: () => {
  1080. console.log("重置录制:停止当前录制成功");
  1081. setTimeout(() => {
  1082. this.startMiniProgramRecording();
  1083. }, 500);
  1084. },
  1085. fail: (err) => {
  1086. console.error("重置录制:停止当前录制失败", err);
  1087. this.startMiniProgramRecording();
  1088. }
  1089. });
  1090. }
  1091. common_vendor.index.showToast({
  1092. title: "请重新开始回答",
  1093. icon: "none",
  1094. duration: 2e3
  1095. });
  1096. },
  1097. // 修复 completeRecordingStop 方法,确保视频正确上传和处理
  1098. completeRecordingStop() {
  1099. console.log("完成录制停止");
  1100. this.showStopRecordingButton = false;
  1101. if (this.recordingTimer) {
  1102. clearInterval(this.recordingTimer);
  1103. this.recordingTimer = null;
  1104. }
  1105. this.isRecording = false;
  1106. this.showUploadStatus = true;
  1107. this.uploadStatusText = "正在处理视频...";
  1108. this.isUploading = true;
  1109. const systemInfo = common_vendor.index.getSystemInfoSync();
  1110. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1111. if (isMiniProgram) {
  1112. this.stopMiniProgramRecording();
  1113. } else {
  1114. this.stopBrowserRecording();
  1115. }
  1116. },
  1117. // 修复 stopMiniProgramRecording 方法,确保小程序环境下正确停止录制
  1118. stopMiniProgramRecording() {
  1119. console.log("停止小程序录制");
  1120. if (!this.cameraContext) {
  1121. console.error("相机上下文不存在");
  1122. this.handleRecordingError(new Error("相机上下文不存在"));
  1123. return;
  1124. }
  1125. try {
  1126. common_vendor.index.showLoading({
  1127. title: "正在处理视频...",
  1128. mask: true
  1129. });
  1130. this.cameraContext.stopRecord({
  1131. success: (res) => {
  1132. console.log("停止录制成功:", res);
  1133. common_vendor.index.hideLoading();
  1134. const tempVideoPath = res.tempVideoPath || res.tempFilePath;
  1135. if (tempVideoPath) {
  1136. console.log("获取到视频临时路径:", tempVideoPath);
  1137. this.uploadRecordedVideo(tempVideoPath);
  1138. } else {
  1139. console.error("未获取到视频临时路径");
  1140. this.handleRecordingError(new Error("未获取到视频临时路径"));
  1141. }
  1142. },
  1143. fail: (err) => {
  1144. console.error("停止录制失败:", err);
  1145. common_vendor.index.hideLoading();
  1146. this.handleRecordingError(err);
  1147. }
  1148. });
  1149. } catch (e) {
  1150. console.error("停止录制异常:", e);
  1151. common_vendor.index.hideLoading();
  1152. this.handleRecordingError(e);
  1153. }
  1154. },
  1155. // 添加新方法:停止浏览器录制
  1156. stopBrowserRecording() {
  1157. if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
  1158. this.mediaRecorder.stop();
  1159. console.log("浏览器录制停止成功");
  1160. } else {
  1161. console.error("MediaRecorder不存在或已经停止");
  1162. this.proceedToNextQuestion();
  1163. }
  1164. },
  1165. // 修复 uploadRecordedVideo 方法,确保视频正确上传到服务器
  1166. uploadRecordedVideo(videoPath) {
  1167. console.log("开始上传录制的视频:", videoPath);
  1168. this.lastVideoToRetry = videoPath;
  1169. this.showUploadStatus = true;
  1170. this.uploadStatusText = "正在上传视频...";
  1171. this.isUploading = true;
  1172. this.saveUploadStatus();
  1173. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1174. const openid = common_vendor.index.getStorageSync("userInfo") ? JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid : "";
  1175. const application_id = common_vendor.index.getStorageSync("appId") || "";
  1176. const uploadTask = common_vendor.index.uploadFile({
  1177. url: `${common_config.apiBaseUrl}/api/upload/`,
  1178. filePath: videoPath,
  1179. name: "file",
  1180. formData: {
  1181. tenant_id,
  1182. openid,
  1183. application_id,
  1184. biz_type: "interview_video",
  1185. video_duration: this.recordingTimerCount || 0,
  1186. has_audio: "true"
  1187. // 明确标记包含音频
  1188. },
  1189. success: (uploadRes) => {
  1190. var _a, _b;
  1191. console.log("视频上传成功:", uploadRes);
  1192. try {
  1193. const result = typeof uploadRes.data === "string" ? JSON.parse(uploadRes.data) : uploadRes.data;
  1194. if ((result.success || result.code === 2e3) && (((_a = result.data) == null ? void 0 : _a.url) || ((_b = result.data) == null ? void 0 : _b.permanent_link))) {
  1195. const videoUrl = result.data.url || result.data.permanent_link || "";
  1196. console.log("视频URL:", videoUrl);
  1197. this.uploadStatusText = "视频处理完成,正在分析...";
  1198. this.saveUploadStatus();
  1199. this.submitToAiVoiceInteraction(videoUrl);
  1200. } else {
  1201. console.error("上传响应格式错误:", result);
  1202. const errorMsg = result.msg || result.message || "上传响应格式错误";
  1203. this.handleUploadError(new Error(errorMsg));
  1204. }
  1205. } catch (e) {
  1206. console.error("解析上传响应失败:", e);
  1207. this.handleUploadError(e);
  1208. }
  1209. },
  1210. fail: (err) => {
  1211. console.error("视频上传失败:", err);
  1212. let errorMessage = "网络错误,请检查网络连接";
  1213. if (err.errMsg) {
  1214. if (err.errMsg.includes("timeout")) {
  1215. errorMessage = "上传超时,请检查网络连接";
  1216. } else if (err.errMsg.includes("fail")) {
  1217. errorMessage = "上传失败: " + err.errMsg;
  1218. }
  1219. }
  1220. this.handleUploadError(new Error(errorMessage));
  1221. },
  1222. complete: () => {
  1223. this.showUploadStatus = false;
  1224. this.isUploading = false;
  1225. this.saveUploadStatus();
  1226. }
  1227. });
  1228. uploadTask.onProgressUpdate((res) => {
  1229. console.log("上传进度:", res.progress);
  1230. this.uploadStatusText = `正在上传视频... ${res.progress}%`;
  1231. if (res.progress < 10 && res.totalTimeMs > 1e4) {
  1232. this.uploadStatusText = `上传速度较慢,请耐心等待... ${res.progress}%`;
  1233. }
  1234. });
  1235. },
  1236. // 修改 processUploadQueue 方法,添加后台上传支持
  1237. processUploadQueue() {
  1238. if (this.uploadQueue.length === 0) {
  1239. this.isUploading = false;
  1240. this.showUploadStatus = false;
  1241. try {
  1242. common_vendor.index.removeStorageSync("videoUploadStatus");
  1243. } catch (e) {
  1244. console.error("清除上传状态失败:", e);
  1245. }
  1246. this.notifyUploadComplete();
  1247. return;
  1248. }
  1249. this.isUploading = true;
  1250. this.showUploadStatus = true;
  1251. const task = this.uploadQueue[0];
  1252. this.uploadStatus[task.id] = "uploading";
  1253. this.updateUploadStatusText();
  1254. task.attempts++;
  1255. if (typeof task.file !== "string") {
  1256. this.uploadFileWithXHR(task);
  1257. } else {
  1258. this.uploadFileWithUni(task);
  1259. }
  1260. this.saveUploadStatus();
  1261. },
  1262. // 添加新方法:发送上传完成通知
  1263. notifyUploadComplete() {
  1264. try {
  1265. common_vendor.index.$emit("videoUploadComplete", {
  1266. timestamp: Date.now()
  1267. });
  1268. console.log("发送上传完成通知");
  1269. } catch (e) {
  1270. console.error("发送上传完成通知失败:", e);
  1271. }
  1272. const systemInfo = common_vendor.index.getSystemInfoSync();
  1273. if (systemInfo.platform === "android" || systemInfo.platform === "ios") {
  1274. if (plus && plus.push) {
  1275. plus.push.createMessage("视频上传完成", "您的面试视频已成功上传", {});
  1276. }
  1277. }
  1278. },
  1279. // 添加新方法:使用XMLHttpRequest上传文件
  1280. uploadFileWithXHR(task) {
  1281. const userInfo = common_vendor.index.getStorageSync("userInfo");
  1282. const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
  1283. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1284. const formData = new FormData();
  1285. formData.append("file", task.file);
  1286. formData.append("openid", openid);
  1287. formData.append("tenant_id", tenant_id);
  1288. formData.append("application_id", common_vendor.index.getStorageSync("appId"));
  1289. formData.append("question_id", task.questionId);
  1290. formData.append("video_duration", this.recordingTimerCount || 0);
  1291. formData.append("has_audio", "true");
  1292. const xhr = new XMLHttpRequest();
  1293. xhr.open("POST", `${common_config.apiBaseUrl}/api/upload/`, true);
  1294. xhr.timeout = 12e4;
  1295. xhr.upload.onprogress = (event) => {
  1296. if (event.lengthComputable) {
  1297. const percentComplete = Math.round(event.loaded / event.total * 100);
  1298. this.uploadProgress[task.id] = percentComplete;
  1299. this.updateUploadStatusText();
  1300. }
  1301. };
  1302. xhr.onload = () => {
  1303. if (xhr.status === 200) {
  1304. try {
  1305. const res = JSON.parse(xhr.responseText);
  1306. console.log("上传响应:", res);
  1307. if (res.code === 2e3) {
  1308. const videoUrl = res.data.url || res.data.photoUrl || "";
  1309. if (videoUrl) {
  1310. this.uploadStatus[task.id] = "success";
  1311. this.updateUploadStatusText();
  1312. this.submitVideoToInterview(videoUrl, task);
  1313. } else {
  1314. this.handleUploadFailure(task, "视频URL获取失败");
  1315. }
  1316. } else {
  1317. this.handleUploadFailure(task, res.msg || "上传失败");
  1318. }
  1319. } catch (e) {
  1320. this.handleUploadFailure(task, "解析响应失败");
  1321. }
  1322. } else {
  1323. this.handleUploadFailure(task, "HTTP状态: " + xhr.status);
  1324. }
  1325. };
  1326. xhr.onerror = () => {
  1327. this.handleUploadFailure(task, "网络错误");
  1328. };
  1329. xhr.ontimeout = () => {
  1330. this.handleUploadFailure(task, "上传超时");
  1331. };
  1332. xhr.send(formData);
  1333. },
  1334. // 添加新方法:使用uni.uploadFile上传文件
  1335. uploadFileWithUni(task) {
  1336. const userInfo = common_vendor.index.getStorageSync("userInfo");
  1337. const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
  1338. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1339. const uploadTask = common_vendor.index.uploadFile({
  1340. url: `${common_config.apiBaseUrl}/api/upload/`,
  1341. filePath: task.file,
  1342. name: "file",
  1343. formData: {
  1344. openid,
  1345. tenant_id,
  1346. application_id: common_vendor.index.getStorageSync("appId"),
  1347. question_id: task.questionId,
  1348. video_duration: this.recordingTimerCount || 0,
  1349. has_audio: "true"
  1350. // 明确标记包含音频
  1351. },
  1352. success: (uploadRes) => {
  1353. try {
  1354. const res = JSON.parse(uploadRes.data);
  1355. console.log("上传响应:", res);
  1356. if (res.code === 2e3) {
  1357. const videoUrl = res.data.permanent_link || res.data.url || "";
  1358. if (videoUrl) {
  1359. this.uploadStatus[task.id] = "success";
  1360. this.updateUploadStatusText();
  1361. this.submitVideoToInterview(videoUrl, task);
  1362. } else {
  1363. this.handleUploadFailure(task, "视频URL获取失败");
  1364. }
  1365. } else {
  1366. this.handleUploadFailure(task, res.msg || "上传失败");
  1367. }
  1368. } catch (e) {
  1369. this.handleUploadFailure(task, "解析响应失败");
  1370. }
  1371. },
  1372. fail: (err) => {
  1373. this.handleUploadFailure(task, err.errMsg || "上传失败");
  1374. }
  1375. });
  1376. uploadTask.onProgressUpdate((res) => {
  1377. this.uploadProgress[task.id] = res.progress;
  1378. this.updateUploadStatusText();
  1379. });
  1380. },
  1381. // 添加新方法:处理上传失败
  1382. handleUploadFailure(task, errorMsg) {
  1383. console.error("上传失败:", errorMsg);
  1384. this.uploadStatus[task.id] = "failed";
  1385. this.updateUploadStatusText();
  1386. if (task.attempts < task.maxAttempts) {
  1387. console.log(`将在5秒后重试上传,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1388. setTimeout(() => {
  1389. this.uploadProgress[task.id] = 0;
  1390. if (typeof task.file !== "string") {
  1391. this.uploadFileWithXHR(task);
  1392. } else {
  1393. this.uploadFileWithUni(task);
  1394. }
  1395. }, 5e3);
  1396. } else {
  1397. console.log("超过最大重试次数,放弃上传");
  1398. common_vendor.index.showToast({
  1399. title: "视频上传失败,请稍后重试",
  1400. icon: "none",
  1401. duration: 2e3
  1402. });
  1403. this.uploadQueue.shift();
  1404. this.processUploadQueue();
  1405. }
  1406. },
  1407. // 修改 submitVideoToInterview 方法
  1408. submitVideoToInterview(videoUrl, task = null) {
  1409. console.log("提交视频URL到面试接口:", videoUrl);
  1410. let questionId;
  1411. if (task) {
  1412. questionId = task.questionId;
  1413. } else {
  1414. switch (this.currentVideoIndex) {
  1415. case 1:
  1416. questionId = 36;
  1417. break;
  1418. case 2:
  1419. questionId = 11;
  1420. break;
  1421. case 3:
  1422. questionId = 12;
  1423. break;
  1424. case 4:
  1425. questionId = 13;
  1426. break;
  1427. default:
  1428. questionId = 10;
  1429. }
  1430. }
  1431. ({
  1432. application_id: common_vendor.index.getStorageSync("appId"),
  1433. question_id: questionId,
  1434. video_url: videoUrl,
  1435. tenant_id: common_vendor.index.getStorageSync("tenant_id") || "1",
  1436. has_audio: true
  1437. // 明确标记包含音频
  1438. });
  1439. this.submitToAiVoiceInteraction(videoUrl);
  1440. },
  1441. // 添加新方法:处理提交失败
  1442. handleSubmitFailure(task, errorMsg) {
  1443. console.error("提交失败:", errorMsg);
  1444. this.uploadStatus[task.id] = "failed";
  1445. this.updateUploadStatusText();
  1446. if (task.attempts < task.maxAttempts) {
  1447. console.log(`将在5秒后重试提交,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1448. setTimeout(() => {
  1449. this.submitVideoToInterview(task.videoUrl, task);
  1450. }, 5e3);
  1451. } else {
  1452. console.log("超过最大重试次数,放弃提交");
  1453. common_vendor.index.showToast({
  1454. title: "视频提交失败,请稍后重试",
  1455. icon: "none",
  1456. duration: 2e3
  1457. });
  1458. this.uploadQueue.shift();
  1459. this.processUploadQueue();
  1460. }
  1461. },
  1462. // 添加新方法:更新上传状态文本
  1463. updateUploadStatusText() {
  1464. if (this.uploadQueue.length === 0) {
  1465. this.uploadStatusText = "";
  1466. return;
  1467. }
  1468. const currentTask = this.uploadQueue[0];
  1469. const progress = this.uploadProgress[currentTask.id] || 0;
  1470. const status = this.uploadStatus[currentTask.id] || "pending";
  1471. let statusText = "";
  1472. switch (status) {
  1473. case "pending":
  1474. statusText = "等待上传";
  1475. break;
  1476. case "uploading":
  1477. statusText = `上传中 ${progress}%`;
  1478. break;
  1479. case "success":
  1480. statusText = "上传成功,提交中...";
  1481. break;
  1482. case "failed":
  1483. statusText = `上传失败,${currentTask.attempts < currentTask.maxAttempts ? "即将重试" : "已放弃"}`;
  1484. break;
  1485. }
  1486. this.uploadStatusText = `问题${currentTask.questionId - 9}:${statusText}`;
  1487. if (this.uploadQueue.length > 1) {
  1488. this.uploadStatusText += ` (${this.uploadQueue.length}个视频待处理)`;
  1489. }
  1490. },
  1491. // 修改 proceedToNextQuestion 方法
  1492. proceedToNextQuestion() {
  1493. console.log("准备跳转到下一页面");
  1494. if (this.isPlayingAiVoice) {
  1495. console.log("AI语音正在播放,等待播放完成后再跳转");
  1496. return;
  1497. }
  1498. if (this.uploadQueue.length > 0) {
  1499. console.log("上传队列将在后台继续处理...");
  1500. this.saveUploadStatus();
  1501. }
  1502. },
  1503. // 修改 navigateToNextPage 方法
  1504. navigateToNextPage() {
  1505. console.log("执行页面跳转");
  1506. this.isPlayingAiVoice = false;
  1507. this.currentSubtitle = "";
  1508. common_vendor.index.reLaunch({
  1509. url: "/pages/success/success",
  1510. success: () => {
  1511. console.log("页面跳转成功");
  1512. },
  1513. fail: (err) => {
  1514. console.error("页面跳转失败:", err);
  1515. common_vendor.index.showToast({
  1516. title: "页面跳转失败",
  1517. icon: "none",
  1518. duration: 2e3
  1519. });
  1520. }
  1521. });
  1522. },
  1523. // 添加处理导航失败的方法
  1524. handleNavigationFailure() {
  1525. common_vendor.index.reLaunch({
  1526. url: "/pages/success/success",
  1527. //'/pages/posture-guide/posture-guide',
  1528. fail: (err2) => {
  1529. console.error("备用跳转也失败:", err2);
  1530. common_vendor.index.navigateBack({
  1531. delta: 1
  1532. });
  1533. }
  1534. });
  1535. },
  1536. // 修改 handleAnswerButtonClick 方法
  1537. handleAnswerButtonClick() {
  1538. this.showAnswerButton = false;
  1539. common_vendor.index.showToast({
  1540. title: "面试完成",
  1541. icon: "success",
  1542. duration: 500
  1543. // 只显示0.5秒
  1544. });
  1545. if (this.lastUploadedVideoUrl) {
  1546. this.submitToAiVoiceInteraction(this.lastUploadedVideoUrl);
  1547. } else {
  1548. this.navigateToNextPage();
  1549. }
  1550. },
  1551. // 处理相机错误
  1552. handleCameraError(e) {
  1553. console.error("相机错误:", e);
  1554. const systemInfo = common_vendor.index.getSystemInfoSync();
  1555. const isIOS = systemInfo.platform === "ios";
  1556. if (isIOS) {
  1557. console.log("iOS相机错误,尝试重新初始化");
  1558. common_vendor.index.showToast({
  1559. title: "相机初始化中...",
  1560. icon: "loading",
  1561. duration: 2e3
  1562. });
  1563. this.resetCamera();
  1564. if (this.isRecording) {
  1565. this.isRecording = false;
  1566. this.showStopRecordingButton = false;
  1567. setTimeout(() => {
  1568. this.useAlternativeRecordingMethod();
  1569. }, 1e3);
  1570. }
  1571. } else {
  1572. common_vendor.index.showToast({
  1573. title: "相机初始化失败,请检查权限设置",
  1574. icon: "none"
  1575. });
  1576. this.tryFallbackOptions();
  1577. }
  1578. },
  1579. // 添加新方法:尝试备用选项
  1580. tryFallbackOptions() {
  1581. const systemInfo = common_vendor.index.getSystemInfoSync();
  1582. if (systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay") {
  1583. this.useMiniProgramCamera();
  1584. } else {
  1585. this.showStaticCameraPlaceholder();
  1586. }
  1587. },
  1588. // 添加新方法:使用小程序相机API
  1589. useMiniProgramCamera() {
  1590. console.log("尝试使用小程序相机组件");
  1591. this.useMiniProgramCameraComponent = true;
  1592. },
  1593. // 添加新方法:显示静态图像
  1594. showStaticCameraPlaceholder() {
  1595. console.log("显示静态摄像头占位图");
  1596. const img = document.createElement("img");
  1597. img.src = "/static/images/camera-placeholder.png";
  1598. img.className = "static-camera-image";
  1599. img.style.width = "100%";
  1600. img.style.height = "100%";
  1601. img.style.objectFit = "cover";
  1602. const container = this.$refs.userCameraVideo.parentNode;
  1603. container.appendChild(img);
  1604. },
  1605. // 处理视频时间更新事件
  1606. handleTimeUpdate(e) {
  1607. const currentTime = e.target.currentTime;
  1608. if (this.isRecording && this.recordingTimerCount) {
  1609. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
  1610. }
  1611. let currentSubtitles;
  1612. if (this.currentVideoIndex === 0) {
  1613. currentSubtitles = this.subtitles;
  1614. } else if (this.currentVideoIndex === 1) {
  1615. currentSubtitles = this.secondVideoSubtitles;
  1616. } else if (this.currentVideoIndex === 2) {
  1617. currentSubtitles = this.thirdVideoSubtitles;
  1618. } else if (this.currentVideoIndex === 3) {
  1619. currentSubtitles = this.fourthVideoSubtitles;
  1620. } else if (this.currentVideoIndex === 4) {
  1621. currentSubtitles = this.fifthVideoSubtitles;
  1622. } else if (this.currentVideoIndex === 5) {
  1623. currentSubtitles = this.sixthVideoSubtitles;
  1624. } else {
  1625. currentSubtitles = [];
  1626. }
  1627. const subtitle = currentSubtitles.find(
  1628. (sub) => currentTime >= sub.startTime && currentTime < sub.endTime
  1629. );
  1630. this.currentSubtitle = subtitle ? subtitle.text : "";
  1631. },
  1632. // Add a new method to handle the "Start Recording" button click
  1633. handleStartRecordingClick() {
  1634. this.showStartRecordingButton = false;
  1635. this.clearCountdown();
  1636. this.startRecordingAnswer();
  1637. },
  1638. // 修改 checkAudioPermission 方法,确保在录制前获取音频权限
  1639. checkAudioPermission() {
  1640. const systemInfo = common_vendor.index.getSystemInfoSync();
  1641. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1642. if (isMiniProgram) {
  1643. common_vendor.index.getSetting({
  1644. success: (res) => {
  1645. if (!res.authSetting["scope.record"]) {
  1646. common_vendor.index.authorize({
  1647. scope: "scope.record",
  1648. success: () => {
  1649. console.log("录音权限已获取");
  1650. },
  1651. fail: (err) => {
  1652. console.error("录音权限获取失败:", err);
  1653. this.showPermissionDialog("录音");
  1654. }
  1655. });
  1656. }
  1657. if (!res.authSetting["scope.camera"]) {
  1658. common_vendor.index.authorize({
  1659. scope: "scope.camera",
  1660. success: () => {
  1661. console.log("相机权限已获取");
  1662. },
  1663. fail: (err) => {
  1664. console.error("相机权限获取失败:", err);
  1665. this.showPermissionDialog("相机");
  1666. }
  1667. });
  1668. }
  1669. }
  1670. });
  1671. }
  1672. },
  1673. // 添加新方法:测试音频输入
  1674. testAudioInput() {
  1675. if (!this.cameraStream) {
  1676. console.warn("没有可用的媒体流,无法测试音频");
  1677. return;
  1678. }
  1679. const audioTracks = this.cameraStream.getAudioTracks();
  1680. if (audioTracks.length === 0) {
  1681. console.warn("没有检测到音频轨道,尝试重新获取");
  1682. this.tryGetAudioOnly();
  1683. return;
  1684. }
  1685. console.log("音频轨道信息:", audioTracks[0].getSettings());
  1686. try {
  1687. const AudioContext = window.AudioContext || window.webkitAudioContext;
  1688. if (!AudioContext) {
  1689. console.warn("浏览器不支持AudioContext");
  1690. return;
  1691. }
  1692. const audioContext = new AudioContext();
  1693. const analyser = audioContext.createAnalyser();
  1694. const microphone = audioContext.createMediaStreamSource(this.cameraStream);
  1695. microphone.connect(analyser);
  1696. analyser.fftSize = 256;
  1697. const bufferLength = analyser.frequencyBinCount;
  1698. const dataArray = new Uint8Array(bufferLength);
  1699. let silenceCounter = 0;
  1700. const checkAudio = () => {
  1701. if (this.isRecording)
  1702. return;
  1703. analyser.getByteFrequencyData(dataArray);
  1704. let sum = 0;
  1705. for (let i = 0; i < bufferLength; i++) {
  1706. sum += dataArray[i];
  1707. }
  1708. const average = sum / bufferLength;
  1709. if (average > 10) {
  1710. console.log("检测到音频输入,音量:", average);
  1711. silenceCounter = 0;
  1712. } else {
  1713. silenceCounter++;
  1714. if (silenceCounter > 10) {
  1715. console.warn("持续检测不到音频输入,可能麦克风未正常工作");
  1716. silenceCounter = 0;
  1717. }
  1718. }
  1719. requestAnimationFrame(checkAudio);
  1720. };
  1721. checkAudio();
  1722. } catch (e) {
  1723. console.error("音频测试失败:", e);
  1724. }
  1725. },
  1726. // 添加新方法:尝试单独获取音频
  1727. tryGetAudioOnly() {
  1728. navigator.mediaDevices.getUserMedia({ audio: true }).then((audioStream) => {
  1729. if (this.cameraStream) {
  1730. const videoTrack = this.cameraStream.getVideoTracks()[0];
  1731. const audioTrack = audioStream.getAudioTracks()[0];
  1732. const combinedStream = new MediaStream();
  1733. if (videoTrack)
  1734. combinedStream.addTrack(videoTrack);
  1735. if (audioTrack)
  1736. combinedStream.addTrack(audioTrack);
  1737. this.cameraStream = combinedStream;
  1738. const videoElement = this.$refs.userCameraVideo;
  1739. if (videoElement) {
  1740. videoElement.srcObject = combinedStream;
  1741. videoElement.muted = true;
  1742. }
  1743. console.log("成功合并音频和视频轨道");
  1744. } else {
  1745. console.warn("没有视频流可合并");
  1746. }
  1747. }).catch((err) => {
  1748. console.error("单独获取音频失败:", err);
  1749. });
  1750. },
  1751. // 添加新方法:显示权限对话框
  1752. showPermissionDialog(permissionType) {
  1753. common_vendor.index.showModal({
  1754. title: "需要权限",
  1755. content: `请允许使用${permissionType}权限,否则可能影响面试功能`,
  1756. confirmText: "去设置",
  1757. success: (res) => {
  1758. if (res.confirm) {
  1759. common_vendor.index.openSetting({
  1760. success: (settingRes) => {
  1761. console.log("设置页面打开成功", settingRes);
  1762. }
  1763. });
  1764. }
  1765. }
  1766. });
  1767. },
  1768. // 添加重试上传方法
  1769. retryVideoUpload() {
  1770. if (this.lastVideoToRetry) {
  1771. this.showRetryButton = false;
  1772. common_vendor.index.showLoading({
  1773. title: "正在重新提交...",
  1774. mask: true
  1775. });
  1776. this.submitVideoToInterview(this.lastVideoToRetry);
  1777. } else {
  1778. common_vendor.index.showToast({
  1779. title: "没有可重试的视频",
  1780. icon: "none"
  1781. });
  1782. }
  1783. },
  1784. // 添加一个新方法用于压缩视频
  1785. async compressVideo(videoBlob) {
  1786. if (videoBlob.size < 5 * 1024 * 1024) {
  1787. return videoBlob;
  1788. }
  1789. console.log("开始压缩视频,原始大小:", videoBlob.size);
  1790. const videoElement = document.createElement("video");
  1791. videoElement.muted = true;
  1792. videoElement.autoplay = false;
  1793. const canvas = document.createElement("canvas");
  1794. const ctx = canvas.getContext("2d");
  1795. videoElement.src = URL.createObjectURL(videoBlob);
  1796. return new Promise((resolve) => {
  1797. videoElement.onloadedmetadata = () => {
  1798. const width = Math.floor(videoElement.videoWidth / 2);
  1799. const height = Math.floor(videoElement.videoHeight / 2);
  1800. canvas.width = width;
  1801. canvas.height = height;
  1802. const stream = canvas.captureStream(15);
  1803. if (videoElement.captureStream) {
  1804. const originalStream = videoElement.captureStream();
  1805. const audioTracks = originalStream.getAudioTracks();
  1806. if (audioTracks.length > 0) {
  1807. stream.addTrack(audioTracks[0]);
  1808. }
  1809. }
  1810. const options = {
  1811. mimeType: "video/webm;codecs=vp8,opus",
  1812. audioBitsPerSecond: 64e3,
  1813. videoBitsPerSecond: 8e5
  1814. // 800kbps
  1815. };
  1816. const mediaRecorder = new MediaRecorder(stream, options);
  1817. const chunks = [];
  1818. mediaRecorder.ondataavailable = (e) => {
  1819. if (e.data.size > 0) {
  1820. chunks.push(e.data);
  1821. }
  1822. };
  1823. mediaRecorder.onstop = () => {
  1824. const compressedBlob = new Blob(chunks, { type: "video/webm" });
  1825. console.log("视频压缩完成,压缩后大小:", compressedBlob.size);
  1826. resolve(compressedBlob);
  1827. };
  1828. videoElement.onplay = () => {
  1829. mediaRecorder.start(100);
  1830. const drawFrame = () => {
  1831. if (videoElement.paused || videoElement.ended) {
  1832. mediaRecorder.stop();
  1833. return;
  1834. }
  1835. ctx.drawImage(videoElement, 0, 0, width, height);
  1836. requestAnimationFrame(drawFrame);
  1837. };
  1838. drawFrame();
  1839. };
  1840. videoElement.play();
  1841. };
  1842. });
  1843. },
  1844. // 修改 checkIOSCameraRecordPermission 方法
  1845. checkIOSCameraRecordPermission() {
  1846. const systemInfo = common_vendor.index.getSystemInfoSync();
  1847. if (systemInfo.platform !== "ios")
  1848. return;
  1849. common_vendor.index.getSetting({
  1850. success: (res) => {
  1851. if (!res.authSetting["scope.camera"]) {
  1852. common_vendor.index.authorize({
  1853. scope: "scope.camera",
  1854. success: () => {
  1855. console.log("iOS相机权限已获取");
  1856. },
  1857. fail: (err) => {
  1858. console.error("iOS相机权限获取失败:", err);
  1859. this.showPermissionDialog("相机");
  1860. }
  1861. });
  1862. }
  1863. if (!res.authSetting["scope.record"]) {
  1864. common_vendor.index.authorize({
  1865. scope: "scope.record",
  1866. success: () => {
  1867. console.log("iOS录音权限已获取");
  1868. },
  1869. fail: (err) => {
  1870. console.error("iOS录音权限获取失败:", err);
  1871. this.showPermissionDialog("录音");
  1872. }
  1873. });
  1874. }
  1875. }
  1876. });
  1877. },
  1878. // 添加新方法:检查并修复渲染问题
  1879. checkAndFixRenderingIssues() {
  1880. try {
  1881. if (typeof u !== "undefined" && u) {
  1882. if (!u.currentQuestion) {
  1883. console.log("修复: 创建缺失的currentQuestion对象");
  1884. u.currentQuestion = {};
  1885. }
  1886. if (u.currentQuestion && typeof u.currentQuestion.isImportant === "undefined") {
  1887. console.log("修复: 设置缺失的isImportant属性");
  1888. u.currentQuestion.isImportant = false;
  1889. }
  1890. }
  1891. } catch (e) {
  1892. console.log("防御性检查异常:", e);
  1893. }
  1894. },
  1895. // 添加格式化时间的辅助方法
  1896. formatTime(seconds) {
  1897. if (!seconds && seconds !== 0)
  1898. return "03:30";
  1899. const minutes = Math.floor(seconds / 60);
  1900. const remainingSeconds = seconds % 60;
  1901. return `${minutes.toString().padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
  1902. },
  1903. // 添加新方法:保存上传状态到本地存储
  1904. saveUploadStatus() {
  1905. const uploadStatus = {
  1906. isUploading: this.isUploading,
  1907. uploadQueue: this.uploadQueue.length,
  1908. timestamp: Date.now()
  1909. };
  1910. try {
  1911. common_vendor.index.setStorageSync("videoUploadStatus", JSON.stringify(uploadStatus));
  1912. } catch (e) {
  1913. console.error("保存上传状态失败:", e);
  1914. }
  1915. },
  1916. // 修改 submitToAiVoiceInteraction 方法
  1917. submitToAiVoiceInteraction(videoUrl) {
  1918. console.log("提交视频到AI语音交互接口:", videoUrl);
  1919. common_vendor.index.showLoading({
  1920. title: "面试官正在思考...",
  1921. mask: true
  1922. });
  1923. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1924. const application_id = common_vendor.index.getStorageSync("appId") || "98";
  1925. let positionConfigId = 1;
  1926. if (JSON.parse(common_vendor.index.getStorageSync("configData"))) {
  1927. positionConfigId = JSON.parse(common_vendor.index.getStorageSync("configData")).id;
  1928. }
  1929. const requestData = {
  1930. voice_url: videoUrl,
  1931. tenant_id,
  1932. application_id,
  1933. scene_type: "interview",
  1934. // 场景类型:面试
  1935. // voice_type: 'longxiaoxia', // 角色:龙小侠
  1936. position_config_id: positionConfigId,
  1937. conversation_history: this.conversationHistory
  1938. // 添加对话历史
  1939. };
  1940. const systemInfo = common_vendor.index.getSystemInfoSync();
  1941. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1942. if (isMiniProgram) {
  1943. common_vendor.index.request({
  1944. url: `${common_config.apiBaseUrl}/api/system/voice/mcp/interaction`,
  1945. // 使用新的接口地址
  1946. method: "POST",
  1947. data: requestData,
  1948. header: {
  1949. "content-type": "application/json"
  1950. // 修改为JSON格式
  1951. },
  1952. success: (res) => {
  1953. if (res.statusCode === 200) {
  1954. this.handleAiInteractionResponse(res.data);
  1955. } else {
  1956. this.handleAiInteractionError(res.data);
  1957. }
  1958. },
  1959. fail: (err) => {
  1960. this.handleAiInteractionError(err);
  1961. }
  1962. });
  1963. } else {
  1964. const xhr = new XMLHttpRequest();
  1965. xhr.open("POST", `${common_config.apiBaseUrl}/api/system/voice/mcp/interaction`, true);
  1966. xhr.timeout = 6e4;
  1967. xhr.setRequestHeader("Content-Type", "application/json");
  1968. xhr.onload = () => {
  1969. if (xhr.status === 200) {
  1970. try {
  1971. const response = JSON.parse(xhr.responseText);
  1972. this.handleAiInteractionResponse(response);
  1973. } catch (e) {
  1974. console.error("解析AI响应失败:", e);
  1975. this.handleAiInteractionError({ errMsg: "解析响应失败" });
  1976. }
  1977. } else {
  1978. this.handleAiInteractionError({ errMsg: "HTTP状态: " + xhr.status });
  1979. }
  1980. };
  1981. xhr.onerror = () => {
  1982. this.handleAiInteractionError({ errMsg: "网络错误" });
  1983. };
  1984. xhr.ontimeout = () => {
  1985. this.handleAiInteractionError({ errMsg: "请求超时" });
  1986. };
  1987. xhr.send(JSON.stringify(requestData));
  1988. }
  1989. },
  1990. // 添加处理AI交互响应的方法
  1991. handleAiInteractionResponse(data) {
  1992. console.log("AI语音交互接口响应:", data);
  1993. const systemInfo = common_vendor.index.getSystemInfoSync();
  1994. const isIOS = systemInfo.platform === "ios";
  1995. this.isPlayingAiVoice = true;
  1996. common_vendor.index.hideLoading();
  1997. this.hasTriedFallbackMethod = false;
  1998. if (data && data.success) {
  1999. this.aiText = data.ai_text || "";
  2000. this.transcribedText = data.transcribed_text ? data.transcribed_text.text : "";
  2001. this.conversationHistory.push({
  2002. role: "user",
  2003. content: this.transcribedText
  2004. });
  2005. this.conversationHistory.push({
  2006. role: "assistant",
  2007. content: this.aiText
  2008. });
  2009. const aiVoiceUrl = data.ai_voice_url || "";
  2010. if (aiVoiceUrl) {
  2011. this.aiVoiceUrl = aiVoiceUrl.startsWith("http") ? aiVoiceUrl : `${common_config.apiBaseUrl}${aiVoiceUrl}`;
  2012. console.log("AI语音URL:", this.aiVoiceUrl);
  2013. this.currentSubtitle = this.aiText;
  2014. const systemInfo2 = common_vendor.index.getSystemInfoSync();
  2015. const isMiniProgram = systemInfo2.uniPlatform && systemInfo2.uniPlatform.startsWith("mp-");
  2016. const isUnsupportedFormat = this.checkUnsupportedAudioFormat(this.aiVoiceUrl);
  2017. if (isUnsupportedFormat && isMiniProgram) {
  2018. console.warn("检测到小程序不支持的音频格式,直接使用文本显示");
  2019. this.displayTextResponse();
  2020. return;
  2021. }
  2022. if (isMiniProgram) {
  2023. if (isIOS) {
  2024. this.playIOSMiniProgramAudio();
  2025. } else {
  2026. this.playMiniProgramAudio();
  2027. }
  2028. } else {
  2029. this.playAiVoice();
  2030. }
  2031. this.showContinueQuestionButton = false;
  2032. this.showEndInterviewButton = false;
  2033. } else {
  2034. console.warn("未获取到AI语音URL,使用文本显示");
  2035. this.displayTextResponse();
  2036. }
  2037. } else {
  2038. console.error("AI语音交互失败:", data);
  2039. this.showContinueQuestionOptions();
  2040. this.checkPendingNavigation();
  2041. }
  2042. },
  2043. // 修改 handleAiInteractionError 方法,不要直接跳转,而是显示继续提问选项
  2044. handleAiInteractionError(err) {
  2045. console.error("AI语音交互请求失败:", err);
  2046. common_vendor.index.hideLoading();
  2047. common_vendor.index.showToast({
  2048. title: "AI处理失败,请重试",
  2049. icon: "none",
  2050. duration: 2e3
  2051. });
  2052. this.showContinueQuestionOptions();
  2053. },
  2054. // 添加新方法:播放AI语音
  2055. async playAiVoice() {
  2056. console.log("开始播放AI语音:", this.aiVoiceUrl);
  2057. this.resetAudioState();
  2058. this.isPlayingAiVoice = true;
  2059. this.showContinueQuestionButton = false;
  2060. this.showEndInterviewButton = false;
  2061. this.currentSubtitle = this.aiText;
  2062. if (!this.aiVoiceUrl || this.aiVoiceUrl.trim() === "") {
  2063. console.error("无效的音频URL,直接显示文本");
  2064. this.useTextFallbackAndNavigate();
  2065. return;
  2066. }
  2067. try {
  2068. const systemInfo = common_vendor.index.getSystemInfoSync();
  2069. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  2070. const isIOS = systemInfo.platform === "ios";
  2071. this.audioPlaybackTimer = setTimeout(() => {
  2072. console.log("音频播放超时,使用备选方案");
  2073. if (this.isPlayingAiVoice) {
  2074. this.handlePlaybackTimeout();
  2075. }
  2076. }, 3e4);
  2077. if (isMiniProgram) {
  2078. if (isIOS) {
  2079. await this.playIOSMiniProgramAudio();
  2080. } else {
  2081. await this.playMiniProgramAudio();
  2082. }
  2083. } else if (isIOS) {
  2084. await this.playAiVoiceForIOS();
  2085. } else {
  2086. await this.playAiVoiceForAndroid();
  2087. }
  2088. this.pendingAutoNavigation = true;
  2089. } catch (error) {
  2090. console.error("音频播放失败:", error);
  2091. this.handlePlaybackError(error);
  2092. }
  2093. },
  2094. // 添加新方法:处理播放超时
  2095. handlePlaybackTimeout() {
  2096. console.log("处理音频播放超时");
  2097. this.resetAudioState();
  2098. common_vendor.index.showToast({
  2099. title: "音频播放超时,将显示文字回复",
  2100. icon: "none",
  2101. duration: 2e3
  2102. });
  2103. this.useTextFallbackAndNavigate();
  2104. },
  2105. // 添加新方法:处理播放错误
  2106. handlePlaybackError(error) {
  2107. console.error("处理音频播放错误:", error);
  2108. this.resetAudioState();
  2109. const isIOS = common_vendor.index.getSystemInfoSync().platform === "ios";
  2110. if (isIOS && !this.hasTriedFallbackMethod) {
  2111. this.hasTriedFallbackMethod = true;
  2112. console.log("iOS设备尝试使用备选播放方法");
  2113. this.fallbackIOSAudioPlay();
  2114. return;
  2115. }
  2116. common_vendor.index.showToast({
  2117. title: "音频播放失败,将显示文字回复",
  2118. icon: "none",
  2119. duration: 2e3
  2120. });
  2121. this.useTextFallbackAndNavigate();
  2122. },
  2123. // 新增方法:文本回退并导航
  2124. useTextFallbackAndNavigate() {
  2125. console.log("使用文本回退并准备导航");
  2126. this.isPlayingAiVoice = false;
  2127. if (!this.hasShownTextFallbackToast) {
  2128. this.hasShownTextFallbackToast = true;
  2129. common_vendor.index.showToast({
  2130. title: "为您显示文字回复",
  2131. icon: "none",
  2132. duration: 2e3
  2133. });
  2134. }
  2135. this.currentSubtitle = this.aiText || "抱歉,AI回复内容加载失败";
  2136. setTimeout(() => {
  2137. this.navigateToNextPage();
  2138. }, 5e3);
  2139. },
  2140. // 修改 handleIOSAudioPlaybackComplete 方法
  2141. handleIOSAudioPlaybackComplete() {
  2142. this.isPlayingAiVoice = false;
  2143. setTimeout(() => {
  2144. this.currentSubtitle = "";
  2145. }, 1e3);
  2146. if (this.aiAudioPlayer) {
  2147. try {
  2148. this.aiAudioPlayer.destroy();
  2149. } catch (e) {
  2150. console.error("销毁iOS音频播放器失败:", e);
  2151. }
  2152. this.aiAudioPlayer = null;
  2153. }
  2154. this.navigateToNextPage();
  2155. },
  2156. // 修改 playMiniProgramAudio 方法
  2157. playMiniProgramAudio() {
  2158. return new Promise(async (resolve, reject) => {
  2159. try {
  2160. common_vendor.index.showLoading({
  2161. title: "音频加载中...",
  2162. mask: true
  2163. });
  2164. const localAudioPath = await this.preloadAudio(this.aiVoiceUrl);
  2165. common_vendor.index.hideLoading();
  2166. const audioContext = common_vendor.wx$1.createInnerAudioContext();
  2167. audioContext.src = localAudioPath;
  2168. audioContext.autoplay = true;
  2169. audioContext.bufferSize = 4096;
  2170. let hasStarted = false;
  2171. let hasError = false;
  2172. audioContext.onPlay(() => {
  2173. console.log("AI语音开始播放");
  2174. hasStarted = true;
  2175. this.currentSubtitle = this.aiText;
  2176. });
  2177. audioContext.onEnded(() => {
  2178. console.log("AI语音播放结束");
  2179. this.isPlayingAiVoice = false;
  2180. this.currentSubtitle = "";
  2181. audioContext.destroy();
  2182. if (!hasError) {
  2183. console.log("准备跳转到下一页");
  2184. this.navigateToNextPage();
  2185. resolve();
  2186. }
  2187. });
  2188. audioContext.onStop(() => {
  2189. console.log("AI语音播放停止");
  2190. this.isPlayingAiVoice = false;
  2191. this.currentSubtitle = "";
  2192. audioContext.destroy();
  2193. if (!hasError) {
  2194. console.log("播放停止,准备跳转到下一页");
  2195. this.navigateToNextPage();
  2196. resolve();
  2197. }
  2198. });
  2199. audioContext.onError((err) => {
  2200. hasError = true;
  2201. console.error("AI语音播放错误:", err);
  2202. audioContext.destroy();
  2203. common_vendor.index.showToast({
  2204. title: "音频播放异常,将显示文字",
  2205. icon: "none",
  2206. duration: 2e3
  2207. });
  2208. if (this.aiVoiceUrl.endsWith(".mp3")) {
  2209. const wavUrl = this.aiVoiceUrl.replace(".mp3", ".wav");
  2210. console.log("尝试使用WAV格式:", wavUrl);
  2211. this.aiVoiceUrl = wavUrl;
  2212. this.playMiniProgramAudio().then(resolve).catch(reject);
  2213. } else {
  2214. reject(err);
  2215. }
  2216. });
  2217. setTimeout(() => {
  2218. if (!hasStarted && !hasError) {
  2219. console.error("音频播放启动超时");
  2220. audioContext.destroy();
  2221. reject(new Error("音频播放启动超时"));
  2222. }
  2223. }, 5e3);
  2224. } catch (error) {
  2225. common_vendor.index.hideLoading();
  2226. console.error("音频播放初始化失败:", error);
  2227. reject(error);
  2228. }
  2229. });
  2230. },
  2231. // 新增方法:导航到下一页
  2232. navigateToNextPage() {
  2233. console.log("执行页面跳转");
  2234. this.isPlayingAiVoice = false;
  2235. this.currentSubtitle = "";
  2236. common_vendor.index.reLaunch({
  2237. url: "/pages/success/success",
  2238. success: () => {
  2239. console.log("页面跳转成功");
  2240. },
  2241. fail: (err) => {
  2242. console.error("页面跳转失败:", err);
  2243. common_vendor.index.showToast({
  2244. title: "页面跳转失败",
  2245. icon: "none",
  2246. duration: 2e3
  2247. });
  2248. }
  2249. });
  2250. },
  2251. // 新增方法:专门处理iOS小程序音频播放
  2252. playIOSMiniProgramAudio() {
  2253. return new Promise((resolve, reject) => {
  2254. try {
  2255. const bgAudio = common_vendor.index.getBackgroundAudioManager();
  2256. bgAudio.title = "语音播报";
  2257. bgAudio.epname = "AI Voice";
  2258. bgAudio.singer = "Assistant";
  2259. bgAudio.onCanplay(() => {
  2260. try {
  2261. bgAudio.play();
  2262. } catch (e) {
  2263. console.warn("调用 play 失败,稍后重试", e);
  2264. setTimeout(() => {
  2265. try {
  2266. bgAudio.play();
  2267. } catch (_) {
  2268. }
  2269. }, 50);
  2270. }
  2271. });
  2272. bgAudio.onPlay(() => {
  2273. console.log("iOS小程序音频开始播放");
  2274. });
  2275. bgAudio.onEnded(() => {
  2276. console.log("iOS小程序音频播放完成");
  2277. try {
  2278. bgAudio.stop();
  2279. } catch (_) {
  2280. }
  2281. this.navigateToNextPage();
  2282. resolve();
  2283. });
  2284. bgAudio.onError((err) => {
  2285. console.error("iOS小程序音频播放错误:", err);
  2286. try {
  2287. bgAudio.stop();
  2288. } catch (_) {
  2289. }
  2290. reject(err);
  2291. });
  2292. bgAudio.autoplay = true;
  2293. bgAudio.src = this.aiVoiceUrl;
  2294. } catch (error) {
  2295. reject(error);
  2296. }
  2297. });
  2298. },
  2299. playAiVoiceForIOS() {
  2300. return new Promise((resolve, reject) => {
  2301. try {
  2302. const audioContext = new Audio();
  2303. audioContext.src = this.aiVoiceUrl;
  2304. audioContext.autoplay = true;
  2305. audioContext.addEventListener("play", () => {
  2306. console.log("iOS音频开始播放");
  2307. });
  2308. audioContext.addEventListener("ended", () => {
  2309. console.log("iOS音频播放完成");
  2310. resolve();
  2311. });
  2312. audioContext.addEventListener("error", (err) => {
  2313. console.error("iOS音频播放错误:", err);
  2314. reject(err);
  2315. });
  2316. } catch (error) {
  2317. reject(error);
  2318. }
  2319. });
  2320. },
  2321. playAiVoiceForAndroid() {
  2322. return new Promise((resolve, reject) => {
  2323. try {
  2324. const audioContext = new Audio();
  2325. audioContext.src = this.aiVoiceUrl;
  2326. audioContext.autoplay = true;
  2327. audioContext.addEventListener("play", () => {
  2328. console.log("Android音频开始播放");
  2329. });
  2330. audioContext.addEventListener("ended", () => {
  2331. console.log("Android音频播放完成");
  2332. resolve();
  2333. });
  2334. audioContext.addEventListener("error", (err) => {
  2335. console.error("Android音频播放错误:", err);
  2336. reject(err);
  2337. });
  2338. } catch (error) {
  2339. reject(error);
  2340. }
  2341. });
  2342. },
  2343. // 新增方法:iOS小程序音频预下载
  2344. preloadIOSMiniProgramAudio(audioUrl) {
  2345. return new Promise((resolve, reject) => {
  2346. console.log("开始预下载iOS小程序音频:", audioUrl);
  2347. common_vendor.index.downloadFile({
  2348. url: audioUrl,
  2349. timeout: 15e3,
  2350. // 15秒超时
  2351. success: (res) => {
  2352. if (res.statusCode === 200) {
  2353. console.log("iOS小程序音频下载成功:", res.tempFilePath);
  2354. resolve(res.tempFilePath);
  2355. } else {
  2356. console.error("iOS小程序音频下载失败,状态码:", res.statusCode);
  2357. reject(new Error(`下载失败,状态码: ${res.statusCode}`));
  2358. }
  2359. },
  2360. fail: (err) => {
  2361. console.error("iOS小程序音频下载请求失败:", err);
  2362. reject(err);
  2363. }
  2364. });
  2365. });
  2366. },
  2367. // 新增方法:iOS小程序错误处理
  2368. handleIOSMiniProgramError(audioContext, error) {
  2369. console.error("处理iOS小程序音频错误:", error);
  2370. if (audioContext) {
  2371. try {
  2372. audioContext.destroy();
  2373. } catch (e) {
  2374. console.error("销毁音频播放器失败:", e);
  2375. }
  2376. }
  2377. let errorMessage = "音频播放异常,显示文字";
  2378. if (error.errMsg && error.errMsg.includes("-11850")) {
  2379. console.log("iOS小程序检测到系统音频错误(-11850)");
  2380. errorMessage = "系统音频服务暂停,显示文字";
  2381. } else if (error.errCode === 10002) {
  2382. console.log("iOS小程序检测到errCode:10002,网络或资源问题");
  2383. errorMessage = "音频加载中断,显示文字";
  2384. } else if (error.errCode === 10001) {
  2385. console.log("iOS小程序检测到errCode:10001,系统错误");
  2386. errorMessage = "系统音频错误,显示文字";
  2387. } else if (error.errCode === 10003) {
  2388. console.log("iOS小程序检测到errCode:10003,文件错误");
  2389. errorMessage = "音频文件错误,显示文字";
  2390. } else if (error.errCode === 10004) {
  2391. console.log("iOS小程序检测到errCode:10004,格式不支持");
  2392. errorMessage = "音频格式不支持,显示文字";
  2393. }
  2394. common_vendor.index.showToast({
  2395. title: errorMessage,
  2396. icon: "none",
  2397. duration: 2e3
  2398. });
  2399. this.useIOSTextFallback();
  2400. },
  2401. // 新增方法:iOS小程序播放超时处理
  2402. handleIOSPlaybackTimeout(audioContext) {
  2403. console.log("iOS小程序音频播放超时处理");
  2404. if (audioContext) {
  2405. try {
  2406. audioContext.destroy();
  2407. } catch (e) {
  2408. console.error("销毁超时音频播放器失败:", e);
  2409. }
  2410. }
  2411. this.useIOSTextFallback();
  2412. },
  2413. // 新增方法:iOS小程序备选播放方法
  2414. fallbackIOSMiniProgramPlay(audioContext) {
  2415. console.log("iOS小程序使用备选播放方法");
  2416. try {
  2417. audioContext.src = this.aiVoiceUrl;
  2418. const fallbackTimeout = setTimeout(() => {
  2419. if (this.isPlayingAiVoice) {
  2420. console.log("iOS小程序备选方法也超时");
  2421. clearTimeout(fallbackTimeout);
  2422. this.handleIOSPlaybackTimeout(audioContext);
  2423. }
  2424. }, 3e3);
  2425. audioContext.play();
  2426. } catch (e) {
  2427. console.error("iOS小程序备选播放方法失败:", e);
  2428. this.handleIOSPlaybackTimeout(audioContext);
  2429. }
  2430. },
  2431. // 新增方法:统一的iOS音频完成处理
  2432. handleIOSAudioComplete(audioContext) {
  2433. console.log("iOS音频播放完成");
  2434. this.isPlayingAiVoice = false;
  2435. setTimeout(() => {
  2436. this.currentSubtitle = "";
  2437. }, 2e3);
  2438. if (audioContext) {
  2439. try {
  2440. audioContext.destroy();
  2441. } catch (e) {
  2442. console.error("销毁iOS音频播放器失败:", e);
  2443. }
  2444. }
  2445. this.showContinueQuestionOptions();
  2446. this.checkPendingNavigation();
  2447. },
  2448. // 移除原来的 playMiniProgramAudioForIOS 方法,因为已经被新的 playIOSMiniProgramAudio 替代
  2449. // playMiniProgramAudioForIOS() 方法可以删除或注释掉
  2450. // 保留原有的 useIOSTextFallback 方法,但确保它能正确处理所有iOS场景
  2451. useIOSTextFallback() {
  2452. console.log("iOS使用文本回退方案");
  2453. this.isPlayingAiVoice = false;
  2454. if (!this.hasShownTextFallbackToast) {
  2455. this.hasShownTextFallbackToast = true;
  2456. }
  2457. this.currentSubtitle = this.aiText || "抱歉,AI回复内容加载失败";
  2458. this.showNextButton = true;
  2459. },
  2460. // 添加处理继续按钮点击的方法
  2461. handleNextButtonClick() {
  2462. this.showNextButton = false;
  2463. this.handleIOSAudioComplete(null);
  2464. },
  2465. // 添加新方法:iOS音频播放完成处理
  2466. handleIOSAudioPlaybackComplete() {
  2467. console.log("iOS音频播放完成");
  2468. this.isPlayingAiVoice = false;
  2469. common_vendor.index.hideLoading();
  2470. setTimeout(() => {
  2471. this.currentSubtitle = "";
  2472. }, 2e3);
  2473. if (this.aiAudioPlayer) {
  2474. try {
  2475. this.aiAudioPlayer.destroy();
  2476. } catch (e) {
  2477. console.error("销毁iOS音频播放器失败:", e);
  2478. }
  2479. this.aiAudioPlayer = null;
  2480. }
  2481. this.resetAudioState();
  2482. if (this.pendingAutoNavigation) {
  2483. console.log("执行待处理的自动跳转");
  2484. this.navigateToNextPage();
  2485. } else {
  2486. this.showContinueQuestionOptions();
  2487. }
  2488. },
  2489. // 添加新方法:重置音频状态
  2490. resetAudioState() {
  2491. this.isPlayingAiVoice = false;
  2492. this.hasTriedFallbackMethod = false;
  2493. this.hasShownTextFallbackToast = false;
  2494. if (this.aiAudioPlayer) {
  2495. try {
  2496. this.aiAudioPlayer.destroy();
  2497. } catch (e) {
  2498. console.error("销毁音频播放器失败:", e);
  2499. }
  2500. this.aiAudioPlayer = null;
  2501. }
  2502. if (this.audioPlaybackTimer) {
  2503. clearTimeout(this.audioPlaybackTimer);
  2504. this.audioPlaybackTimer = null;
  2505. }
  2506. },
  2507. // 添加新方法:iOS音频错误处理
  2508. handleIOSAudioError(error) {
  2509. console.error("iOS音频播放错误:", error);
  2510. switch (error.errCode) {
  2511. case 10001:
  2512. console.log("iOS音频系统错误,尝试重新播放");
  2513. this.retryIOSAudioPlay();
  2514. break;
  2515. case 10002:
  2516. console.log("iOS音频网络错误,使用备选方案");
  2517. this.handleIOS10002Error();
  2518. break;
  2519. case 10003:
  2520. console.log("iOS音频文件错误,使用文本回退");
  2521. this.useIOSTextFallback();
  2522. break;
  2523. case 10004:
  2524. console.log("iOS音频格式不支持,使用文本回退");
  2525. this.useIOSTextFallback();
  2526. break;
  2527. default:
  2528. console.log("iOS音频未知错误,使用文本回退");
  2529. this.useIOSTextFallback();
  2530. break;
  2531. }
  2532. },
  2533. // 添加新方法:重试iOS音频播放
  2534. retryIOSAudioPlay() {
  2535. console.log("重试iOS音频播放");
  2536. if (this.aiAudioPlayer) {
  2537. try {
  2538. this.aiAudioPlayer.destroy();
  2539. } catch (e) {
  2540. console.error("销毁播放器失败:", e);
  2541. }
  2542. this.aiAudioPlayer = null;
  2543. }
  2544. setTimeout(() => {
  2545. this.fallbackIOSAudioPlay();
  2546. }, 1e3);
  2547. },
  2548. // 添加新方法:iOS专用音频播放
  2549. async playAiVoiceForIOS() {
  2550. console.log("使用iOS专用音频播放方法");
  2551. return new Promise((resolve, reject) => {
  2552. try {
  2553. this.aiAudioPlayer = common_vendor.index.createInnerAudioContext();
  2554. this.aiAudioPlayer.autoplay = true;
  2555. this.aiAudioPlayer.obeyMuteSwitch = false;
  2556. this.aiAudioPlayer.volume = 1;
  2557. this.aiAudioPlayer.src = this.aiVoiceUrl;
  2558. this.aiAudioPlayer.onPlay(() => {
  2559. console.log("iOS音频开始播放");
  2560. this.currentSubtitle = this.aiText;
  2561. });
  2562. this.aiAudioPlayer.onEnded(() => {
  2563. console.log("iOS音频播放完成");
  2564. this.handleIOSAudioPlaybackComplete();
  2565. resolve();
  2566. });
  2567. this.aiAudioPlayer.onError((err) => {
  2568. console.error("iOS音频播放错误:", err);
  2569. reject(err);
  2570. });
  2571. this.aiAudioPlayer.onWaiting(() => {
  2572. console.log("iOS音频加载中...");
  2573. });
  2574. this.aiAudioPlayer.onCanplay(() => {
  2575. console.log("iOS音频准备就绪");
  2576. });
  2577. } catch (error) {
  2578. console.error("创建iOS音频播放器失败:", error);
  2579. reject(error);
  2580. }
  2581. });
  2582. },
  2583. // 添加新方法:iOS备选音频播放
  2584. fallbackIOSAudioPlay() {
  2585. console.log("iOS备选音频播放方案");
  2586. try {
  2587. this.aiAudioPlayer = common_vendor.index.createInnerAudioContext();
  2588. this.aiAudioPlayer.autoplay = true;
  2589. this.aiAudioPlayer.obeyMuteSwitch = true;
  2590. this.aiAudioPlayer.volume = 0.8;
  2591. this.aiAudioPlayer.src = this.aiVoiceUrl;
  2592. this.aiAudioPlayer.onPlay(() => {
  2593. console.log("iOS备选方案:音频开始播放");
  2594. this.currentSubtitle = this.aiText;
  2595. });
  2596. this.aiAudioPlayer.onEnded(() => {
  2597. console.log("iOS备选方案:音频播放结束");
  2598. this.handleIOSAudioPlaybackComplete();
  2599. });
  2600. this.aiAudioPlayer.onError((err) => {
  2601. console.error("iOS备选方案:音频播放错误:", err);
  2602. this.useIOSTextFallback();
  2603. });
  2604. setTimeout(() => {
  2605. if (this.isPlayingAiVoice && this.aiAudioPlayer) {
  2606. console.log("iOS音频播放超时,使用文本回退");
  2607. this.useIOSTextFallback();
  2608. }
  2609. }, 5e3);
  2610. } catch (e) {
  2611. console.error("iOS备选音频播放失败:", e);
  2612. this.useIOSTextFallback();
  2613. }
  2614. },
  2615. // 修改 playMiniProgramAudio 方法,添加iOS特殊处理
  2616. /* playMiniProgramAudio() {
  2617. console.log('使用小程序原生音频API播放:', this.aiVoiceUrl);
  2618. // 标记正在播放AI语音
  2619. this.isPlayingAiVoice = true;
  2620. // 确保在播放期间不显示继续提问按钮
  2621. this.showContinueQuestionButton = false;
  2622. this.showEndInterviewButton = false;
  2623. // 检查音频URL是否有效
  2624. if (!this.aiVoiceUrl || this.aiVoiceUrl.trim() === '') {
  2625. console.error('无效的音频URL');
  2626. this.handleAudioPlaybackFailure();
  2627. return;
  2628. }
  2629. // 检查平台
  2630. const systemInfo = uni.getSystemInfoSync();
  2631. const isIOS = systemInfo.platform === 'ios';
  2632. // iOS小程序特殊处理
  2633. if (isIOS) {
  2634. this.playMiniProgramAudioForIOS();
  2635. return;
  2636. }
  2637. // 非iOS平台的原有逻辑
  2638. try {
  2639. // 使用wx.createInnerAudioContext API (微信小程序)
  2640. const audioContext = wx.createInnerAudioContext();
  2641. // 设置音频属性
  2642. audioContext.autoplay = false;
  2643. audioContext.obeyMuteSwitch = false; // 忽略静音开关
  2644. // 监听播放开始事件
  2645. audioContext.onPlay(() => {
  2646. console.log('AI语音开始播放');
  2647. // 显示正在播放提示
  2648. });
  2649. // 监听播放结束事件
  2650. audioContext.onEnded(() => {
  2651. console.log('AI语音播放结束');
  2652. // 标记播放结束
  2653. this.isPlayingAiVoice = false;
  2654. // 清空字幕
  2655. this.currentSubtitle = '';
  2656. // 销毁音频播放器
  2657. audioContext.destroy();
  2658. // 播放结束后显示继续提问选项,而不是直接跳转
  2659. this.showContinueQuestionOptions();
  2660. });
  2661. // 监听播放错误事件
  2662. audioContext.onError((err) => {
  2663. console.error('AI语音播放错误:', err);
  2664. // 标记播放结束
  2665. this.isPlayingAiVoice = false;
  2666. // 清空字幕
  2667. this.currentSubtitle = '';
  2668. // 销毁音频播放器
  2669. audioContext.destroy();
  2670. // 播放错误时也显示继续提问选项
  2671. this.showContinueQuestionOptions();
  2672. });
  2673. // 设置音频源
  2674. audioContext.src = this.aiVoiceUrl;
  2675. // 添加超时处理,如果5秒内没有开始播放,则认为出错
  2676. const playTimeout = setTimeout(() => {
  2677. if (this.isPlayingAiVoice) {
  2678. console.warn('小程序音频播放超时,尝试备选方法');
  2679. this.tryMiniProgramFallbackAudioPlay();
  2680. }
  2681. }, 5000);
  2682. // 延迟一小段时间再播放,确保src已经设置完成
  2683. setTimeout(() => {
  2684. audioContext.play();
  2685. // 播放开始后清除超时
  2686. clearTimeout(playTimeout);
  2687. }, 300);
  2688. } catch (e) {
  2689. console.error('小程序播放AI语音时发生错误:', e);
  2690. // 标记播放结束
  2691. this.isPlayingAiVoice = false;
  2692. // 显示错误提示
  2693. // 使用文本显示方式作为备选方案
  2694. this.handleAudioPlaybackFailure();
  2695. }
  2696. }, */
  2697. // 添加新方法:iOS小程序音频播放
  2698. playMiniProgramAudioForIOS() {
  2699. console.log("iOS小程序环境:开始播放AI语音");
  2700. this.hasShownTextFallbackToast = false;
  2701. try {
  2702. const audioContext = common_vendor.wx$1.createInnerAudioContext();
  2703. audioContext.autoplay = false;
  2704. audioContext.obeyMuteSwitch = true;
  2705. audioContext.volume = 1;
  2706. audioContext.onError((err) => {
  2707. console.error("iOS小程序音频播放错误:", err);
  2708. if (err.errMsg && err.errMsg.includes("-11850")) {
  2709. console.log("iOS小程序检测到系统音频错误(-11850)");
  2710. } else if (err.errCode === 10002) {
  2711. console.log("iOS小程序检测到errCode:10002,网络或资源问题");
  2712. } else {
  2713. console.log("iOS小程序其他音频错误:", err.errCode);
  2714. }
  2715. this.useIOSMiniProgramTextFallback(audioContext);
  2716. });
  2717. audioContext.src = this.aiVoiceUrl;
  2718. audioContext.onPlay(() => {
  2719. console.log("iOS小程序音频开始播放");
  2720. this.currentSubtitle = this.aiText;
  2721. });
  2722. audioContext.onEnded(() => {
  2723. console.log("iOS小程序音频播放结束");
  2724. this.handleIOSMiniProgramAudioComplete(audioContext);
  2725. });
  2726. const playTimeout = setTimeout(() => {
  2727. if (this.isPlayingAiVoice) {
  2728. console.log("iOS小程序音频播放超时,切换到文本显示");
  2729. clearTimeout(playTimeout);
  2730. this.useIOSMiniProgramTextFallback(audioContext);
  2731. }
  2732. }, 3e3);
  2733. audioContext.play();
  2734. } catch (e) {
  2735. console.error("iOS小程序音频播放初始化失败:", e);
  2736. this.handleAudioPlaybackFailure();
  2737. }
  2738. },
  2739. // 添加新方法:iOS小程序音频播放完成
  2740. handleIOSMiniProgramAudioComplete(audioContext) {
  2741. this.isPlayingAiVoice = false;
  2742. setTimeout(() => {
  2743. this.currentSubtitle = "";
  2744. }, 2e3);
  2745. if (audioContext) {
  2746. try {
  2747. audioContext.destroy();
  2748. } catch (e) {
  2749. console.error("销毁iOS小程序音频播放器失败:", e);
  2750. }
  2751. }
  2752. this.showContinueQuestionOptions();
  2753. this.checkPendingNavigation();
  2754. },
  2755. // 添加新方法:iOS小程序音频错误处理
  2756. handleIOSMiniProgramAudioError(audioContext, error) {
  2757. console.error("iOS小程序音频错误:", error);
  2758. if (error.errCode === 10002) {
  2759. this.useIOSMiniProgramTextFallback(audioContext);
  2760. } else {
  2761. this.useIOSMiniProgramTextFallback(audioContext);
  2762. }
  2763. },
  2764. // 添加新方法:iOS小程序文本回退
  2765. useIOSMiniProgramTextFallback(audioContext) {
  2766. console.log("iOS小程序使用文本回退方案");
  2767. if (audioContext) {
  2768. try {
  2769. audioContext.destroy();
  2770. } catch (e) {
  2771. console.error("销毁音频播放器失败:", e);
  2772. }
  2773. }
  2774. this.isPlayingAiVoice = false;
  2775. this.currentSubtitle = this.aiText || "抱歉,AI回复内容加载失败";
  2776. const textLength = this.aiText ? this.aiText.length : 20;
  2777. const readingTime = Math.max(6e3, Math.min(textLength * 120, 18e3));
  2778. setTimeout(() => {
  2779. this.handleIOSMiniProgramAudioComplete(null);
  2780. }, readingTime);
  2781. },
  2782. // 添加新方法:处理音频播放错误
  2783. handleAudioPlaybackError(error) {
  2784. console.error("音频播放错误:", error);
  2785. if (!this.hasTriedFallbackMethod) {
  2786. this.hasTriedFallbackMethod = true;
  2787. this.tryFallbackAudioPlay();
  2788. return;
  2789. }
  2790. this.handleAudioPlaybackFailure();
  2791. },
  2792. // 添加新方法:尝试备选音频播放方法
  2793. tryFallbackAudioPlay() {
  2794. console.log("使用备选方法播放音频:", this.aiVoiceUrl);
  2795. if (this.aiAudioPlayer) {
  2796. try {
  2797. this.aiAudioPlayer.destroy();
  2798. } catch (e) {
  2799. console.error("销毁音频播放器失败:", e);
  2800. }
  2801. this.aiAudioPlayer = null;
  2802. }
  2803. common_vendor.index.downloadFile({
  2804. url: this.aiVoiceUrl,
  2805. success: (res) => {
  2806. if (res.statusCode === 200) {
  2807. console.log("音频文件下载成功:", res.tempFilePath);
  2808. const newAudioPlayer = common_vendor.index.createInnerAudioContext();
  2809. this.aiAudioPlayer = newAudioPlayer;
  2810. newAudioPlayer.autoplay = true;
  2811. newAudioPlayer.src = res.tempFilePath;
  2812. newAudioPlayer.onPlay(() => {
  2813. console.log("备选方法:音频开始播放");
  2814. });
  2815. newAudioPlayer.onEnded(() => {
  2816. console.log("备选方法:音频播放结束");
  2817. this.isPlayingAiVoice = false;
  2818. this.currentSubtitle = "";
  2819. newAudioPlayer.destroy();
  2820. this.aiAudioPlayer = null;
  2821. this.showContinueQuestionOptions();
  2822. this.checkPendingNavigation();
  2823. });
  2824. newAudioPlayer.onError((err) => {
  2825. console.error("备选方法:音频播放错误:", err);
  2826. this.isPlayingAiVoice = false;
  2827. this.currentSubtitle = "";
  2828. newAudioPlayer.destroy();
  2829. this.aiAudioPlayer = null;
  2830. this.showContinueQuestionOptions();
  2831. this.checkPendingNavigation();
  2832. });
  2833. } else {
  2834. console.error("音频文件下载失败:", res);
  2835. this.handleAudioPlaybackFailure();
  2836. }
  2837. },
  2838. fail: (err) => {
  2839. console.error("音频文件下载请求失败:", err);
  2840. this.handleAudioPlaybackFailure();
  2841. }
  2842. });
  2843. },
  2844. // 添加新方法:处理音频播放失败的情况
  2845. handleAudioPlaybackFailure() {
  2846. this.isPlayingAiVoice = false;
  2847. this.currentSubtitle = this.aiText;
  2848. setTimeout(() => {
  2849. this.currentSubtitle = "";
  2850. this.showContinueQuestionOptions();
  2851. this.checkPendingNavigation();
  2852. }, 1e4);
  2853. },
  2854. // 添加新方法:从视频中提取音频
  2855. async extractAudioFromVideo(videoBlob) {
  2856. console.log("开始从视频中提取音频");
  2857. return new Promise((resolve, reject) => {
  2858. try {
  2859. const videoElement = document.createElement("video");
  2860. videoElement.muted = false;
  2861. videoElement.autoplay = false;
  2862. const audioContext = new (window.AudioContext || window.webkitAudioContext)();
  2863. let audioDestination = null;
  2864. let mediaRecorder = null;
  2865. const audioChunks = [];
  2866. videoElement.src = URL.createObjectURL(videoBlob);
  2867. videoElement.onloadedmetadata = () => {
  2868. console.log("视频元数据已加载,视频时长:", videoElement.duration);
  2869. const source = audioContext.createMediaElementSource(videoElement);
  2870. audioDestination = audioContext.createMediaStreamDestination();
  2871. source.connect(audioDestination);
  2872. mediaRecorder = new MediaRecorder(audioDestination.stream);
  2873. mediaRecorder.ondataavailable = (event) => {
  2874. if (event.data.size > 0) {
  2875. audioChunks.push(event.data);
  2876. }
  2877. };
  2878. mediaRecorder.onstop = () => {
  2879. const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
  2880. console.log("音频提取完成,大小:", audioBlob.size);
  2881. resolve(audioBlob);
  2882. };
  2883. videoElement.onplay = () => {
  2884. mediaRecorder.start(100);
  2885. };
  2886. videoElement.onended = () => {
  2887. mediaRecorder.stop();
  2888. audioContext.close();
  2889. };
  2890. videoElement.play();
  2891. };
  2892. videoElement.onerror = (err) => {
  2893. console.error("视频加载失败:", err);
  2894. reject(new Error("视频加载失败"));
  2895. };
  2896. } catch (err) {
  2897. console.error("提取音频失败:", err);
  2898. reject(err);
  2899. }
  2900. });
  2901. },
  2902. // 添加新方法:上传音频文件
  2903. async uploadAudioFile(audioBlob, videoUrl) {
  2904. console.log("准备上传音频文件");
  2905. const formData = new FormData();
  2906. const fileName = `audio_${Date.now()}.wav`;
  2907. const audioFile = new File([audioBlob], fileName, { type: "audio/wav" });
  2908. formData.append("audio_file", audioFile);
  2909. formData.append("video_url", videoUrl);
  2910. formData.append("tenant_id", common_vendor.index.getStorageSync("tenant_id") || "1");
  2911. formData.append("openid", common_vendor.index.getStorageSync("userInfo") ? JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid : "");
  2912. formData.append("application_id", common_vendor.index.getStorageSync("appId") || "");
  2913. return new Promise((resolve, reject) => {
  2914. const xhr = new XMLHttpRequest();
  2915. xhr.open("POST", `${common_config.apiBaseUrl}/api/voice_ai_interaction`, true);
  2916. xhr.timeout = 6e4;
  2917. xhr.onload = () => {
  2918. if (xhr.status === 200) {
  2919. try {
  2920. const response = JSON.parse(xhr.responseText);
  2921. resolve(response);
  2922. } catch (e) {
  2923. reject(new Error("解析响应失败"));
  2924. }
  2925. } else {
  2926. reject(new Error("HTTP状态: " + xhr.status));
  2927. }
  2928. };
  2929. xhr.onerror = () => {
  2930. reject(new Error("网络错误"));
  2931. };
  2932. xhr.ontimeout = () => {
  2933. reject(new Error("请求超时"));
  2934. };
  2935. xhr.send(formData);
  2936. });
  2937. },
  2938. // 添加一个新方法:使用小程序原生音频API
  2939. /* playMiniProgramAudio() {
  2940. console.log('使用小程序原生音频API播放:', this.aiVoiceUrl);
  2941. // 标记正在播放AI语音
  2942. this.isPlayingAiVoice = true;
  2943. // 确保在播放期间不显示继续提问按钮
  2944. this.showContinueQuestionButton = false;
  2945. this.showEndInterviewButton = false;
  2946. // 检查音频URL是否有效
  2947. if (!this.aiVoiceUrl || this.aiVoiceUrl.trim() === '') {
  2948. console.error('无效的音频URL');
  2949. // 显示错误提示
  2950. // 标记播放结束
  2951. this.isPlayingAiVoice = false;
  2952. // 显示继续提问选项
  2953. this.showContinueQuestionOptions();
  2954. return;
  2955. }
  2956. try {
  2957. // 使用wx.createInnerAudioContext API (微信小程序)
  2958. const audioContext = wx.createInnerAudioContext();
  2959. // 设置音频属性
  2960. audioContext.autoplay = false;
  2961. audioContext.obeyMuteSwitch = false; // 忽略静音开关
  2962. // 监听播放开始事件
  2963. audioContext.onPlay(() => {
  2964. console.log('AI语音开始播放');
  2965. // 显示正在播放提
  2966. });
  2967. // 监听播放结束事件
  2968. audioContext.onEnded(() => {
  2969. console.log('AI语音播放结束');
  2970. // 标记播放结束
  2971. this.isPlayingAiVoice = false;
  2972. // 清空字幕
  2973. this.currentSubtitle = '';
  2974. // 销毁音频播放器
  2975. audioContext.destroy();
  2976. // 播放结束后显示继续提问选项,而不是直接跳转
  2977. this.showContinueQuestionOptions();
  2978. });
  2979. // 监听播放错误事件
  2980. audioContext.onError((err) => {
  2981. console.error('AI语音播放错误:', err);
  2982. // 标记播放结束
  2983. this.isPlayingAiVoice = false;
  2984. // 清空字幕
  2985. this.currentSubtitle = '';
  2986. // 销毁音频播放器
  2987. audioContext.destroy();
  2988. // 播放错误时也显示继续提问选项
  2989. this.showContinueQuestionOptions();
  2990. });
  2991. // 设置音频源
  2992. audioContext.src = this.aiVoiceUrl;
  2993. // 添加超时处理,如果5秒内没有开始播放,则认为出错
  2994. const playTimeout = setTimeout(() => {
  2995. if (this.isPlayingAiVoice) {
  2996. console.warn('小程序音频播放超时,尝试备选方法');
  2997. this.tryMiniProgramFallbackAudioPlay();
  2998. }
  2999. }, 5000);
  3000. // 延迟一小段时间再播放,确保src已经设置完成
  3001. setTimeout(() => {
  3002. audioContext.play();
  3003. // 播放开始后清除超时
  3004. clearTimeout(playTimeout);
  3005. }, 300);
  3006. } catch (e) {
  3007. console.error('小程序播放AI语音时发生错误:', e);
  3008. // 标记播放结束
  3009. this.isPlayingAiVoice = false;
  3010. // 显示错误提示
  3011. // 使用文本显示方式作为备选方案
  3012. this.handleAudioPlaybackFailure();
  3013. }
  3014. }, */
  3015. // 添加新方法:小程序环境的备选音频播放方法
  3016. tryMiniProgramFallbackAudioPlay() {
  3017. console.log("使用小程序备选方法播放音频:", this.aiVoiceUrl);
  3018. common_vendor.index.downloadFile({
  3019. url: this.aiVoiceUrl,
  3020. success: (res) => {
  3021. if (res.statusCode === 200) {
  3022. console.log("小程序音频文件下载成功:", res.tempFilePath);
  3023. const newAudioContext = common_vendor.wx$1.createInnerAudioContext();
  3024. newAudioContext.autoplay = true;
  3025. newAudioContext.src = res.tempFilePath;
  3026. newAudioContext.onPlay(() => {
  3027. console.log("小程序备选方法:音频开始播放");
  3028. });
  3029. newAudioContext.onEnded(() => {
  3030. console.log("小程序备选方法:音频播放结束");
  3031. this.isPlayingAiVoice = false;
  3032. this.currentSubtitle = "";
  3033. newAudioContext.destroy();
  3034. this.showContinueQuestionOptions();
  3035. this.checkPendingNavigation();
  3036. });
  3037. newAudioContext.onError((err) => {
  3038. console.error("小程序备选方法:音频播放错误:", err);
  3039. this.isPlayingAiVoice = false;
  3040. this.currentSubtitle = "";
  3041. newAudioContext.destroy();
  3042. this.trySystemAudioPlayer();
  3043. });
  3044. } else {
  3045. console.error("小程序音频文件下载失败:", res);
  3046. this.handleAudioPlaybackFailure();
  3047. }
  3048. },
  3049. fail: (err) => {
  3050. console.error("小程序音频文件下载请求失败:", err);
  3051. this.handleAudioPlaybackFailure();
  3052. }
  3053. });
  3054. },
  3055. // 添加新方法:尝试使用系统播放器
  3056. trySystemAudioPlayer() {
  3057. console.log("尝试使用系统播放器播放音频");
  3058. const systemInfo = common_vendor.index.getSystemInfoSync();
  3059. if (systemInfo.platform === "android" || systemInfo.platform === "ios") {
  3060. if (typeof common_vendor.index.playVoice === "function") {
  3061. common_vendor.index.playVoice({
  3062. filePath: this.aiVoiceUrl,
  3063. success: () => {
  3064. console.log("系统播放器播放成功");
  3065. setTimeout(() => {
  3066. this.isPlayingAiVoice = false;
  3067. this.currentSubtitle = "";
  3068. this.showContinueQuestionOptions();
  3069. }, 5e3);
  3070. },
  3071. fail: (err) => {
  3072. console.error("系统播放器播放失败:", err);
  3073. this.handleAudioPlaybackFailure();
  3074. }
  3075. });
  3076. } else {
  3077. common_vendor.index.openDocument({
  3078. filePath: this.aiVoiceUrl,
  3079. fileType: "audio",
  3080. success: () => {
  3081. console.log("使用系统应用打开音频文件");
  3082. setTimeout(() => {
  3083. this.isPlayingAiVoice = false;
  3084. this.currentSubtitle = "";
  3085. this.showContinueQuestionOptions();
  3086. }, 8e3);
  3087. },
  3088. fail: (err) => {
  3089. console.error("无法使用系统应用打开音频:", err);
  3090. this.handleAudioPlaybackFailure();
  3091. }
  3092. });
  3093. }
  3094. } else {
  3095. this.handleAudioPlaybackFailure();
  3096. }
  3097. },
  3098. // 修改 showContinueQuestionOptions 方法,确保状态正确设置
  3099. showContinueQuestionOptions() {
  3100. if (this.isPlayingAiVoice) {
  3101. console.log("AI语音正在播放,暂不显示继续提问选项");
  3102. return;
  3103. }
  3104. this.questionRound++;
  3105. this.currentSubtitle = "";
  3106. console.log("准备跳转到下一页面");
  3107. setTimeout(() => {
  3108. this.navigateToNextPage();
  3109. }, 3e3);
  3110. this.isRecording = false;
  3111. if (this.recordingTimer) {
  3112. clearInterval(this.recordingTimer);
  3113. this.recordingTimer = null;
  3114. }
  3115. this.recordedChunks = [];
  3116. this.recordingTimerCount = 0;
  3117. this.remainingTime = this.maxRecordingTime;
  3118. },
  3119. // 修复 handleContinueQuestionClick 方法,确保状态正确重置
  3120. handleContinueQuestionClick() {
  3121. if (this.isPlayingAiVoice) {
  3122. return;
  3123. }
  3124. this.showContinueQuestionButton = false;
  3125. this.showEndInterviewButton = false;
  3126. this.isRecording = false;
  3127. this.recordingTimerCount = 0;
  3128. this.remainingTime = this.maxRecordingTime;
  3129. this.recordingTimeDisplay = "00:00 / " + this.formatTime(this.maxRecordingTime);
  3130. this.recordedChunks = [];
  3131. if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
  3132. this.mediaRecorder.stop();
  3133. }
  3134. if (this.recorder) {
  3135. try {
  3136. this.cameraContext.stopRecord();
  3137. } catch (e) {
  3138. console.error("停止录制失败:", e);
  3139. }
  3140. this.recorder = null;
  3141. }
  3142. setTimeout(() => {
  3143. this.startRecordingAnswer();
  3144. }, 500);
  3145. },
  3146. // 添加新方法:处理结束面试按钮点击
  3147. handleEndInterviewClick() {
  3148. this.showContinueQuestionButton = false;
  3149. this.showEndInterviewButton = false;
  3150. this.navigateToNextPage();
  3151. },
  3152. // 添加新方法:处理录制错误
  3153. handleRecordingError(error) {
  3154. console.error("录制错误:", error);
  3155. this.isRecording = false;
  3156. this.showStopRecordingButton = false;
  3157. this.showStartRecordingButton = true;
  3158. },
  3159. // 添加新方法:处理上传错误
  3160. handleUploadError(error) {
  3161. console.error("上传错误:", error);
  3162. this.showRetryButton = true;
  3163. this.showUploadStatus = false;
  3164. this.isUploading = false;
  3165. },
  3166. // 添加新方法:检查是否有待处理的自动跳转
  3167. checkPendingNavigation() {
  3168. if (this.pendingAutoNavigation && !this.isPlayingAiVoice && !this.isUploading && !this.currentSubtitle) {
  3169. console.log("所有处理已完成,准备跳转");
  3170. this.pendingAutoNavigation = false;
  3171. setTimeout(() => {
  3172. this.navigateToNextPage();
  3173. }, 1e3);
  3174. }
  3175. },
  3176. // 添加新方法:显示文本回复
  3177. displayTextResponse() {
  3178. this.isPlayingAiVoice = true;
  3179. this.currentSubtitle = "";
  3180. const charDisplayTime = 200;
  3181. let currentIndex = 0;
  3182. const textInterval = setInterval(() => {
  3183. if (currentIndex <= this.aiText.length) {
  3184. this.currentSubtitle = this.aiText.substring(0, currentIndex);
  3185. currentIndex++;
  3186. } else {
  3187. clearInterval(textInterval);
  3188. setTimeout(() => {
  3189. this.isPlayingAiVoice = false;
  3190. this.currentSubtitle = "";
  3191. this.showContinueQuestionOptions();
  3192. this.checkPendingNavigation();
  3193. }, 3e3);
  3194. }
  3195. }, charDisplayTime);
  3196. },
  3197. // 添加新方法:检查不支持的音频格式
  3198. checkUnsupportedAudioFormat(url) {
  3199. if (!url)
  3200. return false;
  3201. const extension = url.split(".").pop().toLowerCase();
  3202. const systemInfo = common_vendor.index.getSystemInfoSync();
  3203. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  3204. if (isMiniProgram) {
  3205. const unsupportedFormats = ["ogg", "flac", "aac", "m4a", "opus"];
  3206. return unsupportedFormats.includes(extension);
  3207. }
  3208. return false;
  3209. },
  3210. // 修改文本回退方法
  3211. useIOSTextFallback() {
  3212. console.log("切换到文本显示模式");
  3213. this.isPlayingAiVoice = false;
  3214. if (!this.hasShownTextFallbackToast) {
  3215. this.hasShownTextFallbackToast = true;
  3216. }
  3217. this.currentSubtitle = this.aiText || "抱歉,无法获取AI回复内容";
  3218. const textLength = this.aiText ? this.aiText.length : 20;
  3219. const readingTime = Math.max(8e3, Math.min(textLength * 150, 2e4));
  3220. console.log(`文本长度: ${textLength}字,预计阅读时间: ${readingTime / 1e3}秒`);
  3221. setTimeout(() => {
  3222. this.navigateToNextPage();
  3223. }, readingTime);
  3224. },
  3225. // 添加音频预加载方法
  3226. preloadAudio(audioUrl) {
  3227. return new Promise((resolve, reject) => {
  3228. console.log("开始预加载音频:", audioUrl);
  3229. const downloadTask = common_vendor.wx$1.downloadFile({
  3230. url: audioUrl,
  3231. success: (res) => {
  3232. if (res.statusCode === 200) {
  3233. console.log("音频文件下载成功,临时路径:", res.tempFilePath);
  3234. resolve(res.tempFilePath);
  3235. } else {
  3236. console.error("音频文件下载失败,状态码:", res.statusCode);
  3237. reject(new Error(`下载失败,状态码: ${res.statusCode}`));
  3238. }
  3239. },
  3240. fail: (error) => {
  3241. console.error("音频文件下载失败:", error);
  3242. reject(error);
  3243. }
  3244. });
  3245. downloadTask.onProgressUpdate((res) => {
  3246. console.log("音频下载进度:", res.progress);
  3247. });
  3248. });
  3249. },
  3250. // 修改音频播放方法
  3251. playMiniProgramAudio() {
  3252. return new Promise(async (resolve, reject) => {
  3253. try {
  3254. common_vendor.index.showLoading({
  3255. title: "音频加载中...",
  3256. mask: true
  3257. });
  3258. const localAudioPath = await this.preloadAudio(this.aiVoiceUrl);
  3259. common_vendor.index.hideLoading();
  3260. const audioContext = common_vendor.wx$1.createInnerAudioContext();
  3261. audioContext.src = localAudioPath;
  3262. audioContext.autoplay = true;
  3263. audioContext.bufferSize = 4096;
  3264. let hasStarted = false;
  3265. let hasError = false;
  3266. audioContext.onPlay(() => {
  3267. console.log("AI语音开始播放");
  3268. hasStarted = true;
  3269. this.currentSubtitle = this.aiText;
  3270. });
  3271. audioContext.onEnded(() => {
  3272. console.log("AI语音播放结束");
  3273. this.isPlayingAiVoice = false;
  3274. this.currentSubtitle = "";
  3275. audioContext.destroy();
  3276. if (!hasError) {
  3277. console.log("准备跳转到下一页");
  3278. this.navigateToNextPage();
  3279. resolve();
  3280. }
  3281. });
  3282. audioContext.onStop(() => {
  3283. console.log("AI语音播放停止");
  3284. this.isPlayingAiVoice = false;
  3285. this.currentSubtitle = "";
  3286. audioContext.destroy();
  3287. if (!hasError) {
  3288. console.log("播放停止,准备跳转到下一页");
  3289. this.navigateToNextPage();
  3290. resolve();
  3291. }
  3292. });
  3293. audioContext.onError((err) => {
  3294. hasError = true;
  3295. console.error("AI语音播放错误:", err);
  3296. audioContext.destroy();
  3297. common_vendor.index.showToast({
  3298. title: "音频播放异常,将显示文字",
  3299. icon: "none",
  3300. duration: 2e3
  3301. });
  3302. if (this.aiVoiceUrl.endsWith(".mp3")) {
  3303. const wavUrl = this.aiVoiceUrl.replace(".mp3", ".wav");
  3304. console.log("尝试使用WAV格式:", wavUrl);
  3305. this.aiVoiceUrl = wavUrl;
  3306. this.playMiniProgramAudio().then(resolve).catch(reject);
  3307. } else {
  3308. reject(err);
  3309. }
  3310. });
  3311. setTimeout(() => {
  3312. if (!hasStarted && !hasError) {
  3313. console.error("音频播放启动超时");
  3314. audioContext.destroy();
  3315. reject(new Error("音频播放启动超时"));
  3316. }
  3317. }, 5e3);
  3318. } catch (error) {
  3319. common_vendor.index.hideLoading();
  3320. console.error("音频播放初始化失败:", error);
  3321. reject(error);
  3322. }
  3323. });
  3324. },
  3325. // 添加备选的音频播放方法
  3326. async playFallbackAudio() {
  3327. return new Promise((resolve, reject) => {
  3328. try {
  3329. const audio = common_vendor.wx$1.createInnerAudioContext();
  3330. audio.volume = 1;
  3331. audio.playbackRate = 1;
  3332. audio.src = this.aiVoiceUrl;
  3333. audio.autoplay = true;
  3334. audio.onPlay(() => {
  3335. console.log("备选音频开始播放");
  3336. });
  3337. audio.onEnded(() => {
  3338. console.log("备选音频播放完成");
  3339. audio.destroy();
  3340. resolve();
  3341. });
  3342. audio.onError((err) => {
  3343. console.error("备选音频播放失败:", err);
  3344. audio.destroy();
  3345. reject(err);
  3346. });
  3347. } catch (error) {
  3348. reject(error);
  3349. }
  3350. });
  3351. },
  3352. // 修改主音频播放方法
  3353. async playAiVoice() {
  3354. console.log("开始播放AI语音:", this.aiVoiceUrl);
  3355. this.isPlayingAiVoice = true;
  3356. this.currentSubtitle = this.aiText;
  3357. try {
  3358. await this.playMiniProgramAudio();
  3359. console.log("音频播放完成,准备跳转");
  3360. this.navigateToNextPage();
  3361. } catch (error) {
  3362. console.error("主要播放方法失败,尝试备选方法:", error);
  3363. try {
  3364. await this.playFallbackAudio();
  3365. console.log("备选音频播放完成,准备跳转");
  3366. this.navigateToNextPage();
  3367. } catch (fallbackError) {
  3368. console.error("备选播放方法也失败:", fallbackError);
  3369. this.useTextFallbackAndNavigate();
  3370. }
  3371. }
  3372. },
  3373. // 监听字幕内容变化
  3374. handleSubtitleChange() {
  3375. this.$nextTick(() => {
  3376. const subtitleEl = document.querySelector(".subtitle-overlay");
  3377. if (subtitleEl) {
  3378. const contentHeight = subtitleEl.scrollHeight;
  3379. this.subtitleHeight = contentHeight;
  3380. this.isSubtitleExpanded = contentHeight > window.innerHeight * 0.3;
  3381. }
  3382. });
  3383. }
  3384. },
  3385. // 添加watch来监听字幕内容变化
  3386. watch: {
  3387. currentSubtitle: {
  3388. handler(newVal) {
  3389. if (newVal) {
  3390. this.handleSubtitleChange();
  3391. } else {
  3392. this.isSubtitleExpanded = false;
  3393. }
  3394. },
  3395. immediate: true
  3396. }
  3397. }
  3398. };
  3399. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  3400. return common_vendor.e({
  3401. a: $data.videoUrl,
  3402. b: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
  3403. c: common_vendor.o((...args) => $options.handleVideoEnded && $options.handleVideoEnded(...args)),
  3404. d: common_vendor.o((...args) => $options.handleTimeUpdate && $options.handleTimeUpdate(...args)),
  3405. e: $data.showAnswerButton
  3406. }, $data.showAnswerButton ? {
  3407. f: common_vendor.o((...args) => $options.handleAnswerButtonClick && $options.handleAnswerButtonClick(...args))
  3408. } : {}, {
  3409. g: $data.currentSubtitle
  3410. }, $data.currentSubtitle ? common_vendor.e({
  3411. h: common_vendor.t($data.currentSubtitle),
  3412. i: $data.showNextButton
  3413. }, $data.showNextButton ? {
  3414. j: common_vendor.o((...args) => $options.handleNextButtonClick && $options.handleNextButtonClick(...args))
  3415. } : {}, {
  3416. k: $data.isSubtitleExpanded ? 1 : "",
  3417. l: $data.subtitleHeight ? `${$data.subtitleHeight}px` : null
  3418. }) : {}, {
  3419. m: $data.useMiniProgramCameraComponent
  3420. }, $data.useMiniProgramCameraComponent ? {
  3421. n: common_vendor.o((...args) => $options.handleCameraError && $options.handleCameraError(...args))
  3422. } : {}, {
  3423. o: $data.loading
  3424. }, $data.loading ? {} : {}, {
  3425. p: $data.showDebugInfo
  3426. }, $data.showDebugInfo ? common_vendor.e({
  3427. q: $data.assistantResponse
  3428. }, $data.assistantResponse ? {
  3429. r: common_vendor.t($data.assistantResponse)
  3430. } : {}, {
  3431. s: $data.audioTranscript
  3432. }, $data.audioTranscript ? {
  3433. t: common_vendor.t($data.audioTranscript)
  3434. } : {}, {
  3435. v: common_vendor.f($data.processedResponses, (item, index, i0) => {
  3436. return common_vendor.e({
  3437. a: item.role
  3438. }, item.role ? {
  3439. b: common_vendor.t(item.role)
  3440. } : {}, {
  3441. c: item.transcript
  3442. }, item.transcript ? {
  3443. d: common_vendor.t(item.transcript)
  3444. } : {}, {
  3445. e: index
  3446. });
  3447. })
  3448. }) : {}, {
  3449. w: $data.showStopRecordingButton
  3450. }, $data.showStopRecordingButton ? {
  3451. x: common_vendor.o((...args) => $options.stopRecordingAnswer && $options.stopRecordingAnswer(...args))
  3452. } : {}, {
  3453. y: $data.isRecording
  3454. }, $data.isRecording ? {
  3455. z: common_vendor.t($data.recordingTimeDisplay || "00:00 / 05:00")
  3456. } : {}, {
  3457. A: $data.showStartRecordingButton
  3458. }, $data.showStartRecordingButton ? {
  3459. B: common_vendor.o((...args) => $options.handleStartRecordingClick && $options.handleStartRecordingClick(...args))
  3460. } : {}, {
  3461. C: $data.showRetryButton
  3462. }, $data.showRetryButton ? {
  3463. D: common_vendor.o((...args) => $options.retryVideoUpload && $options.retryVideoUpload(...args))
  3464. } : {}, {
  3465. E: $data.showCountdown
  3466. }, $data.showCountdown ? {
  3467. F: common_vendor.t($data.countdownValue)
  3468. } : {}, {
  3469. G: $data.isPlayingAiVoice
  3470. }, $data.isPlayingAiVoice ? {} : {}, {
  3471. H: $data.showContinueQuestionButton
  3472. }, $data.showContinueQuestionButton ? {
  3473. I: common_vendor.o((...args) => $options.handleContinueQuestionClick && $options.handleContinueQuestionClick(...args))
  3474. } : {});
  3475. }
  3476. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2a02c54e"]]);
  3477. wx.createPage(MiniProgramPage);