o-oconnell / mp4grep

mp4grep is a CLI for transcribing and searching audio/video files
GNU General Public License v3.0
281 stars 6 forks source link

Vosk MalformedJsonException #17

Closed Matthias84 closed 2 years ago

Matthias84 commented 2 years ago

Hi there, I struggle on the usage of your tool. After the installation of the last release, I encounter the following error mp4grep --model $MP4GREP_MODEL --transcribe mytestfile.mp3

Exception in thread "Thread-2" com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected ':' at line 3 column 25 path $.result[0].861850
    at com.google.gson.Gson.fromJson(Gson.java:947)
    at com.google.gson.Gson.fromJson(Gson.java:897)
    at com.google.gson.Gson.fromJson(Gson.java:846)
    at com.google.gson.Gson.fromJson(Gson.java:817)
    at Transcribe.VoskAdapter.getJsonObject(VoskAdapter.java:163)
    at Transcribe.VoskAdapter.writeToCacheFiles(VoskAdapter.java:139)
    at Transcribe.VoskAdapter.writeMainRecognizerResults(VoskAdapter.java:120)
    at Transcribe.VoskAdapter.transcribeAudio(VoskAdapter.java:40)
    at Transcribe.VoskProxy.getSearchableTranscript(VoskProxy.java:14)
    at Transcribe.Cache.TranscriptCache.getSearchable(TranscriptCache.java:43)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:960)
    at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:934)
    at java.base/java.util.stream.AbstractTask.compute(AbstractTask.java:327)
    at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:754)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
    at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:686)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateParallel(ReduceOps.java:927)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at Transcribe.TranscriptAdapter.lambda$getTranscription$1(TranscriptAdapter.java:140)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: com.google.gson.stream.MalformedJsonException: Expected ':' at line 3 column 25 path $.result[0].861850
    at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1562)
    at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:529)
    at com.google.gson.stream.JsonReader.peek(JsonReader.java:424)
    at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:700)
    at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:723)
    at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:715)
    at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:723)
    at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:698)
    at com.google.gson.internal.bind.TypeAdapters$35$1.read(TypeAdapters.java:894)
    at com.google.gson.Gson.fromJson(Gson.java:932)
    ... 24 more

I tried different audio files and different models, always with this error. If I call the tool again, it just raises 100% transcription, but no text is plottet.

o-oconnell commented 2 years ago

Have you tried clearing the contents of your cache directory ($MP4GREP_CACHE) and then transcribing again? Does this issue only occur when you use the --transcribe option?

Matthias84 commented 2 years ago

Hi, i cleaned the cache, but if I fire up the line without explicitly adding model param, it seems to be confused, even if the var is set properly?

mp4grep --transcribe ~/Musik/Marc-Uwe\ Kling/Qualityland\ 2/1-02\ Qualityland\ 2.0.mp3 Model directory "model" not found. Exiting.

echo $MP4GREP_MODEL /home/matthias/Downloads/mp4grep-0.1.1/model

o-oconnell commented 2 years ago

Have you exported $MP4GREP_MODEL so that the variable also exists in the shell through which mp4grep is run? Is the variable set in your .bashrc? You may need to run export MP4GREP_MODEL=/home/..../model before running mp4grep --transcribe.

Matthias84 commented 2 years ago

The VAR is set and available. Also if I reset the Model VAR in my current Terminal session, the same error persist. This behaviour is on my Ubuntu 21.10 Laptop and on my Linux Mint Uma Desktop as well :disappointed: Any idea for further debugging?

o-oconnell commented 2 years ago

What kind of audio format are you using? The reason for the parse error is likely that Vosk is not transcribing your audio input correctly when your audio/video is converted to a 16000 MHz, single-channel audio file. Also, what version of the JDK do you have installed? Try running java --version.

Matthias84 commented 2 years ago

My JRE is

openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

This test sample of a audiobook is

Stream 0
Codec: MPEG Audio layer 1/2 (mpga)
Kanäle: Stereo
Abtastrate: 44100 Hz
Bits pro Sample: 32
Bitrate: 192 kB/s
Matthias84 commented 2 years ago

I tried different MP3s and a different Vosk model, but the JSonSyntaxException persists :disappointed:

o-oconnell commented 2 years ago

Vosk takes as input single-channel, 16000hz wav files. It's possible that the conversion process is not working properly. You could try converting to the correct format via ffmpeg first, and then running mp4grep on them. I'd also recommend seeing if your input works using some of the examples in the vosk-api repository. Here's the command to convert to the correct wav format: ffmpeg -i [input.mp4/mp3/etc] -acodec pcm_s16le -ac 1 -ar 16000 [output.wav].

o-oconnell commented 2 years ago

@Matthias84 has this been fixed?

Matthias84 commented 2 years ago

Sorry was busy in RL, need some time for experiments though ...

o-oconnell commented 2 years ago

Should be fixed in the most recent release.