Listen, listen, listen to an accent, and IF you have a good ear, you will gradually learn to imitate it. Unfortunately this does not always come easily. I am 82 and have had contact with all sorts of accents throughout my life, yet lowland Scots is about the only one that I can even approximate to--largely because I love to recite Robert Burns poetry in my bath--that is, besides my native Estuary English. On the other hand, my St. Louis (Missouri) born wife began her married life with me in Trinidad and was no longer recognised as an American, even by her fellow countryman, within three months of arriving there. After we had lived three years in England she was accused by her relatives of sounding more English than I did! I presume there are learned books on dialects and accents, with detailed explanation of their phonetic and other characteristics, and some may come with cassettes: ask at your local public library.
My maternal grandmother was born in Liverpool but felt that even as a domestic servant her job prospects would improve if she "gentrified" her accent and ended up working for royalty! Her husband, however, left his native West Suffolk in his youth and was still speaking broad West Suffolk when he died in greater London in his mid eighties. Inhibitions, prejudice and obstinacy are important constraining factors!