仅考虑单文件单说话人识别,导出 TXT 格式为
file: out.mp3
***********************************result**************************************
[0:0.000,1:0.220] 段落1
[1:0.220,1:13.320] 段落2
[1:16.080,1:18.440] 段落3
JavaScript网页版
注:程序仅在本地浏览器中执行。
TXT 转 SRT 字幕生成器
上传包含腾讯云语音识别结果的 TXT 文件(可以选择多个),并转换为 SRT 字幕文件。每个文件的输出都可以单独下载。
转换完成!
C++ 转换程序样例
D:\qcloud_srt>srt.exe in.txt out.srt
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void convert_time(const char* input_time, char* output_time) {
int minutes;
float seconds;
sscanf(input_time, "%d:%f", &minutes, &seconds);
float total_seconds = minutes * 60 + seconds;
int total_milliseconds = (int)(total_seconds * 1000 + 0.5);
int hours = total_milliseconds / (3600 * 1000);
int mins = (total_milliseconds % (3600 * 1000)) / (60 * 1000);
int secs = (total_milliseconds % (60 * 1000)) / 1000;
int milliseconds = total_milliseconds % 1000;
sprintf(output_time, "%02d:%02d:%02d,%03d", hours, mins, secs, milliseconds);
}
int main(int argc, char * argv[]) {
char infile[512], outfile[512];
if (argc < 2) {
printf("error: no input file\nusage: infile outfile\n");
return 0;
}
strcpy(infile, argv[1]);
if (argc == 3) strcpy(outfile, argv[2]);
else strcpy(outfile, strcat(argv[1], ".srt"));
FILE * fin, * fout;
fin = fopen(infile, "r");
if (!fin) {
printf("error: cannot open infile\n");
return 0;
}
fout = fopen(outfile, "w");
if (!fout) {
printf("error: cannot write outfile\n");
fclose(fin);
return 0;
}
char str[5120], str1[128], str2[128], str3[5120];
int row = 1;
while (fgets(str, 5120, fin)) {
if (str[0] != '[') continue;
int ret = sscanf(str, "[%[^,],%[^]]] %[^\n]", str1, str2, str3);
if (ret < 3) continue;
char time1[16], time2[16];
convert_time(str1, time1);
convert_time(str2, time2);
fprintf(fout, "%d\n%s --> %s\n%s\n\n", row++, time1, time2, str3);
}
fclose(fin);
fclose(fout);
return 0;
}