La funzionalità di traduzione vocale utilizza l'AI per interpretare la lingua, consentendo conversazioni tra persone e sistemi che parlano lingue diverse. La tua applicazione può utilizzare questa funzionalità per elaborare un flusso audio contenente un discorso in una lingua e tradurlo in un'altra lingua in tempo reale.
A differenza di altre funzionalità dell'API Live che supportano conversazioni a turni, la traduzione da voce a voce elabora continuamente l'input audio e trasmette i seguenti output man mano che diventano disponibili:
- Trascrizione:il testo riconosciuto dal flusso audio di input nella lingua originale.
- Traduzione:il testo tradotto nella lingua di destinazione.
- Audio sintetizzato: un flusso audio del testo tradotto parlato nella lingua di destinazione che corrisponde alla voce dell'oratore originale.
Modelli supportati
Puoi utilizzare la traduzione vocale con il seguente modello:
| Versione del modello | Livello di disponibilità |
|---|---|
gemini-2.5-flash-s2st-exp-11-2025 |
Privato sperimentale |
Requisiti per l'audio di input
La traduzione vocale supporta solo l'input audio. Per informazioni su formati audio, codec e specifiche supportati, come la frequenza di campionamento, consulta Formati audio supportati.
Utilizzare la traduzione vocale
Per utilizzare la traduzione vocale, vedi i seguenti esempi di codice:
Python
# Set language_code to your desired language, in this case, Mandarin Chinese. speech_config = SpeechConfig(language_code="cmn") config = LiveConnectConfig( response_modalities=["AUDIO"], speech_config=speech_config, input_audio_transcription=input_transcription, output_audio_transcription=output_transcription, ) audio_file = Part.from_uri(file_uri=audio_url, mime_type="audio/mpeg") contents = [audio_file] response = client.models.generate_content(model=MODEL_ID, contents=contents) display(Markdown(response.text))
Python
import asyncio # Set model generation_config CONFIG = { "response_modalities": ["AUDIO"], "speech_config": { "language_code": "cmn", }, } headers = { "Content-Type": "application/json", "Authorization": f"Bearer {bearer_token[0]}", } # Connect to the server async with connect(SERVICE_URL, additional_headers=headers) as ws: # Setup the session await ws.send( json.dumps( { "setup": { "model": MODEL, "generation_config": CONFIG, "input_audio_transcription": {}, "output_audio_transcription": {}, "enable_speech_to_speech_translation": True, } } ) ) # Receive setup response raw_response = await ws.recv(decode=False) setup_response = json.loads(raw_response.decode("ascii")) print(setup_response) msg = { "realtime_input": { "audio": { "mime_type": "audio/pcm", "data": base64.b64encode(wav_data).decode('utf-8'), } } } await ws.send(json.dumps(msg)) overall_responses = [] timeout_seconds = 10 # Set timeout to 3 seconds # Receive chucks of server response with a timeout try: while True: try: raw_response = await asyncio.wait_for(ws.recv(decode=False), timeout_seconds) response = json.loads(raw_response.decode()) server_content = response.pop("serverContent", None) if server_content is None: break # Input Transcription. input_transcription = server_content.pop("inputTranscription", None) if input_transcription is not None: raw_text = input_transcription.pop("text", None) if raw_text is not None: display(Markdown(f"**Input >** {raw_text}")) # Output Transcription. output_transcription = server_content.pop("outputTranscription", None) if output_transcription is not None: raw_text = output_transcription.pop("text", None) if raw_text is not None: display(Markdown(f"**Response >** {raw_text}")) model_turn = server_content.pop("modelTurn", None) if model_turn is not None: parts = model_turn.pop("parts", None) if parts is not None: for part in parts: pcm_data = base64.b64decode(part["inlineData"]["data"]) overall_responses.append(np.frombuffer(pcm_data, dtype=np.int16)) # End of turn # turn_complete = server_content.pop("turnComplete", None) # if turn_complete: # break except asyncio.TimeoutError: print(f"Timeout: No response received from the websocket within {timeout_seconds} seconds.") if overall_responses: display(Audio(np.concatenate(overall_responses), rate=24000, autoplay=True)) break # Exit the loop on timeout except websockets.exceptions.ConnectionClosed as e: print(f"Connection closed by exception, code: {e.code}, reason: {e.reason}") if overall_responses: display(Audio(np.concatenate(overall_responses), rate=24000, autoplay=True)) break # Exit the loop on connection closed except Exception as e: print(f"An unexpected error occurred: {e}") if overall_responses: display(Audio(np.concatenate(overall_responses), rate=24000, autoplay=True)) break # Exit the loop on other exceptions finally: try: await ws.close(code=1000, reason="Normal closure") #example close except websockets.exceptions.ConnectionClosed as e: print(f"Connection closed by exception, code: {e.code}, reason: {e.reason}") except Exception as e: print(f"An unexpected error occurred: {e}")
Lingue supportate
| Codice lingua | Lingua |
|---|---|
| aa | Afar |
| ab | Abcaso |
| ace | Achinese |
| ach | acoli |
| af | Afrikaans |
| ak | Akan |
| alz | Alur |
| am | Amarico |
| un’ | Aragonese |
| ar | Arabo |
| come | Assamese |
| av | Avaric |
| awa | Awadhi |
| ay | Aymara |
| az | Azero |
| ba | Bashkir |
| bal | Beluci |
| ban | Balinese |
| bbc | Batak toba |
| bci | Baulé |
| be | Bielorusso |
| bem | Bemba |
| ber | Berbero |
| bew | Betawi |
| bg | Bulgaro |
| bgc | Haryanvi |
| bho | Bhojpuri |
| bi | Bislama |
| bm | Bambara |
| bn | Bengali |
| bo | Tibetano |
| br | Bretone |
| bs | Bosniaco |
| bts | Batak simalungun |
| btx | Batak karo |
| ca | Catalano |
| ce | Ceceno |
| ceb | Cebuano |
| cgg | Chiga |
| ch | Chamorro |
| chk | Chuukese |
| cmn | Cinese mandarino |
| cnh | Hakha Chin |
| co | Corso |
| cr | Cree |
| crh | Tataro di Crimea |
| crs | Creolo delle Seychelles |
| cs | Ceco |
| cv | Chuvash |
| cy | Gallese |
| da | Danese |
| de | Tedesco |
| din | Dinka |
| doi | Dogri |
| dov | Dombe |
| dv | Divehi |
| dyu | Dyula |
| dz | Dzongkha |
| ee | Ewe |
| el | Greco |
| it | Inglese |
| eo | Esperanto |
| es | Spagnolo |
| et | Estone |
| eu | Basco |
| fa | Farsi |
| ff | Fulah |
| fi | Finlandese |
| fil | Filippino |
| fj | Figiano |
| fo | Faroese |
| fon | Fon |
| fr | Francese |
| pelliccia | Friulano |
| fy | Frisone occidentale |
| ga | Irlandese |
| gaa | Ga |
| gd | Gaelico |
| gl | Galiziano |
| gn | Guarani |
| gu | Gujarati |
| gv | Manx |
| ha | Hausa |
| haw | Hawaiano |
| he | Ebraico |
| ciao | Hindi |
| hil | Hiligaynon |
| hmn | Hmong |
| ho | Hiri Motu |
| h | Croato |
| hrx | Hunsrik |
| ht | Haitiano, creolo haitiano |
| hu | Ungherese |
| hy | Armeno |
| hz | Herero |
| iba | Iban |
| id | Indonesiano |
| ig | Igbo |
| ilo | Ilocano |
| is | Islandese |
| che li ricevano. | Italiano |
| iu | Inuktitut |
| ja | Giapponese |
| Jam | Creolo inglese giamaicano |
| jv | Giavanese |
| ka | Georgiano |
| kac | Kachin |
| kek | Kekchi |
| kg | Kongo |
| kha | Khasi |
| ki | Kikuyu |
| kj | Kuanyama |
| kk | Kazako |
| kl | Groenlandese |
| km | Khmer centrale |
| kn | Kannada |
| ko | Coreano |
| kok | Konkani |
| kr | Kanuri |
| kri | Krio |
| ks | Kashmiri |
| ktu | Kituba |
| ku | Curdo |
| kv | Komi |
| kw | Cornico |
| ky | Kirgizo |
| la | Latino |
| lb | Lussemburghese |
| lg | ganda |
| li | Limburghese |
| lij | Ligure |
| lmo | Lombardo |
| ln | Lingala |
| lo | Lao |
| lt | Lituano |
| lu | Luba-Katanga |
| lua | luba-lulua |
| luo | Dholuo |
| lus | Mizo |
| lv | Lettone |
| pazzia | Madurese |
| mai | Maithili |
| mak | Makasar |
| mam | Mam |
| mfe | creolo mauriziano |
| mg | Malgascio |
| mh | Marshallese |
| min | Minangkabau |
| mk | Macedone |
| ml | Malayalam |
| mn | Mongolo |
| mr | Marathi |
| ms | Malese |
| mt | Maltese |
| mwr | Marwari |
| my | Birmano |
| na | Nauru |
| nb | norvegese bokmal |
| ° | Ndebele del nord |
| ndc | Ndau |
| ne | Nepalese |
| novità | Newari |
| ng | Ndonga |
| nhe | Nahuatl, Huasteca orientale |
| nl | Olandese |
| nn | Norvegese (Nynorsk) |
| nr | Ndebele del sud |
| nso | Pedi |
| nus | Nuer |
| nv | Navajo |
| ny | Chewa |
| oc | Occitano |
| oj | Ojibwa |
| om | Oromo |
| o | Oriya |
| os | Osseto |
| pa | Punjabi |
| pag | Pangasinan |
| pam | Pampanga |
| pap | Papiamento |
| pl | Polacco |
| ps | Pashto |
| pt | Portoghese |
| qu | Quechua |
| rm | Romancio |
| rn | Rundi |
| ro | Rumeno |
| ru | Russo |
| rw | Kinyarwanda |
| sa | Sanscrito |
| sah | Yakut |
| sab | Santali |
| sc | Sardo |
| scn | Siciliano |
| sd | Sindhi |
| se | Lingua sami settentrionale |
| sg | Sango |
| shn | Shan |
| si | Singalese |
| sk | Slovacco |
| sl | Sloveno |
| sm | Samoano |
| sn | Shona |
| so | Somalo |
| sq | Albanese |
| sr | Serbo |
| ss | Swati |
| st | Sotho del sud |
| su | Sundanese |
| sv | Svedese |
| sw | Swahili |
| szl | Slesiano |
| ta | Tamil |
| tcy | Tulu |
| te | Telugu |
| tet | Tetum |
| tg | Tagico |
| th | Tailandese |
| ti | Tigrinya |
| tiv | Tiv |
| tk | Turkmeno |
| tl | Tagalog |
| tn | Tswana |
| a | Tonga |
| tpi | Tok pisin |
| tr | Turco |
| trp | Kok Borok |
| ts | Tsonga |
| tt | Tataro |
| tum | Tumbuka |
| tw | Twi |
| ty | Tahitiano |
| tyv | Tuvano |
| udm | Udmurto |
| ug | Uighur |
| uk | Ucraino |
| ur | Urdu |
| uz | Uzbeco |
| ve | Venda |
| vec | Veneziano |
| vi | Vietnamita |
| wa | Vallone |
| guerra | Waray |
| wo | Wolof |
| xh | Xhosa |
| yi | Yiddish |
| yo | Yoruba |
| yua | Maya yucateco |
| yue | Cantonese |
| za | Zhuang |
| zh | Cinese |
| zu | Zulu |
Fatturazione
In quanto funzionalità sperimentale, non ti verrà addebitato alcun costo per l'utilizzo della traduzione vocale.
Per saperne di più su prezzi e fatturazione, consulta la pagina Prezzi di Vertex AI.