Skip to content

Instantly share code, notes, and snippets.

@wakusei-meron-
Last active March 4, 2019 12:07
Show Gist options
  • Save wakusei-meron-/e2c7ac598bdf32985adcbf6176009e8a to your computer and use it in GitHub Desktop.
Save wakusei-meron-/e2c7ac598bdf32985adcbf6176009e8a to your computer and use it in GitHub Desktop.
Desktop/PPP/python/audio/Untitled.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# scipyでwavwile作成\n# doc: https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html\nimport numpy as np\nimport scipy.io.wavfile as siw\n\nstop = 60 # 再生秒数\nsr = 44100 # サンプリング周波数\nfrq = 440 # 波形の周波数\n\n# フレームの作成 \nrad = np.linspace(0, 2*np.pi * frq * stop, sr * stop)\n\n# 16bidの波形の作成\ny1 = np.sin(rad) * 0.5\ny2 = (y1*np.iinfo(np.int16).max).astype(np.int16)\ny3 = np.array(np.c_[y2,y2]) # ステレオにする\n\n# ファイル名を指定して保存\nfilename = str(frq ) + \"Hz-frequency_\" + str(sr) + \"Hz-SampleRate_\" + str(stop) + \"seconds-duration_sin-1.wav\"\nsiw.write(filename, sr, y3)\nprint(\"finished writing wav. filename = {}\".format(filename))",
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": "finished writing wav. filename = 440Hz-frequency_44100Hz-SampleRate_60seconds-duration_sin-1.wav\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# scipyでwavfileの読み込み\n# doc. https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.io.wavfile.read.html\nsiw.read(filename)",
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 2,
"data": {
"text/plain": "(44100, array([[ 0, 0],\n [ 1026, 1026],\n [ 2048, 2048],\n ...,\n [-2048, -2048],\n [-1026, -1026],\n [ 0, 0]], dtype=int16))"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"_draft": {
"nbviewer_url": "https://gist.github.com/e2c7ac598bdf32985adcbf6176009e8a"
},
"gist": {
"id": "e2c7ac598bdf32985adcbf6176009e8a",
"data": {
"description": "Desktop/PPP/python/audio/Untitled.ipynb",
"public": false
}
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.3",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment