Mercurial > hg > chourdakisreiss2018smc
view demo/workspace/rtsfx.py @ 0:90155bdd5dd6
first commit
author | Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Wed, 16 May 2018 18:27:05 +0100 |
parents | |
children |
line wrap: on
line source
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Apr 18 19:31:02 2018 @author: mmxgn """ from selenium import webdriver import librosa import librosa.display import glob import time import os import matplotlib.pyplot as plt import pandas as pd fxive_dict = { 'stream' : ('http://localhost:8000/update/app/main-panel/stream.html?preset=Stream', '3'), 'sonar' : ('http://localhost:8000/update/app/main-panel/beep.html?preset=Sonar', '10'), 'motor' : ('http://localhost:8000/update/app/main-panel/dc-motor.html?preset=Small%20Boat', '15'), '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'), 'meadow': ('http://localhost:8000/update/app/main-panel/stream.html?preset=Stream', '3'), } class FXive: def __init__(self, sfx_path=None): if sfx_path is not None: self.sfx_df = pd.read_excel(sfx_path) else: self.sfx_df = None options = webdriver.ChromeOptions() options.binary_location = '/usr/bin/google-chrome-stable' options.add_argument('window-size=640x480') self.driver = webdriver.Chrome(chrome_options=options) def get_sfx(self, str_): if self.sfx_df is None: seconds = int(fxive_dict[str_][1]) url = fxive_dict[str_][0] + '&rTime={}'.format(seconds) else: seconds = 5 url = self.sfx_df['url'].loc[self.sfx_df['sfx'] == str_].iloc[0] + '&rTime={}'.format(seconds) print(url) self.driver.get(url) self.driver.implicitly_wait(10) print("Rendering file, please wait {} seconds".format(seconds+3)) time.sleep(seconds+3) # https://stackoverflow.com/questions/24134495/python-get-most-recent-file-in-a-directory-with-certain-extension newest = max(glob.iglob(os.path.expanduser('~/Downloads/*.wav')), key=os.path.getctime) return newest def close(self): self.driver.close() #fxive1 = FXive() #arr, sr = fxive1.get_sfx('river',3 ) #librosa.display.waveplot(arr,sr) #plt.show()