Convert Azure Speech Transcription Result JSON file (.json) file to .VTT and .SRT (Java )
Budget: $30 – $250 USD
Azure transcription of an mp3 audio file result JSON file has this schema
=====
"word": "run",
"offset": "PT0.04S",
"duration": "PT0.48S",
"offsetInTicks": 400000.0,
"durationInTicks": 4800000.0,
"confidence": 0.968795
=====
we want to transform it to VTT/SRT file to include each word in the JSON + offset/duration
so that we can have a valid SRT/VTT , so that we can playback it with subtitles, output format will be like this (vtt example)
=====
00:11.000 --> 00:13.000
<v Roger Bingham>We are in New York City
00:13.000 --> 00:16.000
<v Roger Bingham>We’re actually at the Lucern Hotel, just down the street
=====. how to do it ===
Build Java8 method that:
1- receives JSON File path
2- read JSON file path
3- loop through the json objects, extracts words/phrases+ start + end
3- convert it to VALID .VTT and .SRT file
Method:
public static void convertJSONFileToSRTAndVRT(String jsonPath) {
}
help:
1- example of the JSON schema
https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/batch/transcriptionresult_v3.schema.json
2- what is VTT and SRT
https://jbilocalization.com/the-difference-between-srt-and-webvtt-in-captioning-subtitling/#:~:text=SRT%20separates%20seconds%20from%20milliseconds,they're%20almost%20always%20provided.
3- example:
{
"source": "https://www.contoso.com",
"timestamp": "2020-06-26T15:18:35Z",
"durationTicks": 74800000,
"duration": "PT7.48S",
"combinedRecognizedPhrases": [
{
"channel": 0,
"lexical": "run alabama drivers license zero zero three zero six six nine",
"itn": "run alabama drivers license 0030 669",
"maskedITN": "run alabama drivers license 0030 669",
"display": "Run Alabama drivers license. 0030 669"
}
],
"recognizedPhrases": [
{
"recognitionStatus": "Success",
"channel": 0,
"speaker": 1,
"offset": "PT0.04S",
"duration": "PT2.18S",
"offsetInTicks": 400000.0,
"durationInTicks": 21800000.0,
"nBest": [
{
"confidence": 0.9509893,
"lexical": "run alabama drivers license",
"itn": "run alabama drivers license",
"maskedITN": "run alabama drivers license",
"display": "Run Alabama drivers license.",
"words": [
{
"word": "run",
"offset": "PT0.04S",
"duration": "PT0.48S",
"offsetInTicks": 400000.0,
"durationInTicks": 4800000.0,
"confidence": 0.968795
},
{
"word": "alabama",
"offset": "PT0.52S",
"duration": "PT0.58S",
"offsetInTicks": 5200000.0,
"durationInTicks": 5800000.0,
"confidence": 0.986991
},
{
"word": "drivers",
"offset": "PT1.1S",
"duration": "PT0.52S",
"offsetInTicks": 11000000.0,
"durationInTicks": 5200000.0,
"confidence": 0.989197
},
{
"word": "license",
"offset": "PT1.62S",
"duration": "PT0.6S",
"offsetInTicks": 16200000.0,
"durationInTicks": 6000000.0,
"confidence": 0.996206
}
]
}
]
}
}
4- how to validate VTT example:
put output text/file into this website:
https://quuz.org/webvtt/
=====
"word": "run",
"offset": "PT0.04S",
"duration": "PT0.48S",
"offsetInTicks": 400000.0,
"durationInTicks": 4800000.0,
"confidence": 0.968795
=====
we want to transform it to VTT/SRT file to include each word in the JSON + offset/duration
so that we can have a valid SRT/VTT , so that we can playback it with subtitles, output format will be like this (vtt example)
=====
00:11.000 --> 00:13.000
<v Roger Bingham>We are in New York City
00:13.000 --> 00:16.000
<v Roger Bingham>We’re actually at the Lucern Hotel, just down the street
=====. how to do it ===
Build Java8 method that:
1- receives JSON File path
2- read JSON file path
3- loop through the json objects, extracts words/phrases+ start + end
3- convert it to VALID .VTT and .SRT file
Method:
public static void convertJSONFileToSRTAndVRT(String jsonPath) {
}
help:
1- example of the JSON schema
https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/batch/transcriptionresult_v3.schema.json
2- what is VTT and SRT
https://jbilocalization.com/the-difference-between-srt-and-webvtt-in-captioning-subtitling/#:~:text=SRT%20separates%20seconds%20from%20milliseconds,they're%20almost%20always%20provided.
3- example:
{
"source": "https://www.contoso.com",
"timestamp": "2020-06-26T15:18:35Z",
"durationTicks": 74800000,
"duration": "PT7.48S",
"combinedRecognizedPhrases": [
{
"channel": 0,
"lexical": "run alabama drivers license zero zero three zero six six nine",
"itn": "run alabama drivers license 0030 669",
"maskedITN": "run alabama drivers license 0030 669",
"display": "Run Alabama drivers license. 0030 669"
}
],
"recognizedPhrases": [
{
"recognitionStatus": "Success",
"channel": 0,
"speaker": 1,
"offset": "PT0.04S",
"duration": "PT2.18S",
"offsetInTicks": 400000.0,
"durationInTicks": 21800000.0,
"nBest": [
{
"confidence": 0.9509893,
"lexical": "run alabama drivers license",
"itn": "run alabama drivers license",
"maskedITN": "run alabama drivers license",
"display": "Run Alabama drivers license.",
"words": [
{
"word": "run",
"offset": "PT0.04S",
"duration": "PT0.48S",
"offsetInTicks": 400000.0,
"durationInTicks": 4800000.0,
"confidence": 0.968795
},
{
"word": "alabama",
"offset": "PT0.52S",
"duration": "PT0.58S",
"offsetInTicks": 5200000.0,
"durationInTicks": 5800000.0,
"confidence": 0.986991
},
{
"word": "drivers",
"offset": "PT1.1S",
"duration": "PT0.52S",
"offsetInTicks": 11000000.0,
"durationInTicks": 5200000.0,
"confidence": 0.989197
},
{
"word": "license",
"offset": "PT1.62S",
"duration": "PT0.6S",
"offsetInTicks": 16200000.0,
"durationInTicks": 6000000.0,
"confidence": 0.996206
}
]
}
]
}
}
4- how to validate VTT example:
put output text/file into this website:
https://quuz.org/webvtt/