element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Rocking Raspberry Pi
  • Challenges & Projects
  • Design Challenges
  • Rocking Raspberry Pi
  • More
  • Cancel
Rocking Raspberry Pi
Blog Karaoke Machine Using Raspberry Pi
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: rushikesh988
  • Date Created: 14 May 2014 11:36 PM Date Created
  • Views 762 views
  • Likes 0 likes
  • Comments 0 comments
  • wolfson
  • pi
  • karaoke
  • raspberry-pi
  • machine
  • rocking_pi
Related
Recommended

Karaoke Machine Using Raspberry Pi

rushikesh988
rushikesh988
14 May 2014

Hi all...

 

I have made the karaoke player with python pygame.



Following are the steps in it


1)I have installed wheezy Linux on Raspberry Pi, which was already in the NOOBS.


2) For working with Wolfson PI AUDIO CARD, I have used Kernel,modules and scripts given by ragnar.jensen at


Re: Re: Wolfson modified Noobs raspbian zipped img  Cannot unzip new download


after installing it you will need to execute scripts for each devices in home/pi/use_case_scripts



3)This player uses 3 types of file for one song:

                         MP3 File

                         Lyrics File

                         Timing File

 

 


image

 

 

 

5)Following is the code for my Application:

import pygame, Buttons
import subprocess
import os
from threading import Thread
from pygame.locals import *
from pygame import mixer


pygame.init()



