Skip to content

Conversation

@Aroganta
Copy link

🤔 This is a

  • New feature
  • Bug fix
  • Site / Document optimization
  • TypeScript definition update
  • Refactoring
  • Performance improvement
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English
🇨🇳 Chinese

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

src/Audio.ts Outdated
}
}

async classifyGenre(files: File) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 api 的入参是 files 嘛?是不是可以直接用 data 传入的。

if (files[0]) {
const wavFile = await this.convertAudio(files[0]);
this.worker.postMessage(wavFile);
}
Copy link
Member

@hustcc hustcc May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API 设计如下:

import { Audio } from '@antv/a8';

const audio = new Audio();

audio.data(a);

const c = await audio.classifyGenre();

不使用 callback 的形式,伪代码这么实现:

async classifyGenre() {

  this.worker = new Worker(new URL('./classifyWorker.ts', import.meta.url), { type: 'module' });

  return new Promise((resolve, reject) => {

    this.worker.onmessage = (event) => {
      const { classifyOutput, classifyTime, label } = event.data;
      // this.classifyOutput = classifyOutput;
      // this.onclassify(label, classifyTime);
      resolve({ label, classifyTime, classifyOutput });
    };

    this.worker.onerror = (e) => {
      reject(e);
    }

    const wavFile = await this.convertAudio(files[0]);
      this.worker.postMessage(wavFile);
  })
}

self.onmessage = async function (event) {
const result = await classifyGenre(event.data);
self.postMessage(result);
}; No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码风格,用两个空格做缩进。

@hustcc
Copy link
Member

hustcc commented May 16, 2025

@Aroganta 单元测试报错,看看日志需要解决一下。

image

@antvis antvis deleted a comment from Issues-translate-bot May 16, 2025
@hustcc
Copy link
Member

hustcc commented May 19, 2025

lock 文件删除,并放到 git ignore 中。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Delete the lock file and put it in git ignore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants