Matching audio files with text using java - java

I have a collection of audio files. Now, I have a piece of text (say a lyric) that i want to match with the audio files? In other words, which audio file contains this lyric. I am curious how we can do this in Java. I would prefer a solution that uses preprocessing of the audio files so that the search is fast. Is there any API that can help?

Recognizing words is hard. Recognizing words in songs is even harder.
It sounds like you are not interested in how to do that, but more to locate things in your song database. If so, the simplest way to do so, may be to locate lyrics for each song based on its title and other meta data, and then just search in that text.

For that you'd need speech recognition. The JSAPI might be a way to go, but last time I checked, only text-to-speech parts (they are plug-ins provided by 3rd parties) were available, not the other way around.

Related

Are there an examples of how to use the java api io.humble to encode audio?

I was able to follow the examples of how to encode video with io.humble easily enough. But, the only example of including audio that I can find simply encodes audio at the beginning of the video. I can't figure out how to encode samples at arbitrary locations. Using setTimestamp doesn't do anything.
Here is the example I found:
https://www.javatips.net/api/myLib-master/myLib.AGPLv3/myLib.humble.test/src/test/java/com/ttProject/humble/test/BeepSoundTest.java
If I modify the beepSamples() method to increase the "sampleNum" value, I can create a longer tone. But calling the method multiple times or setting samples.setTimestamp() to other values or calling setTimestamp() on the packets, all do nothing.
No matter what I do, the audio always shows up at the beginning of the video.
Ultimately, I want to be able to load arbitrary mp3 files of various audioclips and then merge them into the audio stream of the video at specific timestamps. But I can't even get this example to encode at different points in the video stream.
The author of this tool unfortunately is not interested in maintaining it or providing examples. Luckily, I found JavaCV which is an alternative that turned out to be really easy to use.
So to anyone else having this problem, I recommend switching to JavaCV. Other options are also JCodec and Xuggler, but Xuggler is deprecated (same author as io.humble) and JCodec apparently is slow and produces much larger files.
If you need support with these kind of projects. I maintain a fork of Xuggler (https://github.com/olivierayache/xuggle-xuggler)..I can provide help on these topics.

I need to play a sound for a text based game in the cmd

I need a function that I can call, that plays a sound. It needs to have a parameter where I can give it the name of the file I'm trying to play. I've tried searching on the internet, but it's all mostly based around the sun library. And that gives me a warning. Thanks in advance.
You can use Java media framework to play media. As for the method :)
that you have to customize as per your need.
Or if you just want beep sounds, you can use bell character or create beep using awt toolkit
//Bell character
System.out.println("\007");
//Toolkit
java.awt.Toolkit.getDefaultToolkit().beep();
The Java Tutorials, for some reason, doesn't have a simple example of playing a sound in the fire-and-forget manner that you are asking about. But there are other tutorials online that do so.
The search term that will be of most help is "Clip" from the library javax.sound.sampled. This is a core library, so there is no need to import anything. The Clip class loads audio files in RAM, and allows you to play them back from RAM on demand. It is mostly used for short sounds. You should be able to find some code examples if you include "java clip" in a search.
Also in that library is SourceDataLine. This is often used for sounds that are too large to hold in memory. The class plays back data that you provide to its write() method. Thus it is common to pair the class with an AudioInputStream that was set up to read data from a file location. Again, there should be code examples if you search on the class name.
I made use of SourceDataLine to write a small audio library which can be found on GitHub, called AudioCue. The syntax is simpler than with Clip, assuming your source file is a wav file with 16-bit encoding, 44100 fps, stereo, low-endian (also known as "CD Quality"). To make use of it, there are six classes to load. You can just cut and paste. It is kind of a "super Clip" in that it allows extra capabilities like real time volume, panning and variable speed playback, as well as concurrent playback. There is a simple "fire-and-forget" example posted in the README.MD
The library is free to use. (BSD-type license.)

Reading lyrics information from a .kar file in java

I want to develop a karaoke player in Java that works with kar files. I got it to play the song, but I coundn't make it read the lyric information from the file. I've searched a lot, but I coundn't find any clue about how kar files work.
How can I do it? I appreciate some example.
Thanks.
I don't think there is a Java library for that so you'll have to write it on your own code.
First, you need to know the inner structure of a .kar file. Since these files are so small, they're probably some kind of text files. Try opening one of them with your text editor and see what it looks like. Then you'll know how to process it.
Apologies as I don't have a definitive answer for you. I have seen several discussions about this but no real solid solutions. Here are a couple links to others' discussions on the topic. It seems to be a much more complicated task than one might imagine, as it is an uncommonly used file type. From what I know, it consists of MIDI data, albeit with slightly different meta data.
Reading lyrics information from a .kar file
How to read MIDI file in C#?
Can you open the .kar file in a text editor? What does it give you?
The best I could find is this:
"KAR"
Origin: The Company Tune 1000 A file kar (kar) is in fact, a midi
file, but whose words are standardized in events meta of the type
TEXT. The texts starting with # are additional indications compared to
the words. Example:
#L specifies the language of the words
#I any additional information
#T information of title
#KMIDI KARAOKE SPINS information of copyright
and type of file
Several lines of titles and information can be present. KaraWin
extracts information from titles to post them. The text even has a
very simple format to him: \ indicates a page break, /a return
indicates has the line
Source.
Besides that, according to Wikipedia, XBMC is an open source program that supports kar files. Since it's an open source project, you can download its code. If you are really interested, you can try searching among its 10k+ files (in C, not Java), how they do it. Maybe you can ask them or in their forum for a little bit of guidance.
You can also try in this yahoo group about karaoke software.

Is there any way I can rate songs in iTunes using java?

I have a list of songs rated by folder they are in (e.g. 1 star songs in a folder, 2 star songs in another folder and so on). I want to rate songs in iTunes depending on which folder they are in, fast and automatically using codes from java.
I found a perl script that does similar thing: http://www.hydrogenaudio.org/forums/index.php?showtopic=38083
It would make it event simpler to use folder name instead of tags to set rating.
If you want to do similar thing in java, you'd have to use Jacob (example here) or BridJ to do access iTunes database via COM. It's painful, platform-dependant and I wouldn't recommend doing it unless you really need it.
iTunes stores its library as an XML file so I suppose you could manipulate that directly from within Java. Of course you'd have to be careful with this approach as different versions of iTunes have different XML formats, and if you invalidate the library than all the metadata iTunes is holding about the tracks in its library will be lost.

Convert Text to audio file like .wav or .au in java

i want to create audio file using text. in this case i tried AudioOutputStream and AudioSystem.write() methods this way audio file created but problem in running. so if any idea that helps for converting text to audio file please write below.
thank you.
Piyush
If you want to make some kind of "text to speech" you'll need a library, which will handle this. Otherwise you will have a lot of work. Try this project:
http://freetts.sourceforge.net/docs/index.php
You think creating audio from text is as simple as writing text data to an audio stream ? ...
LOL
To convert text to audio, you have to rely upon rather complicated tools, like text-to-speech engines.
Hopefully, java is known for the forrest of many trees. Concerning text-to-speech, you can rely upon this excellent question and its anwsers.

Categories