【SIS服务】视频文件中的声音,怎么识别?
1、SIS语音交互参考:https://support.huaweicloud.com/api-sis/sis_03_0005.html

SIS语音交互提供:实时语音识别、一句话识别、录音文件识别、录音文件识别极速版
2、如果需要识别视频中的声音,怎么办?
方案一
在实时语音识别、一句话识别、录音文件识别、录音文件识别极速版中,找符合场景、语种、文件格式的API接口。
比如:录音文件接口,可以识别视频中的声音

方案二(终极方案)
将视频中的声音转为wav或者MP3音频文件,并且设置采样率、声道等,再进行语音识别。
以Java语音为例,给出AudioExtractor.java,进行音频提取。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AudioExtractor {
public static void extractAudioFromMP4(String inputPath, String outputPath) throws IOException, InterruptedException {
// FFmpeg 命令:提取音频为 .mp3
String[] command = {
"C:\\ffmpeg-master-latest-win64-gpl-shared\\bin\\ffmpeg.exe",
"-i", inputPath,
"-vn",
"-ac", "2", // 2 声道
"-ar", "16000", // 采样率 16kHz
"-sample_fmt", "s16", // 16bit PCM
"-f","wav",
outputPath
};
Process process = new ProcessBuilder(command).start();
// 读取 FFmpeg 输出(可选)
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
process.waitFor();
}
public static void main(String[] args) {
try {
extractAudioFromMP4("D:\\*****\\video.mp4",
"D:\\*****\\video_output.wav");
System.out.println("音频提取完成!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
注意:"C:\\ffmpeg-master-latest-win64-gpl-shared\\bin\\ffmpeg.exe", 为ffmpeg.exe存放位置。
ffmpeg下载地址:https://www.ffmpeg.org/download.html
视频转化音频,速度非常快,不影响语音识别的及时性。
- 点赞
- 收藏
- 关注作者
评论(0)