Samples/Audio/AudioRendering.py

Samples/Audio/AudioRendering.py
1 # Copyright 2011 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Script description:
7 # Demonstrate audio render to export a wav file from MotionBuilder, and various options to set.
8 #
9 # Topic: FBAudioRenderOptions, FBApplication().AudioRender
10 #
11 from pyfbsdk import *
12 import os
13 import tempfile
14 
15 gSystem = FBSystem()
16 
17 # Load sample audio clip to scene
18 lAudioSampleFile = os.path.join( gSystem.ApplicationPath, "../../OpenRealitySDK/Scenes/English.wav" )
19 lAudio = FBAudioClip( lAudioSampleFile )
20 
21 # Instance a FBAudioRenderOptions (Default input parameter values are 2 channels, 16 bits, 44100 Hz)
22 lAudioRenderOptions = FBAudioRenderOptions()
23 
24 # Set the TimeSpan for the audio render to begin and end.
25 lAudioRenderOptions.TimeSpan = gSystem.CurrentTake.LocalTimeSpan
26 
27 # Set Channel mode, Mono or Stereo. Stereo default.
28 lAudioRenderOptions.ChannelMode = FBAudioChannelMode.kFBAudioChannelModeStereo
29 
30 # Set Bit Depth mode, 8 bits and 16 bits available, 16 bits default.
31 lAudioRenderOptions.BitDepthMode = FBAudioBitDepthMode.kFBAudioBitDepthMode_16
32 
33 #Set Rate mode, 44100 Hz default,8000,11025,12000,16000,22050,24000,32000,44100,48000,64000,88200,96000 available.
34 lAudioRenderOptions.RateMode = FBAudioRateMode.kFBAudioRateMode_44100
35 
36 # Set Output file name. If file exists, it will be overwritten; if file is currently being opened by other application, export may fail.
37 lAudioRenderOptions.OutputFileName = os.path.join( tempfile.gettempdir(), "Output.wav" )
38 
39 # Render the wave file with the options specified.
40 if FBApplication().AudioRender(lAudioRenderOptions):
41  print "File successfully saved to %s" % lAudioRenderOptions.OutputFileName
42 else:
43  print "Failed to save file: %s" % lAudioRenderOptions.OutputFileName