2016-09-28 3 views
1

나는 mp4 비디오 클립을 FLAC 오디오 파일로 변환하려고 시도하고 있으며, 다음과 같이 검색 할 수 있도록 동영상에서 단어를 뱉어 내고 있습니다. 특정 단어는 말했다. 나는 FLAC 파일로 MP4로 변환하기 위해 FFMPEG를 사용하고Google Speech API "요청시 샘플링 속도가 FLAC 헤더와 일치하지 않습니다."

{ 
    "error": { 
    "code": 400, 
    "message": "Sample rate in request does not match FLAC header.", 
    "status": "INVALID_ARGUMENT" 
    } 
} 

:

나는 모든 것을 나는 음성 API에서 오류를 얻고 것을 제외하고 작업을해야합니다. FLAC 파일을 명령에서 16 비트로 지정했지만 FLAC 파일을 마우스 오른쪽 버튼으로 클릭하면 Windows에서 302kbps라고 알려줍니다.

// convert mp4 video to 16 bit flac audio file 
$cmd = 'C:/wamp/www/ffmpeg/bin/ffmpeg.exe -i C:/wamp/www/test.mp4 -c:a flac -sample_fmt s16 C:/wamp/www/test.flac'; 
exec($cmd, $output); 

// convert flac to text so we can detect if certain words were said 
$data = array(
    "config" => array(
     "encoding" => "FLAC", 
     "sampleRate" => 16000, 
     "languageCode" => "en-US" 
    ), 
    "audio" => array(
     "content" => base64_encode(file_get_contents("test.flac")), 
    ) 
); 

$json_data = json_encode($data); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=MY_API_KEY'); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

$result = curl_exec($ch); 
+0

샘플 형식 (부호가 16으로 설정 됨)과 샘플 속도간에 차이가 있습니다. – fakedad

+0

감사합니다. 알아 냈습니다. Google Speech API는 비트, 샘플 및 채널과 함께 매우 까다 롭습니다. – kjdion84

답변

6

내 FFMPEG 명령에 매우 구체적인 것으로하여 고정 : 여기

내 PHP 코드

$cmd = 'C:/wamp/www/ffmpeg/bin/ffmpeg.exe -i C:/wamp/www/test.mp4 -acodec flac -bits_per_raw_sample 16 -ar 44100 -ac 1 C:/wamp/www/test.flac'; 
+0

오, 세상에 ... 이것은 실제로 일했습니다 .... 이것은 지난 24 시간 이래로 나를 죽이고 있습니다 ............ 어떻게 세상에서 짧은 명령이 작동하지 않았습니까 ?? – Mahesh

1

kjdion84의 대답은 잘 작동하고 난을 찾기 위해 좀 더 연주 근본 원인. this 대답, 모든 인코딩 만 지원 1 개 채널 (모노) 오디오 당으로

나는이 명령을 사용하여 FLAC 파일 생성되었습니다 요청

ffmpeg -i test.mp3 test.flac 

샘플 속도는하지 않습니다를 FLAC 헤더와 일치

그러나 -ac 1 (설정 오디오 채널 수를 1로 설정하여이 문제를 해결했습니다.

ffmpeg -i test.mp3 -ac 1 test.flac 

여기

const Speech = require('@google-cloud/speech'); 
const projectId = 'EnterProjectIdGeneratedByGoogle'; 

const speechClient = Speech({ 
    projectId: projectId 
}); 

// The name of the audio file to transcribe 
var fileName = '/home/user/Documents/test/test.flac'; 


// The audio file's encoding and sample rate 
const options = { 
    encoding: 'FLAC', 
    sampleRate: 44100 
}; 

// Detects speech in the audio file 
speechClient.recognize(fileName, options) 
    .then((results) => { 
     const transcription = results[0]; 
     console.log(`Transcription: ${transcription}`); 
    }, function(err) { 
     console.log(err); 
    }); 

샘플 속도가 16000 또는 44100 또는 다른 유효한 사람이 될 수 내 전체 Node.js 번호 및 인코딩은 FLAC 또는 LINEAR16 될 수 있습니다. Cloud Speech Docs

+1

이것은 굉장합니다. 내 대답보다 훨씬 짧고 & 간단하고, 내가 사랑하는 것이 있다면, 그것의 단순함. – kjdion84

관련 문제