US President Barack Obama has implored Americans of all races to show more unity and understanding as he addressed an emotional memorial ceremony for five police officers shot dead in Dallas last week.

"I know that Americans are struggling right now with what we've witnessed over the past week," Obama said on Tuesday

"I'm here to say we must reject such despair. I'm here to insist that we are not as divided as we seem."

Obama's speech included a frank admission that his own efforts to tackle violence, guns and racism had come up short.

"I have spoken at too many memorials during the course of this presidency," he said with uncommon candour. "I've seen how a spirit of unity born of tragedy can gradually dissipate."

"I've seen how inadequate words can be in bringing about lasting change. I've seen how inadequate my own words have been."

REPORTER'S NOTEBOOK: There are two Americans that need to meet one another

Al Jazeera’s Patty Culhane, reporting from in Dallas, said that unlike Obama's previous speeches after other mass shootings, "this was not a president hoping to comfort people, just the opposite.

"This was an impatient president," Culhane said.

Obama said it was time for the country to start having "uncomfortable conversations about race", as well as inequality and gun control, Culhane added.

'Prejudice in our heads and hearts'

Dallas residents unite in wake of US police shootings

Micah Johnson, 25, a US military veteran, was killed on July 7 by police using an explosive device after he shot dead five police officer in the streets of Dallas following a demonstration over police killings of African-Americans. Nine other officers and two civilians were wounded by Johnson.

Black Americans protesting about police racism, Obama said, must understand how hard the police's job can be.

"You know how dangerous some of the communities where these police officers serve are. And you pretend as if there's no context?"

Obama also challenged a mostly-white police force and white Americans at large to admit that while the edifice of legalised racism had gone, prejudice remained.

"We have all seen this bigotry in our own lives at some point," he said.

"We've heard it at times in our own homes. If we're honest, perhaps we've heard prejudice in our own heads and felt it in our own hearts."

OPINION: Structural racism in the US won't diminish with time

Obama also made a call for Republicans to realise the cost of their opposition to gun control and spending on mental health and drug treatment.

"We allow poverty to fester so that entire neighbourhoods offer no prospect for gainful employment," Obama said, pointing to a string of causes for violence.

"We refuse to fund drug treatment and mental health programmes. We flood communities with so many guns that it is easier for a teenager to buy a Glock than get his hands on a computer or even a book.”

Following the service, Obama spent more than an hour with families of the officers killed and wounded.

Source: Al Jazeera and agencies