您可以在 Gemini 要求中加入音訊,執行需要理解音訊內容的工作。本頁面說明如何使用Cloud de Confiance 控制台和 Agent Platform API,在 Gemini Enterprise Agent Platform 中,將音訊新增至 Gemini 要求。
支援的模型
下表列出支援音訊理解功能的模型:
| 模型 | 媒體詳細資料 | MIME 類型 |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
如需 Gemini 模型支援的語言清單,請參閱 Google 模型的資訊。如要進一步瞭解如何設計多模態提示詞,請參閱「設計多模態提示詞」。如要直接從行動和網頁應用程式使用 Gemini,請參閱 Firebase AI Logic 用戶端 SDK,適用於 Swift、Android、網頁、Flutter 和 Unity 應用程式。
在要求中加入音訊
您可以在 Gemini 要求中加入音訊檔案。
單一音訊
以下說明如何使用音訊檔案生成 Podcast 摘要:
控制台
如要使用 Cloud de Confiance 控制台傳送多模態提示,請按照下列步驟操作:前往 Cloud de Confiance 控制台「Agent Platform」部分的「Agent Studio」頁面。
按一下「建立提示」。
選用步驟:設定模型和參數:
- Model (模型):選取模型。
選用:如要設定進階參數,請按一下「Advanced」(進階),然後按照下列步驟操作:
按一下即可展開進階設定
Top-K:使用滑桿或文字方塊輸入 Top-K 值。
「Top-K」會影響模型選取輸出符記的方式。如果 Top-K 設為
1,代表下一個所選詞元是模型詞彙表的所有詞元中可能性最高者 (也稱為「貪婪解碼」)。如果 Top-K 設為3,則代表模型會依據 temperature,從可能性最高的 3 個詞元中選取下一個詞元。在每個符記選取步驟中,模型會對機率最高的「Top-K」符記取樣,接著進一步根據「Top-P」篩選詞元,最後依 temperature 選出最終詞元。
如要取得較不隨機的回覆,請指定較低的值;如要取得較隨機的回覆,請調高此值。
- Top-P:使用滑桿或文字方塊輸入 Top-P 值。
模型會按照可能性最高到最低的順序選取詞元,直到所選詞元的可能性總和等於 Top-P 值。如要讓結果的變化性降到最低,請將 Top-P 設為
0。 - Max responses (回覆數量上限):使用滑桿或文字方塊,輸入要生成的回覆數量。
- 串流回覆:啟用後,系統會顯示正在生成的回覆。
- 安全篩選器門檻:選取看見可能有害回應的機率門檻。
- 啟用建立基準:多模態提示不支援建立基準。
- Region (區域):選取要使用的區域。
- 溫度:使用滑桿或文字方塊輸入溫度值。
The temperature is used for sampling during response generation, which occurs whentopPandtopKare applied. Temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a less open-ended or creative response, while higher temperatures can lead to more diverse or creative results. A temperature of0means that the highest probability tokens are always selected. In this case, responses for a given prompt are mostly deterministic, but a small amount of variation is still possible.If the model returns a response that's too generic, too short, or the model gives a fallback response, try increasing the temperature. If the model enters infinite generation, increasing the temperature to at least
0.1may lead to improved results.1.0is the recommended starting value for temperature. </li> <li>**Output token limit**: Use the slider or textbox to enter a value for the max output limit. <p>Maximum number of tokens that can be generated in the response. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words.</p> <p>Specify a lower value for shorter responses and a higher value for potentially longer responses.</p></li> <li>**Add stop sequence**: Optional. Enter a stop sequence, which is a series of characters that includes spaces. If the model encounters a stop sequence, the response generation stops. The stop sequence isn't included in the response, and you can add up to five stop sequences.</li> </ul>
按一下「插入媒體」,然後選取檔案來源。
上傳
選取要上傳的檔案,然後按一下「開啟」。
使用網址上傳
輸入要使用的檔案網址,然後按一下「插入」。
Cloud Storage
依序選取 bucket 和要匯入的檔案,然後按一下「Select」(選取)。
Google 雲端硬碟
- 首次選取這個選項時,請選擇帳戶並授權 Agent Studio 存取。您可以上傳多個檔案,總大小上限為 10 MB。單一檔案不得超過 7 MB。
- 按一下要新增的檔案。
按一下「選取」。
檔案縮圖會顯示在「提示詞」窗格中。系統也會顯示權杖總數。如果提示資料超出詞元限制,系統會截斷詞元,且不會納入處理資料。
在「Prompt」(提示) 窗格中輸入文字提示詞。
選用:如要查看「Token ID to text」(詞元 ID 轉文字) 和「Token IDs」(詞元 ID),請按一下「Prompt」(提示) 窗格中的「tokens count」(詞元數量)。
按一下「提交」。
選用:如要將提示詞儲存至「我的提示詞」,請依序點選 和「儲存」。
選用:如要取得提示的 Python 程式碼或 curl 指令,請依序點選 「Build with code」>「Get code」。
Python
安裝
pip install --upgrade google-genai
詳情請參閱 SDK 參考文件。
設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True
Go
詳情請參閱 SDK 參考文件。
設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True
Node.js
安裝
npm install @google/genai
詳情請參閱 SDK 參考文件。
設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True
Java
詳情請參閱 SDK 參考文件。
設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True
REST
設定環境後,您可以使用 REST 測試文字提示詞。下列範例會將要求傳送至發布者模型端點。
使用任何要求資料之前,請先修改下列項目的值:
PROJECT_ID:您的專案 ID。。FILE_URI:要加入提示的檔案 URI 或網址。可接受的值包括:- Cloud Storage bucket URI:物件必須可公開讀取,或位於傳送要求的 Cloud de Confiance 專案中。
- HTTP 網址:檔案網址必須可公開讀取。每項要求可指定一個影片檔案、一個音訊檔案和最多 10 個圖片檔。音訊檔案、影片檔案和文件不得超過 15 MB。
- YouTube 影片網址:YouTube 影片必須由您用來登入 Cloud de Confiance 控制台的帳戶擁有,或設為公開。每項要求僅支援一個 YouTube 影片網址。
指定
fileURI時,也必須指定檔案的媒體類型 (mimeType)。如果已啟用 VPC Service Controls,則不支援為fileURI指定媒體檔案網址。如果 Cloud Storage 中沒有音訊檔案,可以使用下列公開檔案:
gs://cloud-samples-data/generative-ai/audio/pixel.mp3,MIME 類型為audio/mp3。如要聆聽這段音訊,請開啟 MP3 範例檔案。MIME_TYPE:fileUri欄位中指定的檔案媒體類型。可接受的值包括:按一下即可展開 MIME 類型
application/pdfaudio/mpegaudio/mp3audio/wavimage/pngimage/jpegimage/webptext/plainvideo/movvideo/mpegvideo/mp4video/mpgvideo/avivideo/wmvvideo/mpegpsvideo/flv
要加入提示的文字指示。例如:TEXT
Please provide a summary for the audio. Provide chapter titles, be concise and short, no need to provide chapter summaries. Do not make up any information that is not part of the audio and do not be verbose.
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
cat > request.json << 'EOF'
{
"contents": {
"role": "USER",
"parts": [
{
"fileData": {
"fileUri": "FILE_URI",
"mimeType": "MIME_TYPE"
}
},
{
"text": "TEXT"
}
]
}
}
EOF接著執行下列指令,傳送 REST 要求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/publishers/google/models/gemini-3.5-flash:generateContent"
PowerShell
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
@'
{
"contents": {
"role": "USER",
"parts": [
{
"fileData": {
"fileUri": "FILE_URI",
"mimeType": "MIME_TYPE"
}
},
{
"text": "TEXT"
}
]
}
}
'@ | Out-File -FilePath request.json -Encoding utf8接著執行下列指令,傳送 REST 要求:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/publishers/google/models/gemini-3.5-flash:generateContent" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆。
請注意這個範例網址中的下列部分:- 使用
generateContent方法,要求在回覆完全生成後傳回。如要減少人類觀眾對延遲時間的感知,請使用streamGenerateContent方法,在生成回覆時串流回覆。 - 多模態模型 ID 位於網址結尾,在方法之前 (例如
gemini-3.5-flash)。這個範例可能也支援其他模型。 - 使用區域 API 端點 (例如
us-central1) 時,系統會根據端點網址中的區域,決定處理要求的位置。系統會忽略資源路徑中任何衝突的位置。
音訊轉錄
以下說明如何使用音訊檔案轉錄訪談內容。如要啟用純音訊檔案的時間戳記理解功能,請在 GenerationConfig 中啟用 audioTimestamp 參數:
控制台
如要使用 Cloud de Confiance 控制台傳送多模態提示,請按照下列步驟操作:前往 Cloud de Confiance 控制台「Agent Platform」部分的「Agent Studio」頁面。
按一下「建立提示」。
選用步驟:設定模型和參數:
- Model (模型):選取模型。
選用:如要設定進階參數,請按一下「Advanced」(進階),然後按照下列步驟操作:
按一下即可展開進階設定
Top-K:使用滑桿或文字方塊輸入 Top-K 值。
「Top-K」會影響模型選取輸出符記的方式。如果 Top-K 設為
1,代表下一個所選詞元是模型詞彙表的所有詞元中可能性最高者 (也稱為「貪婪解碼」)。如果 Top-K 設為3,則代表模型會依據 temperature,從可能性最高的 3 個詞元中選取下一個詞元。在每個符記選取步驟中,模型會對機率最高的「Top-K」符記取樣,接著進一步根據「Top-P」篩選詞元,最後依 temperature 選出最終詞元。
如要取得較不隨機的回覆,請指定較低的值;如要取得較隨機的回覆,請調高此值。
- Top-P:使用滑桿或文字方塊輸入 Top-P 值。
模型會按照可能性最高到最低的順序選取詞元,直到所選詞元的可能性總和等於 Top-P 值。如要讓結果的變化性降到最低,請將 Top-P 設為
0。 - Max responses (回覆數量上限):使用滑桿或文字方塊,輸入要生成的回覆數量。
- 串流回覆:啟用後,系統會顯示正在生成的回覆。
- 安全篩選器門檻:選取看見可能有害回應的機率門檻。
- 啟用建立基準:多模態提示不支援建立基準。
- Region (區域):選取要使用的區域。
- 溫度:使用滑桿或文字方塊輸入溫度值。
The temperature is used for sampling during response generation, which occurs whentopPandtopKare applied. Temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a less open-ended or creative response, while higher temperatures can lead to more diverse or creative results. A temperature of0means that the highest probability tokens are always selected. In this case, responses for a given prompt are mostly deterministic, but a small amount of variation is still possible.If the model returns a response that's too generic, too short, or the model gives a fallback response, try increasing the temperature. If the model enters infinite generation, increasing the temperature to at least
0.1may lead to improved results.1.0is the recommended starting value for temperature. </li> <li>**Output token limit**: Use the slider or textbox to enter a value for the max output limit. <p>Maximum number of tokens that can be generated in the response. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words.</p> <p>Specify a lower value for shorter responses and a higher value for potentially longer responses.</p></li> <li>**Add stop sequence**: Optional. Enter a stop sequence, which is a series of characters that includes spaces. If the model encounters a stop sequence, the response generation stops. The stop sequence isn't included in the response, and you can add up to five stop sequences.</li> </ul>
按一下「插入媒體」,然後選取檔案來源。
上傳
選取要上傳的檔案,然後按一下「開啟」。
使用網址上傳
輸入要使用的檔案網址,然後按一下「插入」。
Cloud Storage
依序選取 bucket 和要匯入的檔案,然後按一下「Select」(選取)。
Google 雲端硬碟
- 首次選取這個選項時,請選擇帳戶並授權 Agent Studio 存取。您可以上傳多個檔案,總大小上限為 10 MB。單一檔案不得超過 7 MB。
- 按一下要新增的檔案。
按一下「選取」。
檔案縮圖會顯示在「提示詞」窗格中。系統也會顯示權杖總數。如果提示資料超出詞元限制,系統會截斷詞元,且不會納入處理資料。
在「Prompt」(提示) 窗格中輸入文字提示詞。
選用:如要查看「Token ID to text」(詞元 ID 轉文字) 和「Token IDs」(詞元 ID),請按一下「Prompt」(提示) 窗格中的「tokens count」(詞元數量)。
按一下「提交」。
選用:如要將提示詞儲存至「我的提示詞」,請依序點選 和「儲存」。
選用:如要取得提示的 Python 程式碼或 curl 指令,請依序點選 「Build with code」>「Get code」。
Python
安裝
pip install --upgrade google-genai
詳情請參閱 SDK 參考文件。
設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True
Go
詳情請參閱 SDK 參考文件。
設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True
Node.js
安裝
npm install @google/genai
詳情請參閱 SDK 參考文件。
設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True
Java
詳情請參閱 SDK 參考文件。
設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True
REST
設定環境後,您可以使用 REST 測試文字提示詞。下列範例會將要求傳送至發布者模型端點。
使用任何要求資料之前,請先修改下列項目的值:
PROJECT_ID:FILE_URI:要加入提示的檔案 URI 或網址。可接受的值包括:- Cloud Storage bucket URI:物件必須可公開讀取,或位於傳送要求的 Cloud de Confiance 專案中。
- HTTP 網址:檔案網址必須可公開讀取。每項要求可指定一個影片檔案、一個音訊檔案和最多 10 個圖片檔。音訊檔案、影片檔案和文件不得超過 15 MB。
- YouTube 影片網址:YouTube 影片必須由您用來登入 Cloud de Confiance 控制台的帳戶擁有,或設為公開。每項要求僅支援一個 YouTube 影片網址。
指定
fileURI時,也必須指定檔案的媒體類型 (mimeType)。如果啟用 VPC Service Controls,則不支援為fileURI指定媒體檔案網址。如果 Cloud Storage 中沒有音訊檔案,可以使用下列公開檔案:
gs://cloud-samples-data/generative-ai/audio/pixel.mp3,MIME 類型為audio/mp3。如要聆聽這段音訊,請開啟 MP3 範例檔案。MIME_TYPE:data或fileUri欄位中指定檔案的媒體類型。可接受的值包括:按一下即可展開 MIME 類型
application/pdfaudio/mpegaudio/mp3audio/wavimage/pngimage/jpegimage/webptext/plainvideo/movvideo/mpegvideo/mp4video/mpgvideo/avivideo/wmvvideo/mpegpsvideo/flv
要加入提示的文字指示。例如:TEXT
Can you transcribe this interview, in the format of timecode, speaker, caption. Use speaker A, speaker B, etc. to identify speakers.
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
cat > request.json << 'EOF'
{
"contents": {
"role": "USER",
"parts": [
{
"fileData": {
"fileUri": "FILE_URI",
"mimeType": "MIME_TYPE"
}
},
{
"text": "TEXT"
}
]
},
"generationConfig": {
"audioTimestamp": true
}
}
EOF接著執行下列指令,傳送 REST 要求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/publishers/google/models/gemini-3.5-flash:generateContent"
PowerShell
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
@'
{
"contents": {
"role": "USER",
"parts": [
{
"fileData": {
"fileUri": "FILE_URI",
"mimeType": "MIME_TYPE"
}
},
{
"text": "TEXT"
}
]
},
"generationConfig": {
"audioTimestamp": true
}
}
'@ | Out-File -FilePath request.json -Encoding utf8接著執行下列指令,傳送 REST 要求:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/publishers/google/models/gemini-3.5-flash:generateContent" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆。
請注意這個範例網址中的下列部分:- 使用
generateContent方法,要求在回覆完全生成後傳回。如要減少人類觀眾對延遲時間的感知,請使用streamGenerateContent方法,在生成回覆時串流回覆。 - 多模態模型 ID 位於網址結尾,在方法之前 (例如
gemini-3.5-flash)。這個範例可能也支援其他模型。 - 使用區域 API 端點 (例如
us-central1) 時,系統會根據端點網址中的區域,決定處理要求的位置。系統會忽略資源路徑中任何衝突的位置。
設定選用模型參數
每個模型都有一組可設定的選用參數。詳情請參閱「內容生成參數」。
限制
雖然多模態版 Gemini 在許多多模態用途中都很強大,但請務必瞭解模型的限制:
- 非語音聲音辨識:支援音訊的模型可能會誤判非語音聲音。
- 純音訊時間戳記:如要為純音訊檔案產生準確的時間戳記,必須在
generation_config中設定audio_timestamp參數。
後續步驟
- 開始使用多模態版 Gemini 建構內容:新客戶可獲得價值 $300 美元的免費 Cloud de Confiance by S3NS 抵免額,探索 Gemini 的功能。
- 瞭解如何傳送即時通訊提示要求。
- 瞭解負責任的 AI 技術最佳做法和 Agent Platform 的安全篩選器。