-
Notifications
You must be signed in to change notification settings - Fork 2
/
features.py
49 lines (36 loc) · 1.04 KB
/
features.py
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
from mido import MidiFile
from dotenv import load_dotenv
import os
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
load_dotenv()
uri = f"mongodb+srv://{os.getenv('USER')}:{os.getenv('PASSWORD')}@cluster0.vultpjd.mongodb.net/?retryWrites=true&w=majority"
client = MongoClient(uri, server_api=ServerApi('1'))
db = client["MusicCatalog"]
collection = db["MusicCatalog"]
title = input('Title: ')
album = input('Album: ')
singer = input('Singer: ')
composer = input('Composer: ')
lyricist = input('Lyricist: ')
link = input('Link: ')
sr=48000
hop_length=2048
midi = MidiFile(input('MIDI file path: '))
vector = []
for message in midi.play():
if message.type == 'note_off':
time = message.time
note = message.note
for i in range(int(time * sr / hop_length)):
vector.append(note)
data = {
"title": title,
"album": album,
"singer": singer,
"composer": composer,
"lyricist": lyricist,
"link": link,
"vector": vector
}
collection.insert_one(data)