3.從影片空間化音訊3. Spatializing audio from a video

概觀Overview

在本教學課程中,您將瞭解如何從影片來源 spatialize 音訊,並在 unity 編輯器中測試,並 HoloLens 2。In this tutorial, you will learn how to spatialize audio from an video source and test this in the unity editor and HoloLens 2.

目標Objectives

  • 匯入影片並新增影片播放影片Import a video and add a Video Player
  • 播放影片到四邊形Play the video onto a quadrangle
  • 將音訊從影片路由傳送至四邊形,並 spatialize 音訊Route audio from the video to the quadrangle, and spatialize the audio

匯入影片並將影片播放機新增至場景Import a video and add a Video Player to the Scene

在本教學課程中,您可以使用「空間音訊」範例專案中的 這段影片For this tutorial use You can use this video from the spatial audio sample project.

將影片匯入 unity 專案。To import Video into the unity project. 在 Unity 功能表中,選取 資產 匯 > 入新增 資產匯 ![ 入資產]in the Unity menu select Asset > Import New Asset Importing Asset

在 [匯 入新資產 ] 視窗中,選取您下載的 Microsoft HoloLens 空間音效 PTPvx7mDon4 檔案,然後按一下 [ 開啟 ] 按鈕,將資產匯入至專案中:In the Import New Asset... window, select the Microsoft HoloLens - Spatial Sound-PTPvx7mDon4 file you downloaded and click the Open button to import the asset into the project:

選取資產

調整影片剪輯的品質設定,可確保在 HoloLens 2 上進行順暢的播放。Adjusting the quality settings on the video clip can ensure smooth playback on HoloLens 2. 在 [ 專案 ] 視窗和影片檔案的 [偵測器] 視窗中選取影片檔案,覆 Windows Store 應用程式 的設定,以及:Select the video file in the Project window and in the Inspector window of the video file, override the settings for Windows Store Apps, and:

  • 啟用 轉碼Enable Transcode
  • 編解碼器 設定為 H264Set Codec to H264
  • 位元速率模式 設定為低Set Bitrate Mode to Low
  • 空間品質 設定為中等空間品質Set Spatial Quality to Medium Spatial Quality

進行這些調整之後,請按一下 [套用] 來變更影片剪輯上的品質設定。After these adjustments, click on Apply to change the quality setting on the video clip.

影片屬性變更

以滑鼠右鍵按一下階層,然後選取 [視頻 > 影片播放 影片] 以新增影片播放元件。Right click on the Hierarchy, Select Video > Video Player to add Video player component.

新增影片播放影片

播放影片至四邊形Play video onto a quadrangle

影片播放影片 物件需要有紋理的遊戲物件才能轉譯影片。The Video Player object needs a textured game object to render the video.

以滑鼠右鍵按一下階層,選取 [ 3d 物件 > 個] 以建立四個並設定其 轉換 元件,如下所示:Right click the Hierarchy , Select 3D Object > Quad to create a quad and configure its Transform component as follows:

  • 位置: X = 0、Y = 0、Z = 2Position: X = 0, Y = 0, Z = 2
  • 旋轉:X = 0、Y = 0、Z = 0Rotation: X = 0, Y = 0, Z = 0
  • Scale: X = 1.28、Y = 0.72、Z = 1Scale: X = 1.28, Y = 0.72, Z = 1

新增四個

現在您需要將 段影片的材質材質,請在 [專案] 視窗中,以滑鼠右鍵按一下並選擇 [建立 轉譯 > 材質] 來建立轉譯材質元件、為轉譯紋理輸入適當的名稱,例如,空間音訊材質Now you need to texture the Quad with the video, In the Project window, right-click and choose Create > Render Texture to create a Render Texture component, enter a suitable name to the Render Texture for example, Spatial Audio Texture:

建立呈現材質

