How to use the OK Google command from any screen on your Android phone (including the lock screen)
Here it goes: open your Google app and scroll down until you see the menu icon on the bottom-right side of the page. Tap on the menu icon, then go to Settings -> Voice -> “OK Google” Detection. After that, you’ll see several options that can be activated, or deactivated, and you need to simply check the box next to “From any screen” to enable it. You’ll then be prompted to agree to the fact that Google can store your voice recordings (to help improve recognition). After you agree, you have to teach Google the sound of your voice by saying “OK Google” three times. And that is all: from now on, the power of Google Now is always with you, as long as your screen is on.
To use OK Google from your lock screen, you need to enable it separately - this is done in the same window where you enabled the use “from any screen.” As always, we’ve included screenshots to illustrate the whole process.
Before enabling the use of OK Google on any screen, make sure your Google app is up to date (check if it needs to be updated at the reference link below). Also note that your Google app's default language must be set to English (US).
reference: Google app (Play Store)