鍍金池/ 問答/HTML5  影視  網(wǎng)絡(luò)安全  HTML/ JavaScript如何把視頻(video)轉(zhuǎn)為音頻(audio)?

JavaScript如何把視頻(video)轉(zhuǎn)為音頻(audio)?

用純 JavaScript 如何實現(xiàn)從 video 到 audio 的轉(zhuǎn)碼?(比如 mp4 到 wav)
PS:我的目的是想從網(wǎng)頁上抓取視頻的聲音轉(zhuǎn)換為音頻,然后通過訊飛等平臺識別出文字。

回答
編輯回答
厭遇

前端做不了的 實在想用js做的話
nodejs下用這個https://www.npmjs.com/package...

2017年5月19日 11:25
編輯回答
獨特范

參考了一下 stackoverflow https://stackoverflow.com/que...
以下代碼可以提取出音頻,但是音頻體積卻比源視頻大的問題卻沒解決。
有人提到了 offlineAudioContext.startRendering() 這個方法,獲取能解決體積問題?

var videoSrc = 'http://otof18y9e.bkt.clouddn.com/frag_bunny.mp4'

function startSelect(){
  var audioContext = new OfflineAudioContext(2, 44100 * 100, 44100);
  // var audioContext = new window.AudioContext()
  var videoFileAsBuffer = new Promise(requestVideo)
  videoFileAsBuffer.then(function (data) {
    console.log(data)
    audioContext.decodeAudioData(data).then(function (decodedAudioData) {
        mySoundBuffer = decodedAudioData
        soundSource = audioContext.createBufferSource()
        soundSource.buffer = mySoundBuffer
        soundSource.connect(audioContext.destination)
        // soundSource.start()
        console.log(mySoundBuffer.length)
    });
  })
}

function requestVideo(resolve){
  var xhr = new XMLHttpRequest()
  xhr.open('GET', videoSrc, true)
  xhr.responseType = 'arraybuffer' // 'blob'

  xhr.onload = function(e) {
      var binaryData = this.response
      // console.log(binaryData)
      resolve(binaryData)
  }

  xhr.send()
}
2018年6月19日 08:58
編輯回答
陌上花

在瀏覽器里是做不了的,可以通過nodejs來處理

2018年4月7日 18:10
編輯回答
懶洋洋

犯不著,用 ffpmeg 吧

2018年7月21日 09:43
編輯回答
下墜

這個是后臺做的 不管是音頻還是視頻都是屬于流得需要后臺轉(zhuǎn)換格式

2018年3月24日 13:05