Spice Girl Mel B has confessed to taking cocaine during her stint as a judge on The X Factor.

Extracts of her autobiography published in The Sun on Sunday also reveal that she tried to take her own life in December 2014.

The 43-year-old speaks candidly in the book, entitled Brutally Honest, about some of the darkest times in her life, and admits that she used cocaine as a “quick fix” to help her cope with work and her turbulent marriage to second husband Stephen Belafonte.

“On so many levels I felt myself sinking,” she writes. “I had a routine. I was ashamed of what I was doing, but I felt I had to have it.”

The popstar, who insists she never took the drug during X Factor shows, tells how she prayed to God and told herself he would forgive her.

She claims she would snort the drug as soon as she left the building after filming the popular singing show, as it helped her “numb the pain”.

“I was a sad, pathetic person. I was out of control,” she says.

Mel B also opens up about her suicide attempt, which came during a run of live shows, and says she downed aspirin pills.

Despite writing notes to her children, she soon realised it was not the answer and told herself she needed to go to hospital, she says.

When she woke, her daughter Phoenix was by her bedside.

Mel B with the Spice Girls (Ian West/PA)

“Looking at my daughter — distraught, devastated, angry — was the moment I knew the fightback had to start,” she confesses.

The book is also said to explore her relationship with movie producer Belafonte, whom she married in 2007.

She finalised her divorce from Belafonte in August, bringing their bitter split to an end.

The mother-of-three, real name Melanie Brown, alleged during the divorce proceedings that he was abusive to her and her children, while he accused her of turning his stepdaughter Angel against him.

Speaking of the book, the Spice Girl, who is due to go on tour with the band next year, told The Sun: “Good, bad or ugly, I’m going to peel back the layers and tell it like it was. You can judge me or you can try and understand me.”