Uber said it may soon know if customers are drunk — even before they get picked up.

The ride-hailing company said in a recent patent application that it has come up with a way to tell “the state of the user” by analyzing a number of factors.

The patent imagines a world where you might stumble out of a bar at 2 a.m. and the app will be able to know if you are drunk based on the angle you’re holding your phone, how you are walking and how you are interacting with the app compared to other times you’ve used it.

For example, the app will be able to register the speed at which you switch through pages and type directions — skills that are normally impaired after too much alcohol.

The application, titled “Predicting user state using machine learning,” says that the app would notify drivers of the “state” the customer is in.

If it appears that a customer is impaired, the app will match them with a driver “with experience or training with users having an unusual state,” according to the application filed with the US Patent and Trademark Office.

In an interview with The Post, Uber Chief Executive Dara Khosrowshahi described it as a “crazy idea” — conceived at an in-house hackathon.

“We don’t know whether we can commercialize it or not but it’s kind of a cool idea,” he said. “If it makes Uber safer but opens us up to be available to everyone, it’s certainly something we would look at.”

Uber has said it is looking to recruit more female drivers, and that weeding out possible drunk passengers wouldn’t hurt that effort.

It is not known if the info would be used to deter drivers from picking up such passengers in order to sidestep potential trouble.

Uber has no imminent plans to roll out the drunk-detecting tech, and has not shared details of how or when it would be used.

With Danielle Furfaro