Detecting music title inside string

310 Views Asked by At

I am currently writing my own voice assistant in python using nltk for preprocessing and pytorch for processing the data. After lots of hours searching for any method, I can't find a way to extract the title of a song from other spoken text. So what I want to achieve is at example filtering "Numb" out of "Play numb by Linkin Park". Is this somehow possible with NLP or just using neural network and how?

1

There are 1 best solutions below

1
PirateNinjas On

This is potentially quite a difficult problem to solve generally. As a first pass, you could try imposing some additional assumptions:

  1. The text passed to your "song name extractor" is perfectly translated from speech
  2. The user will follow a set format for requesting the song

If you make these assumptions the problem can be solved using regex, like so:

import re

# your input text
song_request = "Play numb by Linkin Park"

# search the input text for a matching substring
song_search = re.search("(?<=Play ).*(?= by)", song_request)

# if you get a match, extract the song title
if song_search:
    song_title = song_search.group()
else:
    song_title = ""  # just in case your assumption doesn't hold