Nikolas Cruz, the teen who confessed to having killed 17 people at a Florida high school, told investigators that he heard voices in his head telling him to "burn, kill, destroy" and that he tried but failed to kill himself two months before the massacre, according to a just-released transcript of his first formal interview with authorities.

Cruz, 19, is charged with 17 counts of murder and 17 counts of attempted murder in the assault on Marjory Stoneman Douglas High School in Parkland on Valentine's Day. His attorneys have said he would be willing to plead guilty to avoid the death penalty, an offer prosecutors have rejected.

Under Florida law, statements that are considered to be the "substance" of a confession must be withheld from the public until trial. As a result, long parts of the transcript of his interview with a Broward County sheriff's detective are blacked out.

It does, however, reveal a deeply troubled young man who, at one point, was overhead talking to himself, saying: "Kill me. Just f---ing kill me. F---."

School and government records previously made public have revealed that Cruz was diagnosed as developmentally delayed at age 3 and had disciplinary issues dating to middle school.

During the interview, he says that he had used a lot of marijuana and had taken a lot of the prescription tranquilizer Xanax.

He says that "two months ago" — which would be mid-December — he swallowed most of a bottle of ibuprofen in an attempt to kill himself because he was depressed by his mother's recent death. But he only got sick, he says.

It wasn't his first suicide attempt, he says, providing no details beyond the word "alcohol."

The transcript shows that Cruz shook his head "no" when he was asked whether he understand his constitutional right to remain silent. After extensive explanation by the detective, he eventually says he understands.

Repeatedly, he tells the detective, "I can't remember anything, dude."

He also seems unable to recall what city he was born in or the name of the friend he had temporarily been living with, although he does ask whether the friend is "okay."

Several times, the detective asks Cruz whether he wants some water. Cruz repeatedly refuses, at one point saying, "I don't deserve it."

Cruz's lawyers strenuously opposed releasing even the heavily redacted transcript, arguing that it would contaminate potential jurors, but they didn't object when a judge overruled them last month.

Gordon Weekes, Cruz's public defender, said he had no comment.

CORRECTION (Aug. 6, 2018, 6:35 p.m. ET): An earlier version of this story misspelled the name of the Florida school where 17 people were killed. The high school is named after Marjory Stoneman Douglas, not Margery Stoneman Douglas.