Jump to content
  • Announcement

    Welcome to the forums!

    If you are a newly-approved member, make sure you check out the New Member Checklist!

    If you are a Detachment member and can't see the member-only area, post here for access.

    -DV

Darth Nihilus voice program.


Darth Tader

Recommended Posts

Found a some sounds files, and I set mine up as follows.

Assumptions based on how I set it up this weekend:

  • Uses Raspbian OS, set up via PiBakery
  • One push button configuration, used with two different setups (one-click and in development, multi-click) on glove. I put buttons between my left-hand thumb and index finger to minimize accidental pressing.
  • GPIO Pin 23 will be used for button
  • Files are MP3 (number is only limited by memory, I had 39):
    • Format: #X.mp3
      • Files were numbered 1-39, then length added (S/M/L) then .mp3. For example: '1L.mp3' for the first file and is long. This will allow filtering 
  • MP3 files are saved in '/home/pi/nihilus'
  • Script can be saved anywhere but I had it in '/home/pi/playback.py'
  • crontab is set up as per my last post to run on reboot (every boot)

This is the code I used for a single push button; with a push triggering one of the random 39 files:

#!/usr/bin/env python
#One push button setup:

import os, glob, random, RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)

os.chdir("/home/pi/nihilus")
files = glob.glob("*.mp3")

while True:
    if (GPIO.input(23) == False):
        os.system("mpg123 -q " + random.choice(files))

    sleep(0.1)

Prototype: (not confirmed working yet): From here, I'm working on using the one button to do 3 actions: 1 press for short files, 2 presses for medium files, and 3 presses for long files. I am waiting to get my new push button before fine tuning this:

#!/usr/bin/env python
#Multi push-button setup:

import os, glob, random, time, RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)

# Read in files
os.chdir("/home/pi/nihilus")
shortfiles = glob.glob("*S.mp3")
mediumfiles = glob.glob("*M.mp3")
longfiles = glob.glob("*L.mp3")

while True:
	if GPIO.event_detected(23):
		GPIO.remove_event_detect(23)
		now = time.time()
		count = 1
		GPIO.add_event_detect(23,GPIO.RISING)
		while time.time() < now + 1: # 1 second period
			if GPIO.event_detected(23):
				count +=1
				time.sleep(.25) # debounce time
		if count == 2:
			os.system("mpg123 -q " + random.choice(shortfiles))
			GPIO.remove_event_detect(23)
			GPIO.add_event_detect(23,GPIO.FALLING)
		elif count == 3:
			os.system("mpg123 -q " + random.choice(mediumfiles))
			GPIO.remove_event_detect(23)
			GPIO.add_event_detect(23,GPIO.FALLING)
		elif count == 4:
			os.system("mpg123 -q " + random.choice(longfiles))
			GPIO.remove_event_detect(23)
			GPIO.add_event_detect(23,GPIO.FALLING)

 

Once it's confirmed working, then it's a matter of running the script at boot, which I use crontab ('crontab -e'):

@reboot /home/pi/playback.py &

 

Edited by cooldevo
updated second script to include the #!, and OS used
Link to comment
Share on other sites

Sure, I have the ZIP file in my Google Drive, at the link below. I forget where I got the original MP3 file, it was a long file with all the different KOTOR2 clips mashed into one. I split them all out into individual clips using Audacity

 

The filenames are broken down as: #[SML].mp3

  • # has no real significance, gave them one-ups as I cut them
  • [SML] only matters in the multi-button script for Short (under 4 seconds), Medium (4-7 seconds), and Long (7+ seconds) tracks; if use use the single push it plays any sound in the directory regardless of length

If the link doesn't work let me know! Sorry about the delay in getting back to you.

 

https://drive.google.com/open?id=1hj7CQmV-8xVZMJLceK2VgscHNPEcmZLW

Edited by cooldevo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...