Ich versuche, die Lautstärke von Sound-Bytes [] in C# zu ändern. Ich lese eine Audiodatei mit FFMPEG und möchte die Lautstärke im laufenden Betrieb ändern. Ich habe ein paar Beispiele gefunden, aber ich habe sie nicht verstanden.C# Wie stelle ich die Lautstärke von Sound-Bytes ein []
public void SendAudio(string pathOrUrl)
{
cancelVid = false;
isPlaying = true;
mProcess = Process.Start(new ProcessStartInfo
{ // FFmpeg requireqs us to spawn a process and hook into its stdout, so we will create a Process
FileName = "ffmpeg",
Arguments = "-i " + (char)34 + pathOrUrl + (char)34 + // Here we provide a list of arguments to feed into FFmpeg. -i means the location of the file/URL it will read from
" -f s16le -ar 48000 -ac 2 pipe:1", // Next, we tell it to output 16-bit 48000Hz PCM, over 2 channels, to stdout.
UseShellExecute = false,
RedirectStandardOutput = true, // Capture the stdout of the process
Verb = "runas"
});
while (!isRunning(mProcess)) { Task.Delay(1000); }
int blockSize = 3840; // The size of bytes to read per frame; 1920 for mono
byte[] buffer = new byte[blockSize];
byte[] gainBuffer = new byte[blockSize];
int byteCount;
while (true && !cancelVid) // Loop forever, so data will always be read
{
byteCount = mProcess.StandardOutput.BaseStream // Access the underlying MemoryStream from the stdout of FFmpeg
.Read(buffer, 0, blockSize); // Read stdout into the buffer
if (byteCount == 0) // FFmpeg did not output anything
break; // Break out of the while(true) loop, since there was nothing to read.
if (cancelVid)
break;
disAudioClient.Send(buffer, 0, byteCount); // Send our data to Discord
}
disAudioClient.Wait(); // Wait for the Voice Client to finish sending data, as ffMPEG may have already finished buffering out a song, and it is unsafe to return now.
isPlaying = false;
Console.Clear();
Console.WriteLine("Done Playing!");
Was hast du nicht verstanden? Hast du versucht, den Code zu debuggen? –
sie konvertieren nur Zeug und erklärten sie überhaupt nicht. – McLucario
@cFrozenDeath Vielen Dank, dass Sie meinen Beitrag per Zufall abgelehnt haben. Nun beantwortet wohl niemand diese Frage. – McLucario