-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path09_python_OSC_data_sender.py
More file actions
85 lines (70 loc) · 9.11 KB
/
09_python_OSC_data_sender.py
File metadata and controls
85 lines (70 loc) · 9.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#This program listens to several addresses, and prints some information about received packets.
import argparse
import math
import requests # importing the requests library
from pythonosc import dispatcher
from pythonosc import osc_server
from pythonosc import udp_client
import json
client = udp_client.SimpleUDPClient('127.0.0.1', 5006) #this client sends to SC
#def tf_handler(unused_addr, *args):
# sending get request and saving the response as response object
headers = {"content-type": "application/json"}
#data = {"instances": [[*args]]}
#data = {"instances": [[0.041936565190554,0.032059013843536,0.030089406296611,0.077820494771004,0.15420484542847,0.18183119595051,0.065042808651924,0.047550316900015,0.028162691742182,0.023385472595692,0.034666936844587,0.046103205531836,0.39019185304642,0.31156715750694,0.22988504171371,0.99054163694382,0.9373100399971,0.92201918363571,0.19265024363995,0.070833414793015,0.046349670737982,0.033381376415491,0.069773949682713,0.12093216925859,0.17335620522499,0.066322207450867,0.034398194402456,0.024828063324094,0.028708720579743,0.036969713866711,0.049505569040775,0.34541577100754,0.29664179682732,0.20788516104221,0.99056619405746,0.93655282258987,0.92207098007202,0.19014853239059,0.044834580272436,0.075794830918312,0.058394558727741,0.055273402482271,0.096657432615757,0.16366383433342,0.082803830504417,0.024457586929202,0.024853954091668,0.030369685962796,0.022445909678936,0.027469918131828,0.43923243880272,0.26492539048195,0.3078026175499,0.99071329832077,0.93673247098923,0.92220658063889,0.18654923141003,0.042450625449419,0.062807492911816,0.022676130756736,0.077096097171307,0.14078330993652,0.13533592224121,0.047845423221588,0.037605565041304,0.02925962023437,0.032300811260939,0.012359394691885,0.017929593101144,0.43923243880272,0.24253730475903,0.28586387634277,0.9904191493988,0.9493715763092,0.92201149463654,0.18479047715664,0.059029255062342,0.086857132613659,0.025873053818941,0.046905770897865,0.075408473610878,0.041986271739006,0.044802639633417,0.037688013166189,0.024041038006544,0.031171238049865,0.02981236949563,0.037732370197773,0.21535177528858,0.19776119291782,0.19186592102051,0.98996841907501,0.91745406389236,0.92172527313232,0.18302209675312,0.042498521506786,0.072610199451447,0.069073915481567,0.05040742456913,0.035924911499023,0.032208420336246,0.047663260251284,0.037088882178068,0.016058504581451,0.024548975750804,0.02090030349791,0.053677495568991,0.43923243880272,0.26679104566574,0.33212798833847,0.98999059200287,0.92835205793381,0.92175906896591,0.18006929755211,0.036908570677042,0.040950771421194,0.050244733691216,0.061149284243584,0.018854754045606,0.032014235854149,0.049600925296545,0.026885580271482,0.02428531832993,0.029087962582707,0.030491475015879,0.041635882109404,0.57356071472168,0.3358208835125,0.43585813045502,0.98990482091904,0.92405676841736,0.92172741889954,0.17804296314716,0.046607680618763,0.029519369825721,0.043951209634542,0.036747552454472,0.031304821372032,0.012361654080451,0.027823563665152,0.051408126950264,0.025157988071442,0.03116868622601,0.02638435550034,0.049433428794146,0.53091686964035,0.30597016215324,0.41454544663429,0.99001532793045,0.91409718990326,0.9218031167984,0.17588970065117,0.075526557862759,0.04496031627059,0.059743702411652,0.052422471344471,0.028434060513973,0.014223497360945,0.016756163910031,0.044564813375473,0.014538938179612,0.053829930722713,0.03930888697505,0.077363580465317,0.58208954334259,0.6194030046463,0.45549553632736,0.99032837152481,0.9067057967186,0.9220409989357,0.17252843081951,0.10308836400509,0.045763924717903,0.071441330015659,0.043703235685825,0.028608987107873,0.022595962509513,0.040739048272371,0.040369525551796,0.0078020733781159,0.078126989305019,0.075545467436314,0.080335795879364,0.56076765060425,0.36380597949028,0.32037109136581,0.99067509174347,0.91601699590683,0.92227590084076,0.17040403187275,0.11319696158171,0.059264939278364,0.074351266026497,0.046587873250246,0.011903530918062,0.022280747070909,0.034779630601406,0.027170117944479,0.016431719064713,0.10559657216072,0.078966774046421,0.091107375919819,0.59914708137512,0.50932836532593,0.41258233785629,0.99101030826569,0.91368401050568,0.92250394821167,0.16833531856537,0.06712482124567,0.044085945934057,0.10135383158922,0.16527380049229,0.016370698809624,0.017273496836424,0.014423417858779,0.011074351146817,0.010282206349075,0.053479820489883,0.033301588147879,0.055431745946407,0.42430701851845,0.46268656849861,0.20203883945942,0.99132412672043,0.91405898332596,0.92270630598068,0.16657930612564,0.028206566348672,0.051788136363029,0.13602384924889,0.129394993186,0.04477971419692,0.010325639508665,0.0080334264785051,0.012466350570321,0.014321833848953,0.015861086547375,0.022040354087949,0.023391041904688,0.50746268033981,0.55597019195557,0.27586349844933,0.99167865514755,0.90861976146698,0.92293173074722,0.16481505334377,0.020967768505216,0.071588404476643,0.10260511189699,0.023878816515207,0.02517481893301,0.0088531710207462,0.013678923249245,0.0089324433356524,0.0079061919823289,0.040705934166908,0.017979633063078,0.01712454482913,0.72068232297897,0.71641790866852,0.44787457585335,0.9919199347496,0.93638223409653,0.92307507991791,0.16423062980175,0.019352607429028,0.029859581962228,0.024044493213296,0.021939031779766,0.020622499287128,0.013196577318013,0.020543146878481,0.016630735248327,0.011461212299764,0.011235452257097,0.011834749951959,0.011802049353719,0.64179104566574,0.63059705495834,0.4452950656414,0.99214959144592,0.90880066156387,0.92320215702057,0.16471126675606,0.013570440001786,0.01476052775979,0.014789614826441,0.010584073141217,0.011401229538023,0.0054151117801666,0.0092838816344738,0.010541400872171,0.0072119198739529,0.0098686451092362,0.0060566230677068,0.0082803200930357,0.59488272666931,0.47201493382454,0.47425574064255,0.99244451522827,0.90401291847229,0.9233626127243,0.16528378427029,0.013048377819359,0.0094274105504155,0.014440406113863,0.011987819336355,0.0055629941634834,0.0058978698216379,0.0045385779812932,0.01122379489243,0.0065355496481061,0.011257235892117,0.0064635956659913,0.0076829823665321,0.73560774326324,0.5,0.59148365259171,0.99283182621002,0.90622770786285,0.92358845472336,0.16598388552666,0.010836808942258,0.0090765915811062,0.015600466169417,0.0069082789123058,0.0082779126241803,0.010811829008162,0.0058813523501158,0.0058341366238892,0.0078679360449314,0.016912888735533,0.014301097020507,0.004967971239239,0.70149254798889,0.4197761118412,0.49587771296501,0.99306184053421,0.93840914964676,0.92371809482574,0.16722489893436,0.01129902806133,0.011853105388582,0.014561583288014,0.0049695358611643,0.010931422002614,0.016330488026142,0.010919068008661,0.0086963726207614,0.0084627978503704,0.033953338861465,0.035685490816832,0.0052819671109319,0.56289976835251,0.36194029450417,0.45078572630882,0.99304187297821,0.91075879335403,0.92368471622467,0.16984710097313,0.0044574737548828,0.013208940625191,0.014190497808158,0.0082565005868673,0.02486072294414,0.010240953415632,0.011158086359501,0.017058169469237,0.015329769812524,0.063877910375595,0.042418707162142,0.0047494731843472,0.51599144935608,0.36007460951805,0.35835897922516,0.9930505156517,0.89790385961533,0.92367577552795,0.21481466293335]]}
r = requests.post(url = "http://localhost:8501/v1/models/improv_class:predict", data=json.dumps(data), headers=headers)
# extracting data in json format
data = r.json()["predictions"]
client.send_message("/clase", *data)
print (data)
#caotico = data[0][0]
complejo = data[0][0]
fijo = data[0][1]
periodico = data[0][2]
file = open('clases_database.txt', 'a')
# printable_data = "Compuesto", str(data)
# # if caotico > 0.5:
# # printable_data = "Caotico", str(caotico)
# if complejo > 0.5:
# printable_data = "Complejo", str(complejo)
# if fijo > 0.5:
# printable_data = "Fijo", str(fijo)
# if periodico > 0.5:
# printable_data = "Periodico",str(periodico)
# print(printable_data)
# #print(data)
printable_data = "Compuesto", str(data)
if complejo > 0.5:
printable_data = "Complejo", str(complejo)
if fijo > 0.5:
printable_data = "Fijo", str(fijo)
if periodico > 0.5:
printable_data = "Periodico", str(periodico)
print(printable_data)
#print(data)
for i in printable_data:
file.write(printable_data + ", ")
while n < lenFiles:
myaudio = AudioSegment.from_file(files[n], "wav")
n = n+1
chunk_length_ms = 8000 # pydub calculates in millisec
chunks = make_chunks(myaudio, chunk_length_ms) #Make chunks of one sec
lenChunks = (len(chunks))
for i, chunk in enumerate(chunks):
chunk_name = "chunk{:02d}.wav".format(i)
print ("exporting", chunk_name)
chunk.export((str(lenChunks) + "_" + chunk_name), format="wav")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip",
default="127.0.0.1", help="The ip to listen on")
parser.add_argument("--port",
type=int, default=5005, help="The port to listen on")
args = parser.parse_args()
dispatcher = dispatcher.Dispatcher()
dispatcher.map("/features", tf_handler)
server = osc_server.ThreadingOSCUDPServer(
(args.ip, args.port), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()
file.close()