def PlaySong(self, event): if self.Songs != None: Player = self.ASH_Frame.Tools.Player if Player != None: Player.Stop() Player = None SongIndex = self.SongList.GetSelections()[0] SongName = self.Songs.keys()[SongIndex] SongPath = self.Songs[SongName] ServerUrl = self.ASH_Frame.Search.LastSearchServer + "songs/" RequestUrl = ServerUrl+SongPath SongFile = open("saves/.temp.wav", "wb") import urllib Song = urllib.urlopen(ServerUrl+SongPath) SongFile.writelines(Song.read()) SongFile.close() import player player.play(self.ASH_Frame) self.ASH_Frame.Tune.TkRoot = Tkinter.Tk() tkSnack.initializeSnack(self.ASH_Frame.Tune.TkRoot) self.ASH_Frame.Tune.SnackSound.write(".tempfile.wav") self.ASH_Frame.Tune.SnackSound = tkSnack.Sound(load=".tempfile.wav")
def save(file, notes): sound = tkSnack.Sound(frequency=SAMPLE_RATE) length = len(notes) sound.length(length) for i in range(length): sound.sample(i, int(notes[i] * 30000)) sound.write(file, fileformat='WAV')
def playNote(freq, duration): """play a note of freq (hertz) for duration (seconds)""" snd = tkSnack.Sound() filt = tkSnack.Filter('generator', freq, 30000, 0.0, 'sine', int(11500 * duration)) snd.stop() snd.play(filter=filt, blocking=1)
def show_element(self, frame, key=None, **opts): if key != None and key != "<space>": return #element, self.desired_answer = [s.strip() for s in reading_items.next().split('\t')] #self.times.append(time.time()) frame.set_text(self.text, new_fontsize=fontsize_test) print "reading:\n" print self.text if self.save_audio: self.audiofile = data_path + "/s_%s_type_%s_n_%d.wav" % ( subject_id, self.type_item, self.number) self.recorder = tkSnack.Sound( file=self.audiofile, channels=use_channels, frequency=use_frequency, encoding="Lin16") #,,encoding=use_encoding #fileformat=use_fileformat, #) self.recorder.record() print "Recording... " + self.audiofile + "\n" self.time = time.time() #initial time self.number += 1 self.next = self.store_results
def read(file): sound = tkSnack.Sound() sound.read(file, fileformat='WAV') sound.convert(frequency=SAMPLE_RATE) notes = [] for i in range(sound.length()): notes.append(sound.sample(i) / 30000.0) return notes
def playsound(self): """ Play the Magic Word sound, if tkSnack is installed """ try: tkSnack.initializeSnack(self.consoleText) mysound = tkSnack.Sound() mysound.read('magicword.wav') mysound.play() except: print "[-] Cannot play sound"
def play (Frame): ASH_Frame = Frame ASH_Sound = tkSnack.Sound(load="saves/.temp.wav") ASH_Frame.Tune.TkRoot.geometry("+200+200") Wave = tkSnack.SnackCanvas(height=200, width=400) Wave.pack() Wave.create_waveform(0, 0, sound=ASH_Sound, height=200, width=400) ASH_Sound.play() ASH_Frame.Tune.TkRoot.mainloop()
def playnote(freq, duration): # Initialize sound interface snd = tkSnack.Sound() # Generate a sound of given frequency for given duration # Sound is produced using a sine wave filt = tkSnack.Filter('generator', freq, 30000, 0.0, 'sine', int(10000 * duration)) # Stop all sound definitions snd.stop() # Play sound, block all other sounds except this snd.play(filter=filt, blocking=1)
def __init__ (self,Frame,Panel): self.ASH_Frame = Frame wx.StaticBoxSizer.__init__(self,wx.StaticBox(Panel, -1, label='Tune'), wx.VERTICAL) self.Time = wx.StaticText(Panel, label="Time : 0 Sec") self.Title = wx.StaticText(Panel, size=(250,20), label="untitled.wav", style=wx.ALIGN_CENTER) Img = wx.Image('icons/wave.jpg', wx.BITMAP_TYPE_ANY) self.Waveform = wx.StaticBitmap(Panel, -1, Img.ConvertToBitmap(), size=(270,200)) self.Add(self.Time, 0, wx.ALL, border=5) self.Add(self.Waveform, 0, wx.ALL, border=1) self.Add(self.Title, 0, wx.BOTTOM, border=5) self.TuneName = None self.TkRoot = Tkinter.Tk() tkSnack.initializeSnack(self.TkRoot) self.SnackSound = tkSnack.Sound()
def playNote(freq, duration, base): """play a note of freq (hertz) for duration (seconds)""" snd = tkSnack.Sound() if bsound ==1: filt = tkSnack.Filter('generator', freq, 44100, 0.0, 'sine', int(11500*duration)) elif bsound==2: filt = tkSnack.Filter('generator', freq, 44100, 0.5, 'rectangle', int(11500*duration)) elif bsound==3: filt = tkSnack.Filter('generator', freq, 44100, 0.0, 'triangle', int(11500*duration)) snd.stop() for i in range(delay) : snd.play(filter=filt, blocking=1) sleep(delay2)
def recorder(Frame): global ASH_Frame, ASH_Sound ASH_Frame = Frame ASH_Sound = tkSnack.Sound() ASH_Frame.Tune.TkRoot.geometry("+100+100") Wave = tkSnack.SnackCanvas(height=200, width=400) Wave.pack() Wave.create_waveform(0, 0, sound=ASH_Sound, height=200, width=400) Tkinter.Button(Frame.Tune.TkRoot, bitmap='snackStop', command=stop).pack(side='left') Tkinter.Button(Frame.Tune.TkRoot, bitmap='snackRecord', fg='red', command=record).pack(side='right') ASH_Frame.Tune.TkRoot.mainloop()
def __init__(self, items_to_display, type_item, practice=False): self.type_item = type_item self.reading_items = self.items_obj(items_to_display[self.type_item]) self.reading_items_len = len(items_to_display[self.type_item]) self.text = "" # data strctures for collecting the results: self.practice = practice self.audiofile = "none" self.save_audio = save_audio and not (practice) self.number = 0 self.times = [] self.time = 0 self.acumulated_time = 0 self.recorder = tkSnack.Sound() self.next = self.before_show_element
def OnRecord(self, event): import tune, Tkinter, tkSnack tune.recorder(self.ASH_Frame) self.ASH_Frame.Tune.TkRoot = Tkinter.Tk() tkSnack.initializeSnack(self.ASH_Frame.Tune.TkRoot) self.ASH_Frame.Tune.SnackSound.write(".tempfile.wav") self.ASH_Frame.Tune.SnackSound = tkSnack.Sound(load=".tempfile.wav") if tune.IS_RECORDED: self.ASH_Frame.Tune.TuneName = "saves/.temp.wav" self.ASH_Frame.Tune.SnackSound.read("saves/.temp.wav") T = self.ASH_Frame.Tune.SnackSound.length(unit="SECONDS") if T < 10: Time = "Tune too short!" elif T > 20: Time = "Tune too long!" else: Time = "Time : " + str() + "Sec" self.ASH_Frame.Tune.Time.SetLabel(Time) self.ASH_Frame.Tune.DrawGraph()
def extractPitch(fnFullPath, minPitch, maxPitch): ''' Former default pitch values: male (50, 350); female (75, 450) ''' soundObj = tkSnack.Sound(load=fnFullPath) output = soundObj.pitch(method="ESPS", minpitch=minPitch, maxpitch=maxPitch) pitchList = [] for value in output: value = value[0] if value == 0: value = int(value) pitchList.append(value) return pitchList, SAMPLE_FREQ
#stdio.writeln('Playing') playNotes(notes) def playTune2(): notes = [] #while not stdio.isEmpty(): pitch = stdio.readInt() duration = stdio.readFloat() hz = 440 * math.pow(2, pitch / 12.0) playNote(hz, 1) root = Tkinter.Tk() tkSnack.initializeSnack(root) mySound = tkSnack.Sound(frequency=SAMPLE_RATE) #pressed = False def keyPressFunc(event): print 'in keyPressFunc' #mySound.stop() #time.sleep(1) #global pressed #if pressed: # return #pressed = True if event.keysym == 'a': playNote(440.0, .25) if event.keysym == 'c':
def reset(self): """Reset the audio stream.""" self._snack = tkSnack.Sound(load=self._filename)
from playsound import playsound #playsound('alarm_sound.mp3') from pydub import AudioSegment from pydub.playback import play #song = AudioSegment.from_wav("grandfather.wav") #play(song) from Tkinter import * import tkSnack root = Tk() tkSnack.initializeSnack(root) snd = tkSnack.Sound() snd.read('grandfather.wav') snd.play(blocking=1) import os file = "alarm_sound.mp3" #os.system("mpg123 " + file)
#! /usr/bin/env python # -*- coding: iso-8859-1 -*- import Tkinter import tkSnack root = Tkinter.Tk() tkSnack.initializeSnack(root) s = tkSnack.Sound() data = open('ex1.wav', 'rb').read() s.data(data) s.write('copy.wav')
def play_tkSnack(self, mediaFile): ''' Use tkSnack backend to play the .wav.''' stream = tkSnack.Sound() stream.read(mediaFile) stream.play()
def __init__(self, parent): # Instance Attributes self.targetImage = None self.samples = None self.snd = snack.Sound() self.maxWidth = 1000 self.maxHeight = 600 self.rate = 16000 self.time = 4 self.myParent = parent self.introText = """ Hello, and welcome to Sonify. To begin, load an image from your computer. Similar colors will be grouped into notes from the C Major scale. The more color a note has, the stronger the note is played. After you sonify, you can play it back or write it to a file. <Currently only supports RGB .jpg.> """ # Four main frames within the parent self.welcomeFrame = Frame( parent) # Size is overwritten by its contents. self.welcomeFrame.grid(column=0, row=0) self.dataFrame = Frame(parent) # Size is overwritten by its contents. self.dataFrame.grid(column=0, row=1) self.imageFrame = Frame(parent) self.imageFrame.grid(column=1, row=0) self.powerFrame = Frame(parent) self.powerFrame.grid(column=1, row=1) # Welcome frame self.dummyFrame1 = Frame(self.welcomeFrame, width=self.maxWidth / 2, height=self.maxHeight / 2, relief='sunken', borderwidth=2) self.dummyFrame1.grid(column=0, row=0) self.greetingLabel = Label(self.welcomeFrame, text=self.introText, justify="left") self.greetingLabel.grid(column=0, row=0, rowspan=5, columnspan=5) # Data frame self.dummyFrame2 = Frame(self.dataFrame, width=self.maxWidth / 2, height=self.maxHeight / 2, relief='sunken', borderwidth=2) self.dummyFrame2.grid(column=0, row=0, columnspan=2, rowspan=5) # Load entry and button self.loadImageFrame = Frame(self.dataFrame) self.loadImageFrame.grid(column=0, row=0) self.loadImageEntry = Entry(self.loadImageFrame, width=45) self.loadImageEntry.insert(0, "./images/forest.jpg") self.loadImageEntry.grid(column=0, row=0) self.loadImageButton = Button(self.loadImageFrame, text='Load', command=self.load_image) self.loadImageButton.grid(column=1, row=0) # Sonify button #self.sonifyButton = Button(self.dataFrame, text='Sonify', width=50, command=self.sonify_image) #self.sonifyButton.grid(column=0, row=1) # Play button self.playButton = Button(self.dataFrame, text='Play', width=50, command=self.play_wave) self.playButton.grid(column=0, row=1) # Write field and button self.writeFrame = Frame(self.dataFrame) self.writeFrame.grid(column=0, row=2) self.writeEntry = Entry(self.writeFrame, width=45) self.writeEntry.insert(0, "./sounds/temp.wav") self.writeEntry.grid(column=0, row=0) self.writeButton = Button(self.writeFrame, text='Write', command=self.write_wave) self.writeButton.grid(column=1, row=0) # Quit button self.quitButton = Button(self.dataFrame, text='Quit', width=50, command=parent.destroy) self.quitButton.grid(column=0, row=3) # Message Label self.messageLabel = Label(self.dataFrame, justify="left") self.messageLabel.grid(column=0, row=4) # Image frame self.dummyFrame3 = Frame(self.imageFrame, width=self.maxWidth / 2, height=self.maxHeight / 2, relief='sunken', borderwidth=2) self.dummyFrame3.grid(column=0, row=0) self.displayIm = Label(self.imageFrame, image=None) self.displayIm.grid(column=0, row=0) # Power frame self.dummyFrame4 = Frame(self.powerFrame, width=self.maxWidth / 2, height=self.maxHeight / 2, relief='sunken', borderwidth=2) self.dummyFrame4.grid(column=0, row=1) self.powerFigure = Figure(figsize=(self.maxWidth / 200., self.maxHeight / 200.), dpi=97) self.powerFigureCanvas = FigureCanvasTkAgg(self.powerFigure, master=self.powerFrame) self.powerFigureCanvas.show() self.powerWidget = self.powerFigureCanvas.get_tk_widget() self.powerWidget.grid(column=0, row=1)
def __init__(self, master): """ Run a set of timers concurrently - clear_mind (default 5 minutes) - study (default 30 minutes) - review (default 5 minutes) - break (15 minutes) """ super().__init__(master) self.master = master # tkSnack used to play sound tkSnack.initializeSnack(self.master) self.snd = tkSnack.Sound() self.snd.read("media/gong.wav") self.minutes = self.seconds = 0 self.minute_vals = [5, 30, 5, 15] self.stop_timer = False self.clear_mind_label_text = tk.StringVar() self.study_label_text = tk.StringVar() self.review_label_text = tk.StringVar() self.relax_label_text = tk.StringVar() self.clear_mind_input_value = tk.StringVar() self.study_input_value = tk.StringVar() self.review_input_value = tk.StringVar() self.relax_input_value = tk.StringVar() self.error_message = tk.StringVar() self.clocks = ( self.clear_mind_label_text, self.study_label_text, self.review_label_text, self.relax_label_text, ) self.current_row = 0 self.line_label = 0 self.entry_colomn = 1 self.set_entry_column = 2 self.time_column = 3 # ------ styles ----------- self.error_style = ttk.Style() self.error_style.configure('Error.TLabel', foreground='red', background="#5cdb95", font=('Sans', '10', 'bold')) self.title_label_style = ttk.Style() self.title_label_style.configure('Title.TLabel', font=('Sans', '12', 'bold'), background="#5cdb95") self.button_style = ttk.Style() self.button_style.configure('Nice.TButton', foreground='#05386b', background='#5cdb95') self.entry_style = ttk.Style() self.entry_style.configure('Nice.TEntry', fieldbackground='#8ee4af') self.label_style = ttk.Style() self.label_style.configure('Nice.TLabel', background="#5cdb95") self.line_style = ttk.Style() self.line_style.configure('Line.TSeparator', background="#05386b") self.frame_style = ttk.Style() self.frame_style.configure('Nice.TFrame', background="#5cdb95") self.initUI() self.set_vals()
def playNotes(notes): print 'In playNotes' global root global blocked #global oldLength #global globalSound #global blocked #while blocked: # print 'blocked' #blocked = True sound = tkSnack.Sound(frequency=SAMPLE_RATE, buffersize=0) length = len(notes) sound.length(length) for i in range(length): sound.sample(i, int(notes[i] * 30000)) #oldLength = globalSound.length() #globalSound.concatenate(sound) #newLength = globalSound.length() #if newLength - oldLength > 1000: #globalSound.play(blocking=0, start=oldLength, end=-1, # command=unblock()) #root.update() #time.sleep(.1) #if globalSound.length() >= 4096: # globalSound.play(blocking=0, start=) # root.update() #globalSound.flush() #while block: # print 'blocked' #block = True #sound.play(blocking=0, command=unblock()) #newDelay = sound.length(unit='SECONDS') #print 'Delay:', newDelay #length = sound.length(unit='SAMPLES') #print 'Length:', length #print int(2000.0*oldLength/SAMPLE_RATE) #sound.play(blocking=1, starttime=0) #sound.play(blocking=0) #root.update() #wait() #blocked = True #sound.play(blocking=0, command=unblock()) global _startTime global _length global _firstTime #print 'Starttime:', _startTime #print 'Currenttime:', time.time() #print 'Length:', _length #print 'firsttime:', _firstTime if _firstTime: _firstTime = False else: #print 'here' while (time.time() - _startTime) < _length: #print 'sleeping' pass #time.sleep(1) sound.play(blocking=0) _startTime = time.time() #_length = sound.length(unit='SAMPLES') #print 'initiallength:', _length _length = float(length) / 44100.0 root.update()
self.label['fg'] = '#198931' new_str = '%02d:%02d' % ((self.seconds / 60), (self.seconds % 60)) self.labelstr.set(new_str) def set_time(self): """ Gets user input from a dialog and updates self.default_time according to it """ som.stop() try: self.default_time = tkSimpleDialog.askfloat( 'Set time', 'Specify the time (in minutes)', parent=self.top) self.reset() except TypeError: pass if __name__ == '__main__': root = Tk() rootSnack = Tk() tkSnack.initializeSnack(rootSnack) rootSnack.withdraw() som = tkSnack.Sound() som.read('despertador.mp3') clock = Clock(root, 1) root.mainloop()
def playNote(freq, duration): snd = tkSnack.Sound() filt = tkSnack.Filter('generator', freq, 30000, 0.0, 'sine', int(11500*duration)) snd.stop() snd.play(filter=filt, blocking=1)
def __init__(self, master): self.master = master self.master.title('Schedule') # initialize widgets self.time_table = TimeTable(self.master) self.time_table.grid(row=0, column=0) self.panel = tk.Frame(self.master, height=50, width=200) self.panel.grid(row=1, column=0) # bottom panel self.refresh_button = tk.Button(self.panel, text='Refresh', command=self.refresh) self.refresh_button.grid(row=0, column=0) self.auto_refresh = tk.IntVar() self.auto_refresh_button = tk.Checkbutton(self.panel, text = 'Auto Refresh', \ variable = self.auto_refresh, command = self.set_auto_refresh) self.auto_refresh_button.grid(row=0, column=1) self.option_button = tk.Button(self.panel, text='Options', command=self.pop_option_panel) self.option_button.grid(row=0, column=2) self.reinitialize_button = tk.Button(self.panel, text = 'Reinitialize', \ command = self.initialize) self.reinitialize_button.grid(row=0, column=3) # LED path led_on = tk.PhotoImage(file=os.path.join(ABSOLUTE_PATH, 'led_on.png')) led_off = tk.PhotoImage( file=os.path.join(ABSOLUTE_PATH, 'led_off.png')) fake_led = LED(None) # set the image path in the LED class fake_led.set_image(led_on, led_off) fake_led.destroy() # pop-up windows self.wake_up_window = None self.option_panel = None self.option_panel_open = False # initialize schedule self.schedule_path = self._get_schedule_path() self.sc = DisplayableSchedule(self.master) self.initialize() # initialize alarm self.music_path = os.path.join(ABSOLUTE_PATH, MUSIC_PATH) tkSnack.initializeSnack(self.master) tkSnack.audio.inputDevices() self.music = tkSnack.Sound() self.music.read(self.music_path) # intialize time data self.last_refresh = 0 self.update_sync = True # avoids starting the alarm while the schedule is refreshed self.update_period = UPDATE_PERIOD self.refresh_period = REFRESH_PERIOD self.time_before_start = TIME_BEFORE_START self.update()
def init_tk(): root = Tkinter.Tk() tkSnack.initializeSnack(root) tkSnack.audio.play_gain(100) global snd snd = tkSnack.Sound()
def initialize_player(self): tkSnack.initializeSnack(root) #standard init process tkSnack self.soundObject = tkSnack.Sound( ) #create a SoundObject (required by tkSnack)