腾讯云语音识别 TXT 转 SRT 字幕 C++程序

仅考虑单文件单说话人识别,导出 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

转换程序样例

D:\qcloud_srt>srt.exe in.txt out.srt
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char * argv[])
{
    char infile[512],outfile[512];
    if(argc<2){
        printf("error: no input file\nusage: infile outfile "); 
        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");
    }
    fout = fopen (outfile, "w");
    if (!fout){
        printf("error:cannot write file");
    }
    
    char str[5120],str1[128],str2[128],str3[5120];int row=1;
    while(fgets(str,5120,fin)){
    	if(str[0]!='[') continue;
    	//printf("%s",str); 
	    sscanf(str, "\[%[^,],%[^]%*[]]  %[^\n]", str1, str2, str3);
	    //printf("%d|%s|%s|%s\n",row,str1,str2,str3);
	    fprintf(fout, "%d\n%s --> %s\n%s\n\n", row++,str1,str2,str3);
	}
    fclose(fin);
    fclose(fout);
    
    return(0);
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Back to Top