Analyzing speech to detect cognitive impairment associated with dementia and mental illness