Skip to content

Commit

Permalink
speech to date system
Browse files Browse the repository at this point in the history
  • Loading branch information
privacyrespected committed Jun 27, 2022
1 parent 40356d6 commit 8a4afa1
Showing 1 changed file with 147 additions and 2 deletions.
149 changes: 147 additions & 2 deletions experiments/speechrecog.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,158 @@
"source": [
"This notebook is designed to develop possibilities in improving speech recognition system by improving accuracy and understand. It will also explore other platforms that can be used for speech recognition."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 1: Converting date to speech\n",
"\n",
"Users will be asking many forms of dates so we need to convert them into one singular form, as such we will also be defining dates beforehand so computation will be easier and errors are less likely to occur."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"See below are the defined lists:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"MONTHS = [\"january\", \"february\", \"march\", \"april\", \"may\", \"june\",\"july\", \"august\", \"september\",\"october\", \"november\", \"december\"]\n",
"DAYS = [\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\"]\n",
"DAY_EXTENTIONS = [\"rd\", \"th\", \"st\", \"nd\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then, we will write the function related "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"datetime.date(2022, 7, 1)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import datetime\n",
"MONTHS = [\"january\", \"february\", \"march\", \"april\", \"may\", \"june\",\"july\", \"august\", \"september\",\"october\", \"november\", \"december\"]\n",
"DAYS = [\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\"]\n",
"DAY_EXTENTIONS = [\"rd\", \"th\", \"st\", \"nd\"]\n",
"def get_date(text):\n",
" text = text.lower()\n",
" today = datetime.date.today()\n",
"\n",
" if text.count(\"today\") > 0:\n",
" return today\n",
"\n",
" day = -1\n",
" day_of_week = -1\n",
" month = -1\n",
" year = today.year\n",
"\n",
" for word in text.split():\n",
" if word in MONTHS:\n",
" month = MONTHS.index(word) + 1\n",
" elif word in DAYS:\n",
" day_of_week = DAYS.index(word)\n",
" elif word.isdigit():\n",
" day = int(word)\n",
" else:\n",
" for ext in DAY_EXTENTIONS:\n",
" found = word.find(ext)\n",
" if found > 0:\n",
" try:\n",
" day = int(word[:found])\n",
" except:\n",
" pass\n",
"\n",
" # THE NEW PART STARTS HERE\n",
" if month < today.month and month != -1: # if the month mentioned is before the current month set the year to the next\n",
" year = year+1\n",
"\n",
" # This is slighlty different from the video but the correct version\n",
" if month == -1 and day != -1: # if we didn't find a month, but we have a day\n",
" if day < today.day:\n",
" month = today.month + 1\n",
" else:\n",
" month = today.month\n",
"\n",
" # if we only found a dta of the week\n",
" if month == -1 and day == -1 and day_of_week != -1:\n",
" current_day_of_week = today.weekday()\n",
" dif = day_of_week - current_day_of_week\n",
"\n",
" if dif < 0:\n",
" dif += 7\n",
" if text.count(\"next\") >= 1:\n",
" dif += 7\n",
"\n",
" return today + datetime.timedelta(dif)\n",
"\n",
" if day != -1: # FIXED FROM VIDEO\n",
" return datetime.date(month=month, day=day, year=year)\n",
"\n",
"get_date(\"next friday\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, the entire date is converted into proper format for easier identification, even when its pure words."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task: Explore potential in implementation"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.7.8 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.8"
},
"orig_nbformat": 4
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "85cab9e096cbab1951b2d3a14822210bb6543dde301eda19da12202a5ce4203b"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down

0 comments on commit 8a4afa1

Please sign in to comment.