Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Latest commit

 

History

History
53 lines (46 loc) · 1.35 KB

README.md

File metadata and controls

53 lines (46 loc) · 1.35 KB

百度翻译API

本项目仅供学习参考

Build NPM Version

使用方式

  1. 通过npm安装baidu-fanyi-api
    npm i baidu-fanyi-api
  2. 导入BaiduFanyiAPI
    import { BaiduFanyiAPI } from 'baidu-fanyi-api';
    
    const api = new BaiduFanyiAPI();
    
    async function main() {
      await api.init();
      const data = await api.translate('我的', 'zh', 'en');
      console.log(data);
    }
    
    main();

功能概述

所有操作必须在init之后执行

  1. 多语种翻译
    await api.translate('你好', 'zh', 'en');
  2. 语种检测
    await api.langdetect('你好');
  3. 输入建议
    await api.suggest('你好');
  4. OCR图像识别
    const image = createReadStream(join(__dirname, '../img.png'));
    const data = await api.getOCR(image, 'en', 'en');
  5. TTS语音合成
    const steam = createWriteStream(join(__dirname, '../tts.mp3'));
    const data = await api.getTTS('你好!,我是一个机器人。', 'zh');
    data.pipe(steam);