自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
測量音訊延遲時間
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
由於難以使用自訂硬體單獨測量輸入或輸出延遲,因此音訊延遲是透過往返延遲測量,代表輸入和輸出延遲的總和。
做法
測試軟體會自動執行下列步驟:
- 軟體會產生複雜的音調,方法是使用不同長度的短促白噪音,建立容易辨識的結構。
- 裝置的音訊輸出路徑會播放鈴聲。
- 這項測試會將音訊輸出迴路傳回音訊輸入。
- 如果是喇叭和麥克風路徑,由於內建麥克風會錄製內建喇叭播放的聲音,因此不需要額外硬體。
- 類比 3.5 公釐插孔使用自訂的音訊迴路轉接器。
- USB 連接埠可使用 USB 轉 3.5 公釐轉接器搭配迴路轉接器,或是使用 USB 音訊介面,並透過傳輸線將輸出端連接至輸入端。
- 測試軟體會錄製迴路音訊。
- 測試軟體會使用全雙工串流,同步並同時錄製輸出和輸入音訊串流。
下圖顯示測試設定:
圖 1. 測量音訊延遲時間。
往返延遲時間的計算方式是測量輸出和輸入之間的時差,並使用標準化相關演算法找出輸入串流中的輸出音調。
下圖顯示往返延遲時間的計算方式:
圖 2. 計算往返延遲時間。
如要進一步瞭解迴路硬體,請參閱「CTS Verifier 音訊周邊裝置」。
測試應用程式
本節說明測量延遲時間的兩個主要應用程式。兩者都使用相同的技術,預期會產生類似的結果。
OboeTester
OboeTester 是專為 Oboe 程式庫設計的測試套件,提供許多實用測試,包括來回延遲時間測量。
您可以透過下列任一方式取得 OboeTester:
請按照下列步驟,使用 OboeTester 應用程式測量延遲時間:
- 啟動 OboeTester。
- 輕觸「往返延遲時間」。
- 輕觸「測量」。
- 檢查往返延遲時間的
latency.msec
值。
您可以使用持續整合的意圖執行這項測試。
CTS 驗證器
請參閱 CTS Verifier 音訊迴路延遲測試 ,判斷來回延遲是否符合 CDD 要求。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-10 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-10 (世界標準時間)。"],[],[],null,["# Measure audio latency\n\nGiven the difficulty of measuring input or output latency in isolation with custom hardware, audio\nlatency is measured as *round-trip latency*, which represents the combined input and output\nlatency.\n\nTechnique\n---------\n\n\nThe following steps are automated by the test software:\n\n1. The software generates a complex tone using short bursts of white noise of varying lengths, creating an easily recognizable structure.\n2. The device's audio output path plays the tone.\n3. The test loops back the audio output to an audio input.\n - For speaker and microphone paths, no additional hardware is needed as the built-in microphone records the sound played from the built-in speaker.\n - Analog 3.5 mm jacks use a custom [Audio loopback dongle](/docs/core/audio/latency/loopback).\n - USB ports use either a USB to 3.5 mm adapter combined with the loopback dongle or a USB audio interface with cables connecting the output to the input.\n4. The test software records the looped-back audio.\n5. The test software employs a full-duplex stream to synchronize and simultaneously record both the output and input audio streams.\n\nThe following figure shows the test setup:\n\n\n**Figure 1.** Measure audio latency.\n\nRound-trip latency is determined by measuring the time offset between the output and input,\nusing a normalized correlation algorithm to locate the output tone within the input stream.\n\nThe following figure shows how the round-trip latency is calculated:\n\n\n**Figure 2.** Calculate round-trip latency.\n\nSee [CTS Verifier audio peripherals](/docs/compatibility/cts/audio-peripherals) for\nmore information about the loopback hardware.\n\nTest apps\n---------\n\n\nThis section describes two main apps for measuring latency. Both use identical techniques\nand are expected to yield comparable results.\n\n### OboeTester\n\n\nOboeTester, a test suite designed for the Oboe library, offers valuable tests, including round-trip\nlatency measurement.\n\n\nYou can get OboeTester in one of two ways:\n\n- Build the app from source, which can be found on [GitHub](https://github.com/google/oboe/tree/main/apps/OboeTester/docs).\n- Install the app from [Google Play Store](https://play.google.com/store/apps/details?id=com.mobileer.oboetester).\n\n\nFollow these steps to measure the latency on the OboeTester app:\n\n1. Launch OboeTester.\n2. Tap **ROUND TRIP LATENCY**.\n3. Tap **MEASURE**.\n4. Check the `latency.msec` value for the round-trip latency.\n\n\nYou can run this test using an [Intent for Continuous Integration](https://github.com/google/oboe/blob/main/apps/OboeTester/docs/AutomatedTesting.md).\n\n### CTS Verifier\n\n\nSee the CTS Verifier [Audio loopback latency test](/docs/compatibility/cts/audio-loopback-latency)\nto determine if round-trip latency meets CDD requirements."]]