e@0: #!/usr/bin/env python3 e@0: # -*- coding: utf-8 -*- e@0: """ e@0: Created on Wed Apr 18 19:31:02 2018 e@0: e@0: @author: mmxgn e@0: """ e@0: e@0: from selenium import webdriver e@0: import librosa e@0: import librosa.display e@0: import glob e@0: import time e@0: import os e@0: import matplotlib.pyplot as plt e@0: import pandas as pd e@0: e@0: fxive_dict = { e@0: 'stream' : ('http://localhost:8000/update/app/main-panel/stream.html?preset=Stream', '3'), e@0: 'sonar' : ('http://localhost:8000/update/app/main-panel/beep.html?preset=Sonar', '10'), e@0: 'motor' : ('http://localhost:8000/update/app/main-panel/dc-motor.html?preset=Small%20Boat', '15'), e@0: 'stormy' : ('http://localhost:8000/update/app/main-panel/stormy-day.html?state=%7B%22RTSFXrain%22%3A%7B%220%22%3A%7B%22dropletGain%22%3A0.3%2C%22rumbleGain%22%3A0.3%2C%22ambienceGain%22%3A0.3%7D%7D%2C%22RTSFXmaster%22%3A%7B%221%22%3A%7B%22gain%22%3A1%2C%22panning%22%3A0.33000000000000007%7D%2C%223%22%3A%7B%22gain%22%3A1%2C%22panning%22%3A0.8900000000000001%7D%2C%225%22%3A%7B%22gain%22%3A1%2C%22panning%22%3A0%7D%2C%227%22%3A%7B%22gain%22%3A1%2C%22panning%22%3A0%7D%2C%2213%22%3A%7B%22gain%22%3A1%2C%22panning%22%3A0%7D%7D%2C%22RTSFXwind%22%3A%7B%222%22%3A%7B%22windSpeed%22%3A1%2C%22gustiness%22%3A0.8%2C%22squall%22%3A0.9%2C%22buildings%22%3A0.8%2C%22doorways%22%3A0.8%2C%22branches%22%3A0.8%2C%22leaves%22%3A0.8%2C%22pan%22%3A0%2C%22directionality%22%3A1%2C%22gain%22%3A1%7D%7D%2C%22RTSFXstream%22%3A%7B%224%22%3A%7B%22bubbles%22%3A350%2C%22frequency%22%3A1%2C%22qAmount%22%3A2%2C%22sink%22%3A0%7D%7D%2C%22RTSFXthunder%22%3A%7B%226%22%3A%7B%22pitch%22%3A25%2C%22duration%22%3A3000%2C%22distance%22%3A0%2C%22outGain%22%3A1%7D%7D%2C%22RTSFXoverdrive%22%3A%7B%228%22%3A%7B%22knee%22%3A0%2C%22bias%22%3A0%2C%22tone%22%3A1%2C%22drive%22%3A0%2C%22level%22%3A0%2C%22bypass%22%3A0%7D%7D%2C%22RTSFXdelay%22%3A%7B%229%22%3A%7B%22delay%22%3A0%2C%22dry%22%3A1%2C%22wet%22%3A1%2C%22level%22%3A1%2C%22feedback%22%3A-12.000000253286988%2C%22cutOff%22%3A350%2C%22bypass%22%3A0%7D%7D%2C%22RTSFXconvReverb%22%3A%7B%2210%22%3A%7B%22dry%22%3A1%2C%22wet%22%3A1%2C%22level%22%3A1%2C%22lowCut%22%3A20%2C%22highCut%22%3A20000%2C%22type%22%3A0%2C%22bypass%22%3A0%7D%7D%2C%22RTSFXeq%22%3A%7B%2211%22%3A%7B%22Band1Gain%22%3A0%2C%22Band1Frequency%22%3A150%2C%22Band1QFactor%22%3A1%2C%22Band2Gain%22%3A0%2C%22Band2Frequency%22%3A560%2C%22Band2QFactor%22%3A1%2C%22Band3Gain%22%3A0%2C%22Band3Frequency%22%3A1000%2C%22Band3QFactor%22%3A1%2C%22Band4Gain%22%3A0%2C%22Band4Frequency%22%3A3300%2C%22Band4QFactor%22%3A1%2C%22Band5Gain%22%3A0%2C%22Band5Frequency%22%3A8200%2C%22Band5QFactor%22%3A1%2C%22Band1FilterType%22%3A0%2C%22Band5FilterType%22%3A0%7D%7D%2C%22RTSFXspatialisation%22%3A%7B%2212%22%3A%7B%22positionX%22%3A0.5%2C%22positionY%22%3A0.5%2C%22positionZ%22%3A0%2C%22distanceX%22%3A100%2C%22distanceY%22%3A100%7D%7D%7D', '10'), e@0: 'meadow': ('http://localhost:8000/update/app/main-panel/stream.html?preset=Stream', '3'), e@0: e@0: } e@0: e@0: class FXive: e@0: def __init__(self, sfx_path=None): e@0: e@0: if sfx_path is not None: e@0: self.sfx_df = pd.read_excel(sfx_path) e@0: else: e@0: self.sfx_df = None e@0: e@0: options = webdriver.ChromeOptions() e@0: options.binary_location = '/usr/bin/google-chrome-stable' e@0: options.add_argument('window-size=640x480') e@0: self.driver = webdriver.Chrome(chrome_options=options) e@0: e@0: def get_sfx(self, str_): e@0: e@0: if self.sfx_df is None: e@0: seconds = int(fxive_dict[str_][1]) e@0: url = fxive_dict[str_][0] + '&rTime={}'.format(seconds) e@0: else: e@0: seconds = 5 e@0: url = self.sfx_df['url'].loc[self.sfx_df['sfx'] == str_].iloc[0] + '&rTime={}'.format(seconds) e@0: print(url) e@0: e@0: e@0: self.driver.get(url) e@0: self.driver.implicitly_wait(10) e@0: e@0: print("Rendering file, please wait {} seconds".format(seconds+3)) e@0: e@0: time.sleep(seconds+3) e@0: # https://stackoverflow.com/questions/24134495/python-get-most-recent-file-in-a-directory-with-certain-extension e@0: newest = max(glob.iglob(os.path.expanduser('~/Downloads/*.wav')), key=os.path.getctime) e@0: e@0: return newest e@0: e@0: def close(self): e@0: self.driver.close() e@0: e@0: e@0: #fxive1 = FXive() e@0: #arr, sr = fxive1.get_sfx('river',3 ) e@0: #librosa.display.waveplot(arr,sr) e@0: #plt.show()