Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to synchronize mp3 audio with text?

Tags:

java

android

mp3

Read all the previous answers and had no luck. Working on an android app in which I need to synchronize mp3 audio with text. As the mp3 played it keeps on changing the text. Just like the lyrics highlights on YouTube etc.

like image 979
Husnain Avatar asked Oct 06 '17 04:10

Husnain


2 Answers

first you need to create subtitle file of the audio that you want to play and then add that subtitle file in your media player as

String mimeType = getMimeType("file://mnt/sdcard/BarbieGirl.srt");
        //  mp.selectTrack(index);  
        try {
            mp.addTimedTextSource(path, mimeType);
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

for creating subtitle file you can use check this url Create Subtitle .

like image 125
Ashish Avatar answered Nov 06 '22 03:11

Ashish


They use LRC files to generate the lyrics under the mp3

https://en.wikipedia.org/wiki/LRC_(file_format)

Essentially, the lyrics (or whatever) are tagged with times for which they should appear, if the android player you're using is LRC aware, it should automatically overlay the lyrics at the right time intervals, you can even make the lines appear a few words at a time with the extended tagging.

like image 1
user1442498 Avatar answered Nov 06 '22 04:11

user1442498