class Sounds(object): def __init__(self): print('sounds starts') # get sound clips fs = FileStorage() fs.readJson("clips.json") self.db = fs.db print('Found {} sounds clips'.format(len(self.db))) self.audio_player = AudioPlayer() self.audio_player.set_volume(15) # volume is 0-100% time.sleep(0.1) print('AudioPlayer found:', self.audio_player.audio_player) self.r2 = TTAstromech() self.r2.speak('warning') time.sleep(0.5) def sound(self, clip): """ Play an audio clip """ if clip in self.db: self.audio_player.play('clips/' + self.db[clip]) else: print('ERROR: key not found in db:', clip) def speak(self, word): """ Use ttastromech to make r2 sounds """ word = word[0:6] # limit R2 to 6 letters self.r2.speak(word)
class ROS2D2Node: def __init__(self): self.r2 = TTAstromech() rospy.init_node('ros2d2_node') self.load_presets() self.preset_sub = rospy.Subscriber('~preset', String, self.preset_callback) self.speak_sub = rospy.Subscriber('~speak', String, self.speak_callback) self.cmd_pub = rospy.Publisher('~synth_cmd', String, queue_size=5) def load_presets(self): package_path = rospkg.RosPack().get_path('ros2d2') self.presets = {} data = numpy.loadtxt(package_path + '/data/presets', dtype=object, delimiter=':') for line in data: self.presets[line[0]] = line[1] def preset_callback(self, preset_msg): if preset_msg.data not in self.presets: print preset_msg.data, 'not in presets' return cmd_msg = String(data=self.presets[preset_msg.data]) self.cmd_pub.publish(cmd_msg) def speak_callback(self, string_msg): self.r2.speak(string_msg.data)
def __init__(self): self.r2 = TTAstromech() rospy.init_node('ros2d2_node') self.load_presets() self.preset_sub = rospy.Subscriber('~preset', String, self.preset_callback) self.speak_sub = rospy.Subscriber('~speak', String, self.speak_callback) self.cmd_pub = rospy.Publisher('~synth_cmd', String, queue_size=5)
def __init__(self): super(R2D2Speech, self).__init__() self.speaker = TTAstromech() rospy.init_node("hopper_r2d2_speech_core", anonymous=True) rospy.Subscriber("hopper_play_sound", String, self.on_play_sound, queue_size=2) rospy.Subscriber("hopper/sound/play_random", String, self.on_play_sound) rospy.spin()
class R2D2Speech(object): def __init__(self): super(R2D2Speech, self).__init__() self.speaker = TTAstromech() rospy.init_node("hopper_r2d2_speech_core", anonymous=True) rospy.Subscriber("hopper_play_sound", String, self.on_play_sound, queue_size=2) rospy.Subscriber("hopper/sound/play_random", String, self.on_play_sound) rospy.spin() def on_play_sound(self, string): self.speaker.speak(string.data.lower()[:8])
def __init__(self): print('sounds starts') # get sound clips fs = FileStorage() fs.readJson("clips.json") self.db = fs.db print('Found {} sounds clips'.format(len(self.db))) self.audio_player = AudioPlayer() self.audio_player.set_volume(15) # volume is 0-100% time.sleep(0.1) print('AudioPlayer found:', self.audio_player.audio_player) self.r2 = TTAstromech() self.r2.speak('warning') time.sleep(0.5)
def __init__(self, file, folder, vol=5): print('sounds starts') # get path # self.cwd = os.getcwd() + folder # self.cwd = file + '/' + folder # get sound clips self.cwd = folder fs = FileStorage() fs.readJson(file) self.db = fs.db print('Found {} sounds clips'.format(len(self.db))) self.audio_player = AudioPlayer() # self.audio_player.set_volume(vol) # volume is 0-100% time.sleep(0.1) print('AudioPlayer found:', self.audio_player.audio_player) self.r2 = TTAstromech()
def Sound_Func(): print('sounds starts') host = ('localhost', 9000) # get sound clips fs = FileStorage() fs.readJson("clips.json") db = fs.db # pprint(self.db) # self.play(self.db['start']) print('Found {} sounds clips'.format(len(db))) # pub/sub setup sub = zmq.Sub(['sounds', 'speak'], host) audio_player = AudioPlayer() audio_player.set_volume(15) # volume is 0-100% time.sleep(0.1) print('AudioPlayer found:', audio_player.audio_player) r2 = TTAstromech() r2.speak('warning') time.sleep(0.5) print('------start--------') while True: topic, msg = sub.recv() # print('msg?') if msg: if topic == 'sounds': print('Topic, Msg:', topic, msg) # print('play sound') key = msg.dict['sound'] if key in db: audio_player.play('clips/' + db[key]) else: print('ERROR: key not found in db:', key) elif topic == 'speak': print('Topic, Msg:', topic, msg) word = msg.dict['speak'] word = word[0:6] # limit R2 to 6 letters r2.speak(word) # else: # print('nothing') time.sleep(0.5)
def __init__(self, path="/sounds"): TTAstromech.__init__(self, path)
def __init__(self, path="/sounds"): TTAstromech.__init__(self, path) print('<<< Need to install pyaudio >>>')
def handleArgs(): parser = argparse.ArgumentParser(description='Text to Astromech, creates astromech (R2-D2) sounds from text') # parser.add_argument('-v', '--version', help='print version number', version=__version__) # parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin) parser.add_argument('phrase', help='phrase to speak', type=str) # parser.add_argument('--stdin', help='allows you to pipe string into ttastromech') parser.add_argument('-s', '--size', help='how much of the input text phrase should be turned into astromech. The input phase will be trimmed to: phrase[:size]', type=int, default=10) # parser.add_argument('-p', '--path', help='path to write ar markers to, default is current directory', default='.') args = vars(parser.parse_args()) return args if __name__ == '__main__': # create an r2 r2 = TTAstromech() args = handleArgs() # print(args) # allow a sting to be pipped in: # echo "hi how are you" | astromech-speak.py # if args['stdin']: # # print(sys.stdin) # for i in sys.stdin: # r2.speak(i) # exit(0) size = args['size'] phrase = args['phrase'] phrase = phrase[:size]
#!/usr/bin/env python from ttastromech import TTAstromech import time if __name__ == '__main__': r2 = TTAstromech() try: r2.run() # make random astromech sounds time.sleep(2) except KeyboardInterrupt: print('bye ...')
class Sounds(object): def __init__(self, file, folder, vol=5): print('sounds starts') # get path # self.cwd = os.getcwd() + folder # self.cwd = file + '/' + folder # get sound clips self.cwd = folder fs = FileStorage() fs.readJson(file) self.db = fs.db print('Found {} sounds clips'.format(len(self.db))) self.audio_player = AudioPlayer() # self.audio_player.set_volume(vol) # volume is 0-100% time.sleep(0.1) print('AudioPlayer found:', self.audio_player.audio_player) self.r2 = TTAstromech() def set_volume(self, level): if 100 < level < 0: print('Error: volume must be between 0-100%') level = min(max(0, level), 100) # os.system('amixer cset numid=3 {}%'.format(level)) os.system("amixer sset 'Master' {}%".format(level)) # call(["amixer", "sset", "numid=3", str(level), "%"]) def random_char(self, length): """ Generates a random character string of the defined length """ return ''.join( random.choice(string.ascii_lowercase) for x in range(length)) def playWAV(self, clip): """ Play an audio clip """ if clip in self.db: self.audio_player.play(self.cwd + '/' + self.db[clip]) else: print('ERROR: key not found in db:', clip) def playMP3(self, clip): filename = self.cwd + '/' + self.db[clip] print("play mp3:", finelanem) # Popen('mpg321 {}'.format(filename), shell=True).wait() def speak(self, word): """ Use ttastromech to make r2 sounds """ word = word[0:6] # limit R2 to 6 letters self.r2.speak(word) def speak_random(self, length): ltrs = self.random_char(length) self.r2.speak(ltrs)
#!/usr/bin/env python from __future__ import print_function from ttastromech import TTAstromech import time def play(r2, s): print(' ') print('String:', s) r2.speak(s) time.sleep(0.5) r2 = TTAstromech() msgs = [ 'error', 'warning', 'hello', 'luke', 'stop', 'usafa', 'kevin', 'ok, this is the end now ... by!' ] print('This runs through some different strings and plays r2 sounds ... enjoy!') print(' ') print('-'*30)