Charlie Puth surprised people with his funk-infused “Attention,” a bass-heavy middle finger to a two-faced ex that climbed to No. 5 on the Billboard Hot 100 singles chart.

It’s a far cry from the blue-eyed soul that characterized early hits “One Call Away” and “Marvin Gaye” featuring Meghan Trainor, taken from his 2016 debut “Nine Track Mind.”

“I’m glad people are finally hearing the real me,” says Puth, 26. “I always had this music in me. It was just a matter of executing it.”

Attention” is the first single from the piano-playing crooner’s long-delayed sophomore effort “Voicenotes,” out Friday and named for the phone app he uses to make demos.

The album was written and recorded over the past year and a half during his solo headlining tour and North American trek with buddy Shawn Mendes, with Puth handling much of the production himself.

REVIEW: Charlie Puth makes astonishing, glistening pop on ‘Voicenotes’

The experience of making it couldn’t be more different than that of “Nine Track Mind,” which he was forced to rush-release to capitalize on the success of “See You Again,” his “Furious 7” smash with Wiz Khalifa that spent 12 nonconsecutive weeks atop the Hot 100 in summer 2015, tying Eminem’s “Lose Yourself” for the longest-running No. 1 rap single ever.

Critics weren’t kind to the album, writing that Puth “feels stage-managed” and his “anonymity is infuriating.”

“I agree with all of those critiques,” Puth says, “because it’s true. It was such bland music.”

When “See You Again” was released, he was still better known as a songwriter: “I wasn’t planning on being an artist. I had to figure out my artist career in front of millions of people while we had the biggest song in the past decade.

“Was it a good album? No, but I wouldn’t have it any other way. Now, ‘Voicenotes’ feels like my debut album.”

Charlie Puth performs onstage at American Airlines Center in Dallas in November. His new album "Voicenotes" is just out.

Charlie Puth performs onstage at American Airlines Center in Dallas in November. His new album “Voicenotes” is just out. | Getty Images

“Voicenotes” takes sonic cues from late ’80s R&B artists like Babyface and Teddy Riley and includes a feature from Boyz II Men on the a cappella ballad “If You Leave Me Now.”

His lyrics recount heartbreak and the perils of being in the spotlight. “LA Girls,” for instance, is about “how fame almost changed me and kind of made me jaded,” Puth says. “I spent a couple years thinking that I had to have a certain personality to be the ‘perfect male pop singer.’ ”

“Boy” is inspired by “an experience I had when I fell for someone older than me for the first time,” he says.

The lovelorn “Somebody Told Me” feels like a prequel to “We Don’t Talk Anymore”, his 2016 hit with Selena Gomez.

When not in the studio, Puth says he hangs out with best friend Adam Levine at home in Los Angeles and enjoys old-school hip-hop including MC Lyte and Naughty by Nature.

Asked whether he’d ever rap on a song like his pop peers Taylor Swift and Ed Sheeran, he jokingly declines.

“I’ve found out in my career that no one wants to see me dance because I can’t dance for . . .,” Puth says, “and no one wants to see me rap.”