voice-check-modal.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const recorderManager = common_vendor.index.getRecorderManager();
  4. const _sfc_main = {
  5. name: "VoiceCheckModal",
  6. props: {
  7. visible: {
  8. type: Boolean,
  9. default: false
  10. }
  11. },
  12. data() {
  13. return {
  14. isRecording: false,
  15. waveData: Array(20).fill(20),
  16. // 初始波形数据
  17. waveTimer: null
  18. };
  19. },
  20. methods: {
  21. // 开始录音
  22. startRecording() {
  23. this.isRecording = true;
  24. recorderManager.start({
  25. duration: 1e4,
  26. sampleRate: 16e3,
  27. numberOfChannels: 1,
  28. encodeBitRate: 48e3,
  29. format: "wav"
  30. });
  31. this.waveTimer = setInterval(() => {
  32. this.waveData = this.waveData.map(() => Math.random() * 40 + 20);
  33. }, 100);
  34. },
  35. // 停止录音
  36. stopRecording() {
  37. this.isRecording = false;
  38. recorderManager.stop();
  39. clearInterval(this.waveTimer);
  40. this.waveData = Array(20).fill(20);
  41. },
  42. // 处理确认按钮点击
  43. handleConfirm() {
  44. if (!this.isRecording) {
  45. this.startRecording();
  46. } else {
  47. this.stopRecording();
  48. this.$emit("complete");
  49. }
  50. }
  51. },
  52. beforeDestroy() {
  53. clearInterval(this.waveTimer);
  54. }
  55. };
  56. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  57. return common_vendor.e({
  58. a: $props.visible
  59. }, $props.visible ? common_vendor.e({
  60. b: $data.isRecording
  61. }, $data.isRecording ? {
  62. c: common_vendor.f($data.waveData, (item, index, i0) => {
  63. return {
  64. a: index,
  65. b: item + "rpx"
  66. };
  67. })
  68. } : {}, {
  69. d: common_vendor.t($data.isRecording ? "读完了" : "开始"),
  70. e: common_vendor.o((...args) => $options.handleConfirm && $options.handleConfirm(...args))
  71. }) : {});
  72. }
  73. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ce199c44"]]);
  74. wx.createComponent(Component);