寫程式自動將口琴聲音轉成簡譜
先自己吹口琴創造training data,存成wav檔 用MFCC的code將wav檔轉成MFCC存成numpy array 用ML或DL的方式train model supervised learning : 要先把data label(在蒐集時就label好了) 目前只蒐集do~so和noise的wav檔。 使用focus用法,針對signal,取發生那段(詳述在problem.txt內)
- python3.5
- sklearn
- scipy
- numpy
- pyaudio == 0.2.11
- DNN:
- keras == 2.0.8
- tensorflow == 1.3.0
- train decision tree
python3 tree.py
- train random forrest
python3 forrest.py 5 5代表tree數量,也可以自己改
- dnn
python3.5 dnn.py [testfile] => 一路從train到test(使用doremi.wav) testfile放要測試的wav檔 EX : python3.5 dnn.py Testdata/test.wav
python3 test.py [testfile] [model] [tree_num]
testfile 測試的wav檔 ==> 可以用 Testdata/doremi.wav
model為要用的模型 ==> 可以為 tree或 forrest,分別代表使用decision tree、random forrest
tree_num為random forrest樹的數量,只有用random forrest時才要用
EX : python3 test.py Testdata/doremi.wav tree
EX2 : python3 test.py Testdata/doremi.wav forrest 5
python3.5 dnn.py
- record.py:蒐集wav檔的主要程式碼
- complement.py:record.py是做大量蒐集,中間如果有漏錄,或者吹錯音,用這個程式修改,這個程式只做單一wav檔錄製
- mfcc.py:將上述wav檔轉成numpy array(MFCC,36維)
- tree.py : regression decision tree
- svm.py : svm model
- train.py : library for training and turn data to mfcc
- test.py :把file.wav拿來test
- demo.py : demo時錄音用
- dnn.py : Deep Nueral Network
- autoencoder.py : 降維
- tree.pkl:用tree.py train出來的model
- tree00~06.pkl: random forrest的model
- model都存在Dropbox內
- Traindata/
- do/
- wav檔,從00~80.wav
- re/
- wav檔,從00~80.wav
- mi/
- wav檔,從00~80.wav
- fa/
- wav檔,從00~80.wav
- so/
- wav檔,從00~80.wav
- do/
- MFCC/
- do/
- test.npy(do的所有wav檔轉成的大array),shape=(81,43,36)
- re/
- test.npy(do的所有wav檔轉成的大array),shape=(81,43,36)
- mi/
- test.npy(do的所有wav檔轉成的大array),shape=(81,43,36)
- fa/
- test.npy(do的所有wav檔轉成的大array),shape(81,43,36)
- so/
- test.npy(do的所有wav檔轉成的大array),shape=(81,43,36)
- do/
內有所有的model,所以照理說只是要測試的話直接執行 test.py tree.pkl、forrest都有model
do,re,mi,fa,so五個音個80個wav檔,每個wav檔就是一個那個特定的音
<歡樂頌> 前12個音、C大調音階
使用sklearn DecisionTreeRegressor,目前發現效果最好。
使用keras實作
- activation : sigmoid(最後一層用softmax)
- optimizer : adam
- loss : categorical_crossentropy 效果蠻差的,
以上的code都是沒有使用autoencoder的部分, 要使用autoencoder的方法為 首先產生encoder_model
python3 autoencode.py
在test.py裡33,34行內加入
encoder = train.loadAutoencoder()
data = train.lessdimension(data,encoder)
tree.py為例在shuffle之前(約25~26行的地方)加入
encoder = train.loadAutoencoder()
alldata = train.lessdimension(alldata,encoder)
dnn.py在(34~35行)data reshape完但未predict前
encoder = train.loadAutoencoder()
data = train.lessdimension(data,encoder)
forrest在shuffle前(26行)加入
encoder = train.loadAutoencoder()
alldata = train.lessdimension(alldata,encoder)