There are several ways to convert thermal energy into electrical energy such as thermal motors on turbines connected to an alternator or a dynamo, Peltier elements (see https://en.wikipedia.org/wiki/Thermoelectric_effect#Peltier_effect). All need two media at different temperatures and the efficiency is limited to a maximum limit which is the ratio of the temperature difference between the two media and the absolute temperature of the warmer medium. So if the colder medium is at absolute zero temperature, the theoretical efficiency could be 100%. n
Today however, the efficiency is not the only criterion on the Earth. Sustainability is of most importance now. When this is taken into account, the most effective, and currently available ways to convert heat into electricity are photovoltaic cells, converting the solar heat transferred to us by radiation into electricity and water turbines using the gravitational energy of water that was primarily evaporated using the solar heat, then condensed into rain and falling on the mountains. Wind mills, in a matter of fact, also convert heat into electricity, since wind results from temperature differences between zones on the Earth.
you can do this by generating heated vapour which enters through a turbine that makes a rotational movement with the blades attached to it, thats is a mechanical energy, after the alternator can convert this mechanical energy into electrical energy that can be distributed through a grid. there is another way is the peltier elements that is noticed before my comment which is interesting. another way is to use the solar pannels that receive solar ( radiative) energy and convert it into electrical energy. i hope my comment is useful.