Speechmatics adapter throws error if empty speechmatics transcript is provided
Describe the bug
If speechmatics api returns a transcript with no text, the speechmatics adapter throws an TypeError: Cannot read property 'children' of undefined error.
To Reproduce Steps to reproduce the behavior:
- Create transcript from audio with no spoken content in speechmatics.
- Load the transcript.
Expected behavior A empty transcript is shown in the editor and no error is thrown.
@murezzda do you have any thoughts on a workaround for this?
It might be a good edge case to add to the tests, and that we'd have to check the other STT adapters are handling as well.
@pietrop I haven't yet looked at it, but I plan on fixing this soon. Regarding other STT adapters I did not do any testing. I would also recommend to add them to the tests, as an empty transcript will occur from time to time in a productive environment (wrong/bad file or quality of audio).
I found two options for solving this problem:
- Handling empty transcripts in the adapters themselves.
- Handling the error in
TimedTextEditor'ssetEditorContentStatemethod, plus some handling in theWrapperBlockclass to ensure a valid timestamp is shown.
Depending on wether this is a speechmatics specific problem or not I would either opt for the first or the second option. Has someone tried to reproduce the problem with other stt vendors?
Thanks @murezzda,
Yeah, I was thinking about the first option. Seemed the most straight forward and easier to test. altho a lot of "logic repetition" across the adapters.
The second one could also be a good fix that works across adapters, but each adapter should still handle the "empty transcript conversion".
For option one, if an STT adapter gets an "empty transcript" if it returns this draftJS json like this one below
{
"blocks": [
{
"key": "67dlg",
"text": "",
"type": "paragraph",
"depth": 0,
"inlineStyleRanges": [],
"entityRanges": [],
"data": {
"speaker": "UKN",
"words": [],
"start": 0
}
}
],
"entityMap": {}
}
then it would be shown like this
you can try it in the demo app by importing draftJs json
But a user might not be clear on what to do next. eg start typing text, re-do the transcript etc..
However there might be a number of reasons why the transcript is empty. And I guess the choice to make is, if there's an empty transcript, should we just display an error message to say something went wrong and there's no automated transcript to correct?
It also feels like this might be something the parent app needs to handle? either fully or partially?
Happy to think it through a bit more and discuss
Ok, here's a proposed solution, feel free to disagree.
- Parent app is generally responsible to check if transcript is valid or not empty before passing it to the component.
- in case that fails, or dev forgets to implement it, it be good to have a fallback, that displays a message saying, the "The transcript does not contain any text" or something like that.
- The STT adapters can return a draftJS json similar to the one mentioned in the comment above.
-
TimedTextEditorcan display the error message instead of the DraftJs Editor if there is only one block and theentityRangesis an empty array and iftextattribute of the block is an empty string. (could also check forentityMapto be empty)
What do you think?