選取 [轉譯 材質 ],然後在 [偵測器] 視窗中設定 [ 大小 ] 屬性,以符合影片的1280x720 原生解析度。Select the Render Texture and in the Inspector window set the Size property to match the video's native resolution of 1280x720. 然後,若要確保 HoloLens 2 的良好轉譯效能,請將 [ 深度緩衝區 ] 屬性設定為 至少16個位的深度Then, to ensure good rendering performance on HoloLens 2, set the Depth Buffer property to At least 16 bits depth.

轉譯材質屬性

接下來,使用已建立的轉譯材質 空間音訊紋理 作為 個的材質:Next, use the created Render Texture Spatial Audio Texture as the texture for the Quad:

  1. 將 [ 空間音訊材質 ] 從 [ 專案 ] 視窗拖曳至階層中的 [ 個],以將轉譯紋理新增至 [四]Drag the Spatial Audio Texture from the Project window onto the Quad in the Hierarchy to add the Render Texture to the Quad
  2. 若要確保 HoloLens 2 的良好效能,請選取階層中的 [四],然後在著色器的 [偵測器] 視窗中選取 [混合現實工具 組 > 標準 著色器]To ensure good performance on HoloLens 2, select Quad in the Hierarchy and in the Inspector window for shader select the Mixed Reality Toolkit > Standard Shader.

四材質屬性

若要設定 影片播放 和轉譯 材質 來播放影片剪輯,請選取 階層和偵測****器 視窗中的 影片播放機To set Video Player and Render Texture to play the video clip, select the Video Player in the Hierarchy and in the Inspector window,

  • 影片剪輯 屬性設定為下載的影片檔案 ' Microsoft HoloLens-空間音效-PTPvx7mDon4 'Set the Video Clip property to the downloaded video file 'Microsoft HoloLens - Spatial Sound-PTPvx7mDon4'
  • 核取 [ 迴圈 ] 核取方塊Check the Loop checkbox
  • 目標材質 設定為新的轉譯材質 空間音訊紋理Set Target Texture to your new render texture Spatial Audio Texture

影片播放影片屬性

從影片 Spatialize 音訊Spatialize the audio from the video

在 [階層] 視窗中,選取 [ 個物件],然後在 [偵測器] 視窗中,使用 [ 新增元件 ] 按鈕來新增 音訊來源 ,您將從影片將音訊傳送至該來源。In the Hierarchy window, select Quad object, then in the Inspector window, use the Add Component button to add Audio Source to which you'll route the audio from the video.

音訊來源 中:In the Audio Source:

  • 輸出 設定為 空間音訊混音Set Output to the Spatial Audio Mixer
  • 核取 [ Spatialize ] 方塊Check the Spatialize box
  • 空間 Blend 滑杆移至 1 (3d) Move the Spatial Blend slider to 1 (3D)

四音訊來源檢查

若要設定影片播放影片將其音訊路由傳送到 音訊來源,請在 [階層] 視窗中選取 影片播放機 ,然後在偵測器中的 [影片播放流程] 物件執行下列變更。To set the Video Player to route its audio to the Audio Source, select the Video Player In the Hierarchy window, and in Video Player object in the Inspector do the following changes.

  • 音訊輸出模式 設定為 音訊來源Set the Audio Output Mode to Audio Source
  • 將 [音訊來源] 屬性設定為 []Set the Audio Source property to the Quad

影片播放影片設定音訊來源

提示

如需有關如何建立 Unity 專案並將其部署至 HoloLens 2 的提醒,您可以參閱對您的 HoloLens 2 建置應用程式的指示。For a reminder on how to build and deploy your Unity project to HoloLens 2, you can refer to the Building your app to your HoloLens 2 instructions.

恭喜!Congratulations

在本教學課程中,您已瞭解如何從影片來源 spatialize 音訊,並在 HoloLens 2 或 Unity 編輯器中試用您的應用程式。In this tutorial, you have learned how to spatialize audio from an video source Try out your app on a HoloLens 2 or in the Unity editor. 您將會看到並聆聽影片,而影片中的音訊 hrtf。You'll see and hear the video, and the audio from the video is spatialized.

在下一個教學課程中,您將瞭解如何在執行時間啟用和停用 spatializationIn the next tutorial you will learn how to Enable and disable spatialization at run time