Created
December 10, 2019 07:22
-
-
Save analyticsindiamagazine/d464752fa7bcea17e566226eb2a6cb0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"#Loading the saved model\n", | |
"import pickle\n", | |
"filename = 'News_Classifier.pkl'\n", | |
"model = pickle.load(open(filename, 'rb'))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"------------------------------\n", | |
"------------------------------\n", | |
"\n", | |
"\n", | |
"Hi !! Say something and I will try to understand what you are talking about !!\n", | |
"\n", | |
"------------------------------\n", | |
"\n", | |
"Listening :\n", | |
"\n", | |
"------------------------------\n", | |
"\n", | |
"You said : comparison between iPhone 8 versus iPhone 7 give your perspective the iPhone 8 was released in September 2017 volume iPhone 7 in September 2016 16 years of 1 year gap between the two in every people are asking questions suggest shall I upgrade from iPhone 7 to iPhone 8 for which one should I buy iPhone 7 or iPhone 8 and the very basic question just tell me which one is better please remind me after watching this video will deep dive by looking at every aspect of the Smartphones and deliver you\n", | |
"Converting to features started.\n" | |
] | |
}, | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "8d267d59fc9943b496620f44665e774c", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, max=1), HTML(value='')))" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "834d051dfe7f4284a41b21a5db23391e", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, max=1), HTML(value='')))" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"\n", | |
"You spoke about TECHNOLOGY\n" | |
] | |
} | |
], | |
"source": [ | |
"#Importing the speech recognition module\n", | |
"import speech_recognition as sr\n", | |
"#A random default value for prediction -- not among the classes we are predicting\n", | |
"prediction = 10\n", | |
"\n", | |
"#Initializing the speech recognizer\n", | |
"r = sr.Recognizer()\n", | |
"\n", | |
"#Declaring the listener source\n", | |
"with sr.Microphone() as source:\n", | |
" print('-'*30)\n", | |
" print('-'*30)\n", | |
" print(\"\\n\\nHi !! Say something and I will try to understand what you are talking about !!\\n\")\n", | |
" print('-'*30)\n", | |
" print(\"\\nListening :\\n\")\n", | |
" print('-'*30)\n", | |
" \n", | |
" #Initializing the listener \n", | |
" audio = r.listen(source)\n", | |
" \n", | |
" #Collecting Speech and Classifying\n", | |
" try:\n", | |
" text = r.recognize_google(audio)\n", | |
" print(\"\\nYou said : {}\".format(text))\n", | |
" prediction, _ = model.predict([text.strip()])\n", | |
" \n", | |
" except:\n", | |
" print(\"\\nSorry could not recognize what you said\")\n", | |
" \n", | |
" if int(prediction) == 0:\n", | |
" print('\\nYou spoke about POLITICS')\n", | |
" elif int(prediction) == 1:\n", | |
" print('\\nYou spoke about TECHNOLOGY')\n", | |
" elif int(prediction) == 2:\n", | |
" print('\\nYou spoke about Entertainment')\n", | |
" elif int(prediction) == 3:\n", | |
" print('\\nYou spoke about Business')" | |
] | |
} | |
], | |
"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.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment