2

I would like to take input from pySimpleGUI, feed it into a normal Python var, then feed it into a music processor as I love music.

I had already tried to use wxPython for this but was unable to even get a simple fileDialog without crashing.

    from pydub import AudioSegment
    from os import listdir
    import numpy as np
    import math
    import PySimpleGUI as sg

    class Dankify():
            song_dir = "songs"
            attenuate_db = 0
            accentuate_db = 2

            yeet = sg.Window('Dankify ALL THE THINGS!'). Layout([[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()] ]).Read()

            event, values = yeet.Read()
            yeet1 = event, values

            def bass_line_freq(track):
                    sample_track = list(track)

                    # c-value
                    est_mean = np.mean(sample_track)

                    # a-value
                    est_std = 3 * np.std(sample_track) / (math.sqrt(2))

                    bass_factor = int(round((est_std - est_mean) * 0.005))

                    return bass_factor

                    songfile = yeet1
                    for filename in listdir(songfile):
                        sample = AudioSegment.from_mp3(songfile)
                        filtered = sample.low_pass_filter(bass_line_freq(sample.get_array_of_samples()))

                        combined = (sample - attenuate_db).overlay(filtered + accentuate_db)
                        combined.export("exports/" + filename.replace(".mp3", "") + "-export.mp3", format="mp3")

However, it just does nothing, not even processing it. A reminder that I am using some open-source code and that I'm a beginner which knows nothing about how all this works and am trying to build real stuff to gain experience. Thanks!

Ismail Ahmed
  • 41
  • 2
  • 6

2 Answers2

0

I guess you are missing the "event loop".

Try something like this, hope it helps.

import sys  
if sys.version_info[0] >= 3:  
    import PySimpleGUI as sg  
else:  
    import PySimpleGUI27 as sg  

layout = [[sg.Text('Your typed chars appear here:'), sg.Text('', key='_OUTPUT_') ],  
          [sg.Input(do_not_clear=True, key='_IN_')],  
          [sg.Button('Show'), sg.Button('Exit')]]  

window = sg.Window('Window Title').Layout(layout)  

while True:                 # Event Loop  
  event, values = window.Read()  
  print(event, values)
  if event is None or event == 'Exit':  
      break  
  if event == 'Show':  
      # change the "output" element to be the value of "input" element  
      window.FindElement('_OUTPUT_').Update(values['_IN_'])

window.Close()
Alg_D
  • 2,242
  • 6
  • 31
  • 63
0

You're doing 2 Read calls.

Try changing to this:

yeet = sg.Window('Dankify ALL THE THINGS!').Layout(
    [[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()]])

event, values = yeet.Read()

Without the Read on the end of the first statement.

You are instantiating this class, right?

d = Dankify()
Mike from PSG
  • 5,312
  • 21
  • 39