import google.cloud.texttospeech as tts

def text_to_mp3(voice_name: str, text: str, file_name: str):
    language_code = '-'.join(voice_name.split('-')[:2])
    text_input = tts.SynthesisInput(text=text)
    voice_params = tts.VoiceSelectionParams(
        language_code=language_code, name=voice_name
    )
    audio_config = tts.AudioConfig(audio_encoding=tts.AudioEncoding.MP3)

    client = tts.TextToSpeechClient()
    response = client.synthesize_speech(
        input=text_input, voice=voice_params, audio_config=audio_config
    )
    voice_file = file_name + '.mp3'
    with open(voice_file, 'wb') as out:
        out.write(response.audio_content)
