You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
321 lines
7.7 KiB
321 lines
7.7 KiB
2 years ago
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import sys\n",
|
||
|
"import os\n",
|
||
|
"#sys.path.insert(0, os.path.abspath(\"..\\\\..\\\\Sources\")) # FOR WINDOWS\n",
|
||
|
"sys.path.insert(0, os.path.abspath(\"../../Sources\")) # FOR LINUX\n",
|
||
|
"import time"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
2 years ago
|
"from pyOpenRPA.Robot import Audio\n",
|
||
2 years ago
|
"print(Audio.DeviceSystemSoundIndex())\n",
|
||
|
"Audio.DeviceListGet()[9]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"from pyOpenRPA.Robot import Audio\n",
|
||
|
"lRec = Audio.Recorder(inDeviceInt = Audio.DeviceMicrophoneIndex())\n",
|
||
2 years ago
|
"lRec.CaptureStart(inFileNameStr = \"out2\", inFileFormatStr = \"mp3\", inDurationSecFloat = None, inChunkSecFloat = 15.0)"
|
||
2 years ago
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"from pyOpenRPA.Robot import Audio\n",
|
||
2 years ago
|
"lRec = Audio.Recorder()\n",
|
||
2 years ago
|
"lRec.CaptureStart(inFileNameStr = \"out\", inFileFormatStr = \"mp3\", inDurationSecFloat = None, inChunkSecFloat = 5.0, inCallbackChunkDef=test)"
|
||
2 years ago
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
2 years ago
|
"lRec.hi"
|
||
2 years ago
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"lRec.CaptureStop()"
|
||
|
]
|
||
|
},
|
||
2 years ago
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
2 years ago
|
"def test(lRec, lFilenameStr):\n",
|
||
|
" lRec.hi=[lFilenameStr]"
|
||
2 years ago
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"lRec.StatusGet()"
|
||
|
]
|
||
|
},
|
||
2 years ago
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"print (textcolors.blue + \"Available devices:\\n\" + textcolors.end)\n",
|
||
|
"for i in range(0, p.get_device_count()):\n",
|
||
|
" info = p.get_device_info_by_index(i)\n",
|
||
|
" print(info[\"hostApi\"])\n",
|
||
|
" print (textcolors.green + str(info[\"index\"]) + textcolors.end + \": \\t %s \\n \\t %s \\n\" % (info[\"name\"], p.get_host_api_info_by_index(info[\"hostApi\"])[\"name\"]))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"class textcolors:\n",
|
||
|
" if not os.name == 'nt':\n",
|
||
|
" blue = '\\033[94m'\n",
|
||
|
" green = '\\033[92m'\n",
|
||
|
" warning = '\\033[93m'\n",
|
||
|
" fail = '\\033[91m'\n",
|
||
|
" end = '\\033[0m'\n",
|
||
|
" else:\n",
|
||
|
" blue = ''\n",
|
||
|
" green = ''\n",
|
||
|
" warning = ''\n",
|
||
|
" fail = ''\n",
|
||
|
" end = ''"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"import pyaudio\n",
|
||
|
"defaultframes = 512\n",
|
||
|
"recorded_frames = []\n",
|
||
|
"device_info = {}\n",
|
||
|
"useloopback = True\n",
|
||
|
"#Use module\n",
|
||
|
"p = pyaudio.PyAudio()\n",
|
||
|
"\n",
|
||
2 years ago
|
"recordtime = 2\n",
|
||
2 years ago
|
"device_id = 10\n",
|
||
|
"device_info = p.get_device_info_by_index(device_id)\n",
|
||
|
"#Open stream\n",
|
||
|
"channelcount = device_info[\"maxInputChannels\"] if (device_info[\"maxOutputChannels\"] < device_info[\"maxInputChannels\"]) else device_info[\"maxOutputChannels\"]\n",
|
||
|
"stream = p.open(format = pyaudio.paInt16,\n",
|
||
|
" channels = channelcount,\n",
|
||
|
" rate = int(device_info[\"defaultSampleRate\"]),\n",
|
||
|
" input = True,\n",
|
||
|
" frames_per_buffer = defaultframes,\n",
|
||
|
" input_device_index = device_info[\"index\"],\n",
|
||
|
" as_loopback = useloopback)\n",
|
||
|
"\n",
|
||
|
"#Start Recording\n",
|
||
|
"print (\"Starting...\")\n",
|
||
|
"\n",
|
||
|
"for i in range(0, int(int(device_info[\"defaultSampleRate\"]) / defaultframes * recordtime)):\n",
|
||
|
" recorded_frames.append(stream.read(defaultframes))\n",
|
||
|
"\n",
|
||
|
"print (\"End.\")\n",
|
||
|
"#Stop Recording\n",
|
||
|
"\n",
|
||
|
"stream.stop_stream()\n",
|
||
|
"stream.close()\n",
|
||
|
"\n",
|
||
|
"#Close module\n",
|
||
|
"p.terminate()\n",
|
||
|
"\n",
|
||
|
"filename = \"out.wav\"\n",
|
||
|
"from pydub import AudioSegment\n",
|
||
|
"# Advanced usage, if you have raw audio data:\n",
|
||
|
"sound = AudioSegment(\n",
|
||
|
" # raw audio data (bytes)\n",
|
||
|
" data=b''.join(recorded_frames),\n",
|
||
|
" # 2 byte (16 bit) samples\n",
|
||
|
" sample_width=p.get_sample_size(pyaudio.paInt16),\n",
|
||
|
" # 44.1 kHz frame rate\n",
|
||
|
" frame_rate=int(device_info[\"defaultSampleRate\"]),\n",
|
||
|
" # stereo\n",
|
||
|
" channels=channelcount\n",
|
||
|
")\n",
|
||
2 years ago
|
"print(channelcount)\n",
|
||
|
"print(p.get_sample_size(pyaudio.paInt16))\n",
|
||
|
"print(int(device_info[\"defaultSampleRate\"]))\n",
|
||
|
"print(len(b''.join(recorded_frames)))\n",
|
||
2 years ago
|
"sound.export(\"out.mp3\", format=\"mp3\")"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import difflib\n",
|
||
|
"def similarity_no_case(s1, s2):\n",
|
||
|
" normalized1 = s1.lower()\n",
|
||
|
" normalized2 = s2.lower()\n",
|
||
|
" matcher = difflib.SequenceMatcher(None, normalized1, normalized2)\n",
|
||
|
" return matcher.ratio()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
2 years ago
|
"similarity_no_case(\"Ìèêðîôîí (Realtek High Definiti\",\"Динамики (Realtek High Definition Audio)\")"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"p.get_default_input_device_info()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import pyaudio\n",
|
||
|
"p = pyaudio.PyAudio()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"p"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"not (False ^ True)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"from pyOpenRPA.Robot import Audio\n",
|
||
|
"Audio.DeviceMicrophoneIndex()"
|
||
2 years ago
|
]
|
||
|
},
|
||
2 years ago
|
{
|
||
|
"cell_type": "code",
|
||
2 years ago
|
"execution_count": null,
|
||
2 years ago
|
"metadata": {},
|
||
2 years ago
|
"outputs": [],
|
||
2 years ago
|
"source": [
|
||
|
"import os\n",
|
||
|
"os.path.abspath(\"\",\"\")"
|
||
|
]
|
||
|
},
|
||
2 years ago
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.7.2"
|
||
|
},
|
||
|
"varInspector": {
|
||
|
"cols": {
|
||
|
"lenName": 16,
|
||
|
"lenType": 16,
|
||
|
"lenVar": 40
|
||
|
},
|
||
|
"kernels_config": {
|
||
|
"python": {
|
||
|
"delete_cmd_postfix": "",
|
||
|
"delete_cmd_prefix": "del ",
|
||
|
"library": "var_list.py",
|
||
|
"varRefreshCmd": "print(var_dic_list())"
|
||
|
},
|
||
|
"r": {
|
||
|
"delete_cmd_postfix": ") ",
|
||
|
"delete_cmd_prefix": "rm(",
|
||
|
"library": "var_list.r",
|
||
|
"varRefreshCmd": "cat(var_dic_list()) "
|
||
|
}
|
||
|
},
|
||
|
"types_to_exclude": [
|
||
|
"module",
|
||
|
"function",
|
||
|
"builtin_function_or_method",
|
||
|
"instance",
|
||
|
"_Feature"
|
||
|
],
|
||
|
"window_display": false
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|