Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #"Rec" folder is seperate.
- import os, sys, pygame
- from time import sleep as s
- from pygame.locals import *
- import pygame.mixer #no games here, just using pygame for audio purposes
- print "'@quit' to exit\n\n\n"
- resdir = os.getcwd()+"/Rec/"
- #letters = "abcdefghijklmnopqrstuvwxyz " #I don't feel like importing string
- allowed = [i for i in "1234567890abcdefghijklmnopqrstuvwxyz !@$&?%*()/+-=_^.#><:;"]
- soundlink = {
- "1":"1.wav",
- "2":"2.wav",
- "3":"3.wav",
- "4":"4.wav",
- "5":"5.wav",
- "6":"6.wav",
- "7":"7.wav",
- "8":"8.wav",
- "9":"9.wav",
- "0":"0.wav",
- "a":"a.wav",
- "b":"b.wav",
- "c":"c.wav",
- "d":"d.wav",
- "e":"e.wav",
- "f":"f.wav",
- "g":"g.wav",
- "h":"h.wav",
- "i":"i.wav",
- "j":"j.wav",
- "k":"k.wav",
- "l":"l.wav",
- "m":"m.wav",
- "n":"n.wav",
- "o":"o.wav",
- "p":"p.wav",
- "q":"q.wav",
- "r":"r.wav",
- "s":"s.wav",
- "t":"t.wav",
- "u":"u.wav",
- "v":"v.wav",
- "w":"w.wav",
- "x":"x.wav",
- "y":"y.wav",
- "z":"z.wav",
- " ":"space.wav",
- "!":"exclamation.wav",
- "?":"question.wav",
- "@":"at.wav",
- "$":"dollar.wav",
- "&":"and.wav",
- "%":"percent.wav",
- "*":"times.wav",
- "(":"openp.wav",
- ")":"closedp.wav",
- "/":"dividedby.wav",
- "+":"plus.wav",
- "-":"minus.wav",
- "=":"equals.wav",
- "_":"underscore.wav",
- ".":"point.wav",
- "^":"carat.wav",
- "#":"number.wav",
- ">":"greaterthan.wav",
- "<":"lessthan.wav",
- ":":"colon.wav",
- ";":"semicolon.wav"
- #no brackets :(
- #no braces :(
- #no tilde :(
- #no quote :(
- #no apostrophe :(
- #no vertical line :(
- #no backslash :(
- #no comma :(
- #no Unicode characters :(
- }
- pygame.mixer.init()
- loop = 1
- while loop == 1:
- request = raw_input("Speech > ").lower()
- if request.lower() == "@quit":
- loop = 0
- elif request.lower() == "@mmmmm": ######
- pygame.mixer.Sound(resdir+"mmm.wav").play() #
- elif request.lower() == "@augh": #
- pygame.mixer.Sound(resdir+"ow.wav").play() #####--- Because why not?
- elif request.lower() == "@slop": #
- pygame.mixer.Sound(resdir+"squish.wav").play() ######
- else:
- test = []
- for i in request:
- if i in allowed:
- test.append(str(i)) #"sanitizing" the input. allowing only the specified characters
- request = test
- #print test
- for i in test:
- audio = resdir+soundlink[i] #path to file
- length = pygame.mixer.Sound(audio).get_length() #length of sound file in seconds
- pygame.mixer.Sound(audio).play() #play the sound
- s(length/1.5) #wait the length of sound
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement