annotate demo/workspace/rtsfx.py @ 13:16066f0a7127 tip

fixed the problem with brat
author Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk>
date Sat, 08 Dec 2018 11:02:40 +0000
parents 90155bdd5dd6
children
rev   line source
e@0 1 #!/usr/bin/env python3
e@0 2 # -*- coding: utf-8 -*-
e@0 3 """
e@0 4 Created on Wed Apr 18 19:31:02 2018
e@0 5
e@0 6 @author: mmxgn
e@0 7 """
e@0 8
e@0 9 from selenium import webdriver
e@0 10 import librosa
e@0 11 import librosa.display
e@0 12 import glob
e@0 13 import time
e@0 14 import os
e@0 15 import matplotlib.pyplot as plt
e@0 16 import pandas as pd
e@0 17
e@0 18 fxive_dict = {
e@0 19 'stream' : ('http://localhost:8000/update/app/main-panel/stream.html?preset=Stream', '3'),
e@0 20 'sonar' : ('http://localhost:8000/update/app/main-panel/beep.html?preset=Sonar', '10'),
e@0 21 'motor' : ('http://localhost:8000/update/app/main-panel/dc-motor.html?preset=Small%20Boat', '15'),
e@0 22 '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 23 'meadow': ('http://localhost:8000/update/app/main-panel/stream.html?preset=Stream', '3'),
e@0 24
e@0 25 }
e@0 26
e@0 27 class FXive:
e@0 28 def __init__(self, sfx_path=None):
e@0 29
e@0 30 if sfx_path is not None:
e@0 31 self.sfx_df = pd.read_excel(sfx_path)
e@0 32 else:
e@0 33 self.sfx_df = None
e@0 34
e@0 35 options = webdriver.ChromeOptions()
e@0 36 options.binary_location = '/usr/bin/google-chrome-stable'
e@0 37 options.add_argument('window-size=640x480')
e@0 38 self.driver = webdriver.Chrome(chrome_options=options)
e@0 39
e@0 40 def get_sfx(self, str_):
e@0 41
e@0 42 if self.sfx_df is None:
e@0 43 seconds = int(fxive_dict[str_][1])
e@0 44 url = fxive_dict[str_][0] + '&rTime={}'.format(seconds)
e@0 45 else:
e@0 46 seconds = 5
e@0 47 url = self.sfx_df['url'].loc[self.sfx_df['sfx'] == str_].iloc[0] + '&rTime={}'.format(seconds)
e@0 48 print(url)
e@0 49
e@0 50
e@0 51 self.driver.get(url)
e@0 52 self.driver.implicitly_wait(10)
e@0 53
e@0 54 print("Rendering file, please wait {} seconds".format(seconds+3))
e@0 55
e@0 56 time.sleep(seconds+3)
e@0 57 # https://stackoverflow.com/questions/24134495/python-get-most-recent-file-in-a-directory-with-certain-extension
e@0 58 newest = max(glob.iglob(os.path.expanduser('~/Downloads/*.wav')), key=os.path.getctime)
e@0 59
e@0 60 return newest
e@0 61
e@0 62 def close(self):
e@0 63 self.driver.close()
e@0 64
e@0 65
e@0 66 #fxive1 = FXive()
e@0 67 #arr, sr = fxive1.get_sfx('river',3 )
e@0 68 #librosa.display.waveplot(arr,sr)
e@0 69 #plt.show()