我有webm音频文件,并想转换为Google Cloud Speech API支持的flac / Linear16。知道我该怎么做吗?
在React前端上,我正在使用ReactMic来获取录制的音频。
<ReactMic
className="w-10 h-1 aspect-ratio ml2"
record={this.props.recording}
onData={this.props.onData}
onStop={this.props.onStop}
strokeColor="#FFFFFF"
/>
</div>
<div className="ma3">
<Button onClick={this.props.onStartRecord}>Start Recording</Button>
<Button onClick={this.props.onStopRecord}>Stop Recording</Button>
</div>
//各个功能
onStartRecord = e => {
this.setState({ recording: true });
};
onStopRecord = e => {
this.setState({ recording: false });
};
onStop = recordedBlob => {
this.setState({ recordedAudio: recordedBlob });
};
然后将录制的音频作为HTTP Post请求发送
let fd = new FormData();
fd.append("audio", this.state.recordedAudio.blob);
fetch(this.props.url + "speeches/", {
method: "post",
body: fd
})
.then(response => response.text())
.then(data => {
this.setState({ result: data });
});
在Java Spring后端,我将以MultipartFile的形式接收音频
@RequestMapping(value = "/speeches", method = RequestMethod.POST,
consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<String> speechToText(@RequestBody MultipartFile audio) {
return itemService.speechToText(audio);
}
现在的问题是该文件为webm格式,但Google Cloud Speech-To-Text API不支持该格式。有没有一种方法可以在前端或后端转换为flac / linear16格式。谢谢!