class Play_Button:
    def __init__(self):
        self.main()


    #Create a display
    def display(self):
        self.screen = pygame.display.set_mode((600,450),0,32)
        pygame.display.set_caption("player")
        




    #Update the display and show the button
    def update_display(self,some_text):
        self.screen.fill((81,209,247))
        screen=pygame.display.set_mode((600,450),0, 24)
        img=pygame.image.load("/home/pi/Kariyoke_Machine/play music/bg-img.jpg").convert()


        create=pygame.font.SysFont("comicsansms",40)
        f=create.render(some_text,True,(0, 0, 0),(255, 255, 255))

        screen.blit(img,(0, 0))
        screen.blit(f,(200, 20))

        #Parameters:               surface,      color,       x,   y,   length, height, width,    text,      text_color
        self.Prev_Button.create_button(self.screen, (255,142,35), 100, 135, 100,    100,    0,        "Prev", (255,255,255))
        self.Play_Button.create_button(self.screen, (255,142,35), 300, 135, 100,    100,    0,        "Play/Pause", (255,255,255))
        self.Next_Button.create_button(self.screen, (255,142,35), 500, 135, 100,    100,    0,        "Next", (255,255,255))

        pygame.display.flip()
        pygame.display.update()




    #Run the loop
    def main(self):
        pygame.init()
        #os.system("arecord|aplay")
        aplay_arec=subprocess.Popen(["arecord","|","aplay"])
        i=0

        a={}

        for filename in os.listdir("/home/pi/Kariyoke_Machine/songs/"):
            a[i]=filename
            print a[i]
            i=i+1

        i=0;
        play=0
        self.Play_Button = Buttons.Button()
        self.Next_Button = Buttons.Button()
        self.Prev_Button = Buttons.Button()
        self.display()
        self.update_display("Welcome")
        while True:

                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        pygame.quit()
                    elif event.type == MOUSEBUTTONDOWN:
                        if self.Play_Button.pressed(pygame.mouse.get_pos()):

                            if play:
                                print "Stoped"
                                mixer.music.stop()
                                play=0
                            else:
                                text_to_print="Playing " + str(a[i])
                                print text_to_print
                                self.update_display(text_to_print)
                                mixer.music.stop()
                                mixer.init()
                                mixer.music.load('/home/pi/Kariyoke_Machine/songs/'+a[i])
                                  
                                lyrics_file="/home/pi/Kariyoke_Machine/lyrics_and_timings/"+str(i)+"l.txt"
                                timings_file="/home/pi/Kariyoke_Machine/lyrics_and_timings/"+str(i)+"t.txt"
                                if os.path.isfile(lyrics_file):
                                    subtitles_file = open(lyrics_file, 'r')
                                    subtitles_time = open(timings_file, 'r')
                                    loop_counter=int(subtitles_time.readline());
                                    print loop_counter
                                    subtitles_list=[]
                                    timings_list=[]
                                    for x in range(0,loop_counter):

                                        next_subtitles=subtitles_file.readline()
                                        timing=int(subtitles_time.readline())
                                        subtitles_list.append(next_subtitles)
                                        timings_list.append(timing)
                                    mixer.music.play()
                                    for x in range(0,loop_counter):
                                        ev = pygame.event.poll()
                                        if ev.type == pygame.MOUSEBUTTONDOWN:
                                            print "Breaking Loop"
                                            break;
                                        #print "I am in for Loop"
                                        #event=pygame.event.get()
                                        pygame.time.wait(timings_list[x])
                                        text_to_print=subtitles_list[x]
                                        self.update_display(text_to_print)

                                        play=1
                                        
                                        pygame.display.flip()
                                else:
                                    mixer.music.play()
                                    play=1
                                    pygame.display.flip()
                                    
                        elif self.Prev_Button.pressed(pygame.mouse.get_pos()):
                            i=i-1
                            if i<0:
                                i = len (a)
                            text_to_print="Playing " + str(a[i])
                            print text_to_print
                            self.update_display(text_to_print)
                            mixer.music.stop()
                            mixer.init()
                            mixer.music.load('/home/pi/Kariyoke_Machine/songs/'+a[i])
                             
                            lyrics_file="/home/pi/Kariyoke_Machine/lyrics_and_timings/"+str(i)+"l.txt"
                            timings_file="/home/pi/Kariyoke_Machine/lyrics_and_timings//"+str(i)+"t.txt"
                            if os.path.isfile(lyrics_file):
                                subtitles_file = open(lyrics_file, 'r')
                                subtitles_time = open(timings_file, 'r')
                                loop_counter=int(subtitles_time.readline());
                                print loop_counter
                                subtitles_list=[]
                                timings_list=[]
                                for x in range(0,loop_counter):

                                    next_subtitles=subtitles_file.readline()
                                    timing=int(subtitles_time.readline())
                                    subtitles_list.append(next_subtitles)
                                    timings_list.append(timing)
                                mixer.music.play()
                                for x in range(0,loop_counter):
                                    #print "I am in for Loop"
                                    #event=pygame.event.get()
                                    pygame.time.wait(timings_list[x])
                                    text_to_print=subtitles_list[x]
                                    self.update_display(text_to_print)
                            else:
                                 mixer.music.play()

                        elif self.Next_Button.pressed(pygame.mouse.get_pos()):
                            i=i+1;
                            if i > len(a):
                                i=0
                            text_to_print="Playing " + str(a[i])
                            print text_to_print
                            self.update_display(text_to_print)
                            mixer.music.stop()
                            mixer.init()
                           
                            mixer.music.load('/home/pi/Kariyoke_Machine/songs/'+a[i])
                            
                            lyrics_file="/home/pi/Kariyoke_Machine/lyrics_and_timings/"+str(i)+"l.txt"
                            timings_file="/home/pi/Kariyoke_Machine/lyrics_and_timings/"+str(i)+"t.txt"
                            if os.path.isfile(lyrics_file):
                                subtitles_file = open(lyrics_file, 'r')
                                subtitles_time = open(timings_file, 'r')
                                loop_counter=int(subtitles_time.readline());
                                print loop_counter
                                subtitles_list=[]
                                timings_list=[]
                                for x in range(0,loop_counter):

                                    next_subtitles=subtitles_file.readline()
                                    timing=int(subtitles_time.readline())
                                    subtitles_list.append(next_subtitles)
                                    timings_list.append(timing)
                                mixer.music.play()
                                for x in range(0,loop_counter):
                                    #print "I am in for Loop"
                                    #event=pygame.event.get()
                                    pygame.time.wait(timings_list[x])
                                    text_to_print=subtitles_list[x]
                                    self.update_display(text_to_print)

                            else:
                                mixer.music.play()
                                



if __name__ == '__main__':
    obj =Play_Button()


6) You need to execute:

         

arecord|aplay

 


in separate terminal.


7)To player just go to Kariyoke_machine Folder in Home and execute Karaoke_Player.m


8)Enjoy !!


  • Demonstration Video of the project:

     Karaoke Machine With Raspberry Pi and Wolfson PI. - YouTube


  • Following is the source code for the Project:

https://drive.google.com/file/d/0B5TjchJFpKR1M0RwUGtWQTNKa0E/edit?usp=sharing


I am trying to improve it in some aspects.Lets see what happens next .


I would like to thanks to Element14 for giving this wonderful  opportunity !



 



  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube