영상 파일을 갤러리에서 선택후
FFmpegKit.executeAsync('-i $value -ar 44100 -ac 1 -c:v mpeg4 $value.wav', (e) async {
final returnCode = await e.getReturnCode();
if(ReturnCode.isSuccess(returnCode)){
speechTT(context, '${value}.wav', File(value));
print('okokokoko $e');
print('okokokoko value ${value}');
} else {
print('nononononono');
}
});
ffmpegkit 으로 영상에서 -ar 44100 랑 -ac 1 (audioChannel 을 1로 설정) 하며 오디오 파일추출
그 오디오파일로 google speech to text 를 받는다
그후 그걸 srt 파일 (자막파일)로 만들어 준다.
response는 second: nanoseconds: 로 오는데
Duration(dats: , hours: ,등등) 으로 만들어줄수도있고
if(value!= null){
String content = '';
int idx = value.results[0].alternatives[0].words.length;
int chunkSize = 4;
for(var i = 0; i < value.results.length; i++){
for (var j = 0; j < value.results[i].alternatives[0].words.length; j += chunkSize) {
content += '\\n${((j + chunkSize) ~/ chunkSize) + i}\\n';
if(value.results[i].alternatives[0].words.length > j + 3){
String startTimeSeconds = value.results[i].alternatives[0].words[j].startTime.seconds != null && value.results[i].alternatives[0].words[j].startTime.seconds != 0 && value.results[i].alternatives[0].words[j].startTime.seconds < 10
? '0${value.results[i].alternatives[0].words[j].startTime.seconds}'
: value.results[i].alternatives[0].words[j].startTime.seconds != null && value.results[i].alternatives[0].words[j].startTime.seconds != 0 && value.results[i].alternatives[0].words[j].startTime.seconds >= 10
? '${value.results[i].alternatives[0].words[j].startTime.seconds}'
: '00';
String startTimeNanos = value.results[i].alternatives[0].words[j].startTime.nanos != null && value.results[i].alternatives[0].words[j].startTime.nanos != 0
? '${valueInt.format(value.results[i].alternatives[0].words[j].startTime.nanos / 1000000)}'
: '000';
String endTimeSeconds = value.results[i].alternatives[0].words[j + 3].endTime.seconds != null && value.results[i].alternatives[0].words[j + 3].endTime.seconds != 0 && value.results[i].alternatives[0].words[j + 3].endTime.seconds < 10
? '0${value.results[i].alternatives[0].words[j + 3].endTime.seconds}'
: value.results[i].alternatives[0].words[j + 3].endTime.seconds != null && value.results[i].alternatives[0].words[j + 3].endTime.seconds != 0 && value.results[i].alternatives[0].words[j + 3].endTime.seconds >= 10
? '${value.results[i].alternatives[0].words[j + 3].endTime.seconds}'
: '00';
String endTimeNanos = value.results[i].alternatives[0].words[j + 3].endTime.nanos != null && value.results[i].alternatives[0].words[j + 3].endTime.nanos != 0
? '${valueInt.format(value.results[i].alternatives[0].words[j + 3].endTime.nanos / 1000000)}'
: '000';
content += '00:00:$startTimeSeconds,$startTimeNanos --> 00:00:$endTimeSeconds,$endTimeNanos\\n';
content += '${
value.results[i].alternatives[0].words[j].word} '
'${value.results[i].alternatives[0].words[j + 1].word} '
'${value.results[i].alternatives[0].words[j + 2].word} '
'${value.results[i].alternatives[0].words[j + 3].word} ';
} else {
String startTimeSeconds = value.results[i].alternatives[0].words[j].startTime.seconds != null && value.results[i].alternatives[0].words[j].startTime.seconds != 0 && value.results[i].alternatives[0].words[j].startTime.seconds < 10
? '0${value.results[i].alternatives[0].words[j].startTime.seconds}'
: value.results[i].alternatives[0].words[j].startTime.seconds != null && value.results[i].alternatives[0].words[j].startTime.seconds != 0 && value.results[i].alternatives[0].words[j].startTime.seconds >= 10
? '${value.results[i].alternatives[0].words[j].startTime.seconds}'
: '00';
String startTimeNanos = value.results[i].alternatives[0].words[j].startTime.nanos != null && value.results[i].alternatives[0].words[j].startTime.nanos != 0
? '${valueInt.format(value.results[i].alternatives[0].words[j].startTime.nanos / 1000000)}'
: '000';
String endTimeSeconds = value.results[i].alternatives[0].words.last.endTime.seconds != null && value.results[i].alternatives[0].words.last.endTime.seconds != 0 && value.results[i].alternatives[0].words.last.endTime.seconds < 10
? '0${value.results[i].alternatives[0].words.last.endTime.seconds}'
: value.results[i].alternatives[0].words.last.endTime.seconds != null && value.results[i].alternatives[0].words.last.endTime.seconds != 0 && value.results[i].alternatives[0].words.last.endTime.seconds >= 10
? '${value.results[i].alternatives[0].words.last.endTime.seconds}'
: '00';
String endTimeNanos = value.results[i].alternatives[0].words.last.endTime.nanos != null && value.results[i].alternatives[0].words.last.endTime.nanos != 0
? '${valueInt.format(value.results[i].alternatives[0].words.last.endTime.nanos / 1000000)}'
: '000';
content += '00:00:$startTimeSeconds,$startTimeNanos --> 00:00:$endTimeSeconds,$endTimeNanos\\n';
for(var k = j; k < value.results[i].alternatives[0].words.length; k++){
content += '${value.results[i].alternatives[0].words[k].word}';
}
}
content += '\\n';
}
}
String contentSrt = '''$content''';
print('after after: $contentSrt');
Navigator.of(_keyLoader.currentContext,rootNavigator: true).pop();//close the dialoge
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SubtitleUploader(videoFile: videoFile, subtitleText: contentSrt, isPatchSubtitle: false)),
).then((value) {
_handleRefresh();
});
}
사용가능
setState(() {
subtitleString = widget.subtitleText;
});
var object = subtitle.SubtitleObject(
data: subtitleString,
// data: widget.subtitleText,
type: subtitle.SubtitleType.srt,
);
setState(() {
parser = subtitle.SubtitleParser(object);
stringParser = parser.object.data;
});
printResult(parser.parsing());
print('parser.parsing().length ${parser.parsing().length}');
print('parser.parsing().length ${parser.parsing()[0]}');
print('parser.parsing().data ${parser.parsing()[0].data}');
print('parser.parsing().length ${parser.parsing()[1]}');
print('parser.parsing().data ${parser.parsing()[1].data}');
subtitleController = SubtitleController(
showSubtitles: true,
subtitleType: SubtitleType.srt,
// subtitlesContent: '''1
// 00:00:01,600 --> 00:00:04,200
// English (US)
//
// 2
// 00:00:05,900 --> 00:00:07,999
// This is a subtitle in American English
//
// 3
// 00:00:10,000 --> 00:00:14,000
// Adding subtitles is very easy to do''',
subtitlesContent: stringParser,
// subtitlesContent: widget.subtitleText,
// subtitleUrl: parser.object.data,
// subtitleUrl: widget.subtitleText,
// provider: SubtitleProvider.fromString(
// data: widget.subtitleText,
// type: SubtitleType.srt,
// )
);
로 srt parse 를 해준다
혹 수정이여서 srt파일을받아 수정을 해야될때는
var url = Uri.parse(widget.videoSubtitleUrl);
// var object = subtitle.SubtitleObject(
// data: url.path,
// // data: widget.subtitleText,
// type: subtitle.SubtitleType.srt,
// );
subtitle.SubtitleProvider provider = subtitle.NetworkSubtitle(url);
subtitle.SubtitleObject object = await provider.getSubtitle();
setState(() {
parser = subtitle.SubtitleParser(object);
stringParser = parser.object.data;
subtitleString = parser.object.data;
});
printResult(parser.parsing());
print('parser.parsing().length ${parser.parsing().length}');
print('parser.parsing().length ${parser.parsing()[0]}');
print('parser.parsing().data ${parser.parsing()[0].data}');
print('parser.parsing().length ${parser.parsing()[1]}');
print('subtitleString subtitleString subtitleString ${subtitleString}');
// print('video.title: ${widget.video.title}, video.level: ${widget.video.level}, video.type: ${widget.video.type}');
subtitleController = SubtitleController(
showSubtitles: true,
subtitleType: SubtitleType.srt,
subtitlesContent: stringParser,
// subtitlesContent: widget.subtitleText,
// subtitleUrl: parser.object.data,
// subtitleUrl: widget.subtitleText,
// provider: SubtitleProvider.fromString(
// data: widget.subtitleText,
// type: SubtitleType.srt,
// )
);