UNPKG

yinxing

Version:
52 lines (43 loc) 1.13 kB
const { HttpClient, bodyanalysis, contentCensor, easydl, face, imageClassify, imageProcess, imageSearch, kg, nlp, ocr, speech }=require("baidu-aip-sdk") const { baidu_speech_AppID:AppID, baidu_speech_APIKey:APIKey, baidu_speech_SecretKey:SecretKey, }=process.env const fs=require('mz/fs') const read=(i="img/yzm.jpg")=>fs.readFile(i).then(x=>x.toString("utf-8")) const conn=()=>new speech(AppID,APIKey,SecretKey) const audio2text=async (file_name='test.pcm')=>{ let c=conn() let voice =await fs.readFile(file_name); let voiceBuffer = new Buffer(voice); o={dev_pid: '1536', cuid: Math.random()} r1=await c.recognize(voiceBuffer, 'pcm', 16000) r2=await c.recognize(voiceBuffer, 'pcm', 16000,o ) console.log(r1) console.log(r2) } const txt2audio=async (file_name="t.txt")=>{ let c=new speech(AppID,APIKey,SecretKey) let o={ } //let o= {spd: 0, per: 4} let t = await read(file_name) r=await c.text2audio(t,o) console.log(r) s=fs.createWriteStream('t.mp3') s.write(r.data) } //txt2audio()