Mohanapriya R Mohanapriya R
Updated date May 29, 2024
In this article, we will learn how to convert sound into text.

Convert Sound to Strings in C#

This program reads a sound file and converts it into a string representation. See the example below,

using System;
using NAudio.Wave;

class Program
{
    static void Main()
    {
        string filePath = "path/to/your/sound/love_music_file.wav";
        string soundString = ConvertSoundToString(filePath);

        Console.WriteLine("Sound Converted to String:");
        Console.WriteLine(soundString);
    }

    static string ConvertSoundToString(string filePath)
    {
        using (WaveFileReader waveReader = new WaveFileReader(filePath))
        {
            float[] buffer = new float[waveReader.Length];
            waveReader.Read(buffer, 0, buffer.Length);

            // Convert the float array to a string representation
            string soundString = string.Join(", ", buffer);

            return soundString;
        }
    }
}

In this program, we used the NAudio library for handling audio files. The ConvertSoundToString method reads a WAV file, retrieves the audio samples, and converts them into a comma-separated string.

Output:

Sound Converted to String:
0.123, 0.456, -0.789, 0.321, ...

Comments (0)

There are no comments. Be the first to comment!!!