1

I am using Samsung Galaxy S7 and recently, I used the speech-to-text feature in the default Voice Recorder application. When I play one of the audio files that was recorded with that feature, the application is able to show the text in sync with the audio. I saw that there was the text stored in another text file together with the audio file, but it was just the raw text. I'm trying to figure out how this works.

Is this information for syncing the text and audio stored in the audio file? In this case, all the recordings are only in M4A files. Hence, I tried searching what M4A files can store, like if they can store subtitles because it would seem that it could be subtitles that enable this syncing. However, I can't seem to find any information on this. Or it could also be that the application just has this information stored in some sort of storage or cache, which would mean that if I moved the files over to my computer, there would not be any text synced with the audio.

2 Answers 2

2

I guess I have found the answer after looking within the M4A files themselves. The text and the timestamps, if I am correct, are stored in the M4A files.

I looked through the binary data of the file using a hex editor and just the normal Notepad application in Windows and I found all the text within a location and it looks like Java was used. I am guessing this is only a feature designed particularly for the Samsung Voice Recorder application.

A sample is shown here (with some parts and most of the weird characters removed):

;com.sec.android.app.voicenote.common.util.VoiceRecorderData 
mCategoryNamet Ljava/lang/String;L mEffectNameq ~  java.util.ArrayListx sizexp 2com.sec.android.app.voicenote.common.util.TextData ConfidenceScoreI dataTypeJ durationJ elapsedTimeJ   timeStamp[ mTextt [Ljava/lang/String; [Ljava.lang.String;{
t The pppppppppsq ~ 
t 
recording pppppppppsq ~ 
t to pppppppppsq ~ 
0

Here's a Python function that extracts the text of a given .m4a file path:

from codecs import decode

def extract_text_from_audio_data(audio_path):
    with open(audio_path, 'rb') as f:
        binary_data = f.read()
        utf8_data = decode(binary_data, 'utf-8', errors='ignore')
    index_start = utf8_data.index('Ljava.lang.String')
    index_end = utf8_data.index('com.android.version')
    substring = utf8_data[index_start:index_end]
    lines = substring.split('q\x00~')
    pattern_end = ' pppppp'
    pttrn_start = '\n'
    tokens = [l[:(l.index(pattern_end))] for l in lines if pattern_end in l]
    words = [t[t.index(pttrn_start)+4:] for t in tokens]
    phrase = ' '.join(words) + '.'
    return phrase

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .