|
@@ -468,8 +468,8 @@
|
|
|
" 'hostapi': 2,\n",
|
|
|
" 'max_input_channels': 6,\n",
|
|
|
" 'max_output_channels': 10,\n",
|
|
|
- " 'default_low_input_latency': 0.005804988662131519,\n",
|
|
|
- " 'default_low_output_latency': 0.005804988662131519,\n",
|
|
|
+ " 'default_low_input_latency': 0.0014512471655328798,\n",
|
|
|
+ " 'default_low_output_latency': 0.0014512471655328798,\n",
|
|
|
" 'default_high_input_latency': 0.09287981859410431,\n",
|
|
|
" 'default_high_output_latency': 0.09287981859410431,\n",
|
|
|
" 'default_samplerate': 44100.0}]"
|
|
@@ -487,21 +487,22 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 2,
|
|
|
+ "execution_count": 1,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
"import sounddevice as sd\n",
|
|
|
"import numpy as np\n",
|
|
|
+ "import keyboard # using module keyboard\n",
|
|
|
"\n",
|
|
|
"sd.default.device = [1, 26]\n",
|
|
|
"sd.default.samplerate = 44100\n",
|
|
|
- "stream = sd.OutputStream(samplerate=44100, channels=10, dtype='float32')\n"
|
|
|
+ "stream = sd.OutputStream(samplerate=44100, channels=10, dtype='float32')"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 3,
|
|
|
+ "execution_count": 2,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -511,33 +512,37 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 4,
|
|
|
+ "execution_count": 3,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "stream.start()\n",
|
|
|
+ "duration = 0.5\n",
|
|
|
"\n",
|
|
|
- "duration = 10\n",
|
|
|
"x1 = np.linspace(0, duration * 220 * 2*np.pi, int(duration*44100), dtype=np.float32)\n",
|
|
|
"x2 = np.linspace(0, duration * 440 * 2*np.pi, int(duration*44100), dtype=np.float32)\n",
|
|
|
"y1 = np.sin(x1)\n",
|
|
|
"y2 = np.sin(x2)\n",
|
|
|
- "sil = np.zeros(len(x1), dtype=np.float32)\n",
|
|
|
- "\n",
|
|
|
- "#stream.write(np.column_stack([y1, sil, sil, sil, sil, sil, sil, sil, sil, sil]) * 0.5)\n",
|
|
|
- "#stream.write(np.column_stack([sil, y1, sil, sil, sil, sil, sil, sil, sil, sil]) * 0.5)\n",
|
|
|
- "stream.write(np.column_stack([sil, sil, sil, sil, sil, y1, sil, sil, sil, sil]) * 0.5)\n",
|
|
|
- "#stream.write(np.column_stack([sil, sil, sil, sil, sil, y1, sil, sil, sil, sil]) * 0.5)\n",
|
|
|
- "\n",
|
|
|
+ "sil = np.zeros(len(x1), dtype=np.float32)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 5,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "stream.start()\n",
|
|
|
"\n",
|
|
|
- "# for i in range(10):\n",
|
|
|
- "# if i % 2 == 0:\n",
|
|
|
- "# output = np.column_stack([y1, sil, sil, sil])\n",
|
|
|
- "# else:\n",
|
|
|
- "# output = np.column_stack([sil, sil, y2, sil])\n",
|
|
|
- "# stream.write(output*0.5)\n",
|
|
|
+ "try:\n",
|
|
|
+ " while True: # making a loop\n",
|
|
|
+ " if keyboard.is_pressed('q'): # if key 'q' is pressed \n",
|
|
|
+ " break # finishing the loop\n",
|
|
|
"\n",
|
|
|
- "stream.stop()"
|
|
|
+ " stream.write(np.column_stack([y1, sil, sil, sil, sil, sil, sil, y2, sil, sil]) * 0.8)\n",
|
|
|
+ " #stream.write(np.column_stack([y2, y2, y2, y2, y2, y2, y2, y2, y2, y2]) * 0.8)\n",
|
|
|
+ " \n",
|
|
|
+ "finally:\n",
|
|
|
+ " stream.stop()"
|
|
|
]
|
|
|
},
|
|
|
{
|