2017年12月1日 星期五

如何利用 Python 產生樂譜上 中央C D E F G 等 pitch 的訊號

How to create pitch signals
井民全, Jing, mqjing@gmail.com

ETA: 5 min
Back to the Main Page
Google doc: This Document

Purpose

這篇文章教你如何利用 Python 產生樂譜上 中央C D E F G 等 pitch 的訊號, 並且播放出來.

Key Point

Code

from __future__ import print_function, division

%matplotlib inline

import thinkdsp
import thinkplot
import numpy as np

import warnings
warnings.filterwarnings('ignore')

from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets


from thinkdsp import Signal
import math


C4=261.63
D4=293.66
E4=329.63
F=293.66
G=392
A=440
B=493.88
freq=C4
signal = thinkdsp.SinSignal(freq, amp=0.5, offset=0)

# 測試聲音
wave1 = signal.make_wave(duration=1)    # 建立 4 秒鐘,波形
#wave1.segment(start=0, duration=1).plot()  # 只看 1 秒鐘這範圍的波形 y
wave1.make_audio()

Output


Reference