You can use GetCrime and GetCrimeKnown to determine whether or not specific actors know about a crime committed by the player. That only tells you if they know about
any crime the player may have committed that falls under one of the crime types, and only in relation to a specific actor, it doesn't give you a specific crime.
You would have to ref walk cells for actors that detect the player, check to see if any of the player's misc stats have increased (GetPCMiscStat on assaults, murders, etc.), and check to see if they now know about specific crimes that they didn't know about a minute ago and if it was the player that committed them. That's at least part of what you'd need to determine whether or not the actor was a witness.
You'd also have to compare the player's previous bounty to their new bounty after a crime has been committed and deduct it if the witness is killed.
I'm sure it's a lot more complicated than this, but that's all I could come up with off the top of my head. This is actually a feature I've been planning for Balzu but haven't gotten around to implementing yet. I think Kuertee or Reneer has implemented something like this already, so I would check out their mods and see how they did it.
hth