If you have never been through a miscarriage or pregnancy loss yourself, or even if you have, it can be hard to know what to say when someone you know loses a baby. You want to say something, but you just don't know what.
In short, the best thing to say is anything along the lines of "I'm sorry, and I'm here for you if you want to talk about it." It's also a good idea to offer help to your friend if she needs it, and ideally to offer something specific, since it can be hard for people to ask for help even when they need it.
As for talking about the miscarriage, your friend may or may not want to. Some women don't want to talk and may withdraw from friends and family, preferring solitude. If your friend or relative is doing this, it may be her way of coping. Let your friend have her space, and don't try to force her to talk before she's ready. Consider sending a card or flowers to let her know you're thinking of her. You might offer to bring dinner over so she doesn't have to cook or, if she has other children, offer to watch them for a while so she can have some alone time.
If your friend does want to talk, try to keep an open ear. Don't discourage your friend from talking, because it may be therapeutic for her. Consider asking questions like, "How do you feel?" in order to encourage her to open up.
In most cases, you should avoid offering advice unless asked. If you yourself have had experience with miscarriage, your friend might be interested in hearing about your experience but approach the subject with caution. If your miscarriage happened a while ago, remember that the feelings of grief can be very intense in the beginning and your outlook on the experience may be very different from your friend's. Remember also that every person goes through the experience differently, so you do not necessarily know what your friend is feeling (and your friend does not necessarily know what you felt when it happened to you.)
Try to remember that your friend or relative has lost a child, and be sensitive to that fact. Don't minimize the loss. She had probably started to envision her child in her mind and likely feels that she lost a baby, not just a pregnancy. It may be a while before she feels like herself again.
If you feel uncomfortable and awkward, just do your best. Try to be there for your friend as best as you can. She will most likely be reeling and in shock for a while, but years from now she will look back on this time and remember your support.