|
| 1 | +# TensorStack.Audio.Windows |
| 2 | +`TensorStack.Audio.Windows` provides Windows-specific support for reading and writing audio using FFmpeg. It allows loading audio information, reading and writing audio tensors, and muxing audio into video files. |
| 3 | + |
| 4 | +--- |
| 5 | + |
| 6 | +## AudioInput |
| 7 | +`AudioInput` wraps an audio file into a convenient object backed by an `AudioTensor`. It allows loading, manipulating, and saving audio. |
| 8 | + |
| 9 | +```csharp |
| 10 | +// Load Audio |
| 11 | +
|
| 12 | +AudioInput audioInput = new AudioInput("speech.wav"); |
| 13 | + |
| 14 | +AudioInput audioInputAsync = await AudioInput.CreateAsync("speech.wav"); |
| 15 | + |
| 16 | + |
| 17 | +// With custom codec, sample rate, and channels |
| 18 | +
|
| 19 | +AudioInput audioInput = new AudioInput("music.mp3", "pcm_f32le", 44100, 2); |
| 20 | + |
| 21 | +AudioInput audioInputAsync = await AudioInput.CreateAsync("music.mp3", "pcm_f32le", 44100, 2); |
| 22 | + |
| 23 | + |
| 24 | +// Save Audio |
| 25 | +
|
| 26 | +audioInput.Save("output.wav"); |
| 27 | + |
| 28 | +await audioInput.SaveAsync("output.wav"); |
| 29 | +``` |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +## Notes |
| 34 | + |
| 35 | +* `AudioInput` uses `AudioManager` internally to handle the audio tensor. |
| 36 | +* `AudioManager.Initialize` only needed for custom FFmpeg/FFprobe binaries or a different temp directory; the NuGet package provides defaults. |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +# AudioManager |
| 41 | +`AudioManager` is a static helper class for loading, saving, and processing audio files. It can read audio into tensors, write tensors back to audio files, extract audio from videos, and add audio to videos. It uses FFmpeg/FFprobe under the hood and provides both synchronous and asynchronous methods. |
| 42 | + |
| 43 | +## Load Audio Information |
| 44 | +```csharp |
| 45 | +AudioInfo info = AudioManager.LoadInfo("file.wav"); |
| 46 | + |
| 47 | +AudioInfo info = await AudioManager.LoadInfoAsync("file.wav"); |
| 48 | +``` |
| 49 | + |
| 50 | +Returns metadata including codec, sample rate, channels, duration, and sample count. |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## Load Audio Tensor |
| 55 | +```csharp |
| 56 | +AudioTensor tensor = AudioManager.LoadTensor("file.wav", "pcm_s16le", 16000, 1); |
| 57 | + |
| 58 | +AudioTensor tensor = await AudioManager.LoadTensorAsync("file.wav", "pcm_s16le", 16000, 1); |
| 59 | +``` |
| 60 | + |
| 61 | +`AudioTensor` contains the raw audio samples in float32 format. |
| 62 | + |
| 63 | +--- |
| 64 | + |
| 65 | +## Save Audio Tensor |
| 66 | +```csharp |
| 67 | +AudioManager.SaveAudio("output.wav", tensor); |
| 68 | + |
| 69 | +await AudioManager.SaveAudioAync("output.wav", tensor); |
| 70 | +``` |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Add Audio to Video |
| 75 | +```csharp |
| 76 | +AudioManager.AddAudio("video.mp4", "sourceAudio.mp3"); |
| 77 | + |
| 78 | +await AudioManager.AddAudioAsync("video.mp4", "sourceAudio.mp3"); |
| 79 | +``` |
| 80 | + |
| 81 | +This muxes the audio from the source file into the target video. |
| 82 | + |
| 83 | +--- |
| 84 | +## Initialization |
| 85 | + |
| 86 | +The NuGet package supplies FFmpeg binaries. Initialization is only needed if you want to use custom binaries or a different location: |
| 87 | + |
| 88 | +```csharp |
| 89 | +AudioManager.Initialize("ffmpeg.exe", "ffprobe.exe", "Temp"); |
| 90 | +``` |
| 91 | + |
| 92 | +This sets up the executable paths and temporary directory used for conversions. |
| 93 | + |
| 94 | +--- |
| 95 | +## Notes |
| 96 | + |
| 97 | +* All audio I/O uses FFmpeg under the hood. |
| 98 | +* Asynchronous methods use `Task` and support cancellation. |
| 99 | +* Audio data is handled in `float32` format internally. |
| 100 | + |
| 101 | +--- |
0 commit comments