How to sync mp3 audio with text?

Read all the previous answers and no luck. Working with an Android application in which I need to synchronize mp3 audio with text. When playing mp3 it continues to change the text. Just like lyrics on YouTube, etc.

+5
source share
3 answers

first you need to create the audio subtitle file that you want to play, and then add this subtitle file to the 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(); } 

to create a subtitle file that you can use, check this Create subtitle URL.

+2
source

They use LRC files to create lyrics for mp3

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

In fact, the lyrics (or something else) are marked by the time for which they should appear, if the android player you are using is LRC, it should automatically overlap the lyrics at the right intervals, you can even make the lines appear a few words at a time with extended tags.

+1
source

I don't have code for android, but I did something like this using Javascript, so I'm going to point you to some steps. Take a look at this LRC Maker and Generator , it contains a sample of “My Heart Will Go On” with text synchronization. If this is what you want to achieve, then good.

1- Think LRC, which is a text format for processing synchronization for an audio file. Each line contains information about sound or time in brackets, for example:

 [ar:Chubby Checker oppure Beatles, The] [al:Hits Of The 60 - Vol. 2 – Oldies] [ti:Let Twist Again] [au:Written by Kal Mann / Dave Appell, 1961] [length: 2:23] [00:12.00]Naku Penda Piya-Naku Taka Piya-Mpenziwe [00:15.30]Some more lyrics ... 

Note LRC Wikipedia Format , there is a simple format (in turn) and an advanced format (Word-by-Word). I suggest starting with Simple Format.

2- Create a Java class (Activity or your own library) to process information and objects for reading, displaying and writing Simple Format. Your class must have attributes:

  • ArrayList of Raw text lines ([00: 12.00] Naku Penda Piya-Naku Taka Piya-Mpenziwe, ...)
  • ArrayList of parsed tags ([00.12.00], [00.18.50], ...)
  • ArrayList of parsed text strings (Naku Penda Piya-Naku Taka Piya-Mpenzive, ...)
  • ListView to display the time format on the left and text text on the right.
  • The number of rows to display in your ListView
  • A list item that contains views such as (TextView time format, Line TexView lyrics or EditText if you allow the user to add or edit each line of text in the application)

3- Enter the engine code. You will need to use a regular expression to extract formatted strings ([00: 12.00] Naku Penda Piya-Naku Taka Piya-Mpenziwe) and timestamps on each line ([00.12.00]). You can use them from javascript code example:

 var tagRegex = /\[([az]+):(.*)\].*/; var lrcAllRegex = /(\[[0-9.:\[\]]*\])+(.*)/; var timeRegex = /\[([0-9]+):([0-9.]+)\]/; var rawLrcArray = rawLrc.split(/[\r\n]/); 

tagRegex is designed to select information about the music (title, artist, genre, etc.)

lrcAllRegex is for selecting a string that has the LRC format.

timeRegex is designed to select the time format in a full line with the LRC format

rwaLrcArray if to split the whole text into an array of strings. This should not be difficult in Java.

3a So, using the basic process to add multiple items to a ListView via an ArrayAdapter on Android, read the text, split it into an array of several lines, parse the time tags, parse the lines and put them in the attribute tag and line in the “LRC item”, which you will use to populate the information in the ListView.

The LRC item class must have attributes:

  • Start time tag
  • End time tag
  • Line

For each line, the end tag will be the same as the start tag of the next line. Add an event listener to your music player. Play the current time. Each time you get the current time, repeat all the LRC elements, check the current id time between the start time of the LRC and the end time, and then change the color of the Line EditText to highlight this line.

3b- Next The part you want most for synchronization, add an event listener to both the “Time Tag” TextView and the “Line” EditText in the LRC layout. Each time the User clicks on the TextView Time Tag, updates the value of the LRC time tag and writes this new time in the format [XX: YY.ZZ] in the Text Time Tag.

When the user clicks on an EditText or TextView line, change the Music Player to this current time, this will allow the user to return to any line to correct the Time label of the next line.

4- Finally, when this is done, repeat and take new information for each LRC item class and connect each timestamp ([00: 12.00]) next to each line (Naku Penda Piya-Naku Taka Piya-Mpenziwe) and add a New Line "\ n" after each line. It is up to you to decide whether you want to record it to music-file.lrc or just save it to the database.

You can learn more about JS File . Sign up for the Lusaisai Lyricer Package Live Demo that inspired me.

0
source

Source: https://habr.com/ru/post/1272382/


All Articles