This question already has answers here:
How to join 2 or more .WAV files together programmatically?
(5 answers)
Closed 9 years ago.
I am working on Regional Language Text to Voice converter in C#. I have wav files for individual characters.
I want to merge them to get a resultant word's single WAV file.
Im using NAudio library. It supports the concatenate method which takes outputFile and IEnumerable string sourceFiles as arguments.
But when I execute the method I get NullArgumentException in the line which creates WavFileReader object.
But I have a passed a string of array containing filepaths and an existing empty output wavfile as arguments. I am stuck here.
Could you please suggest me how to use this method,as in how to call this method? and what arguments to use...
There is no Concatenate method in NAudio. I assume you are referring to my answer here. The output WAV file should not already exist - it will be created for you. But the most common cause for an ArgumentNull exception is a null parameter being passed into the function. Are you completely sure your source files array does not contain a null. (adding the stack trace of the exception to your question might help us diagnose further).
Related
This question already has an answer here:
Read each line in file and put each line into a string
(1 answer)
Closed 5 years ago.
I need to make something that can get a specific line number and get the information in it into a String. And I couldn't figure out how I can do that.
Does anybody have a sample code/example that solves this problem?
Use File.ReadAllText (or Lines it might be) and then split the text by newline into an array of strings.
Then you can index into that array.
This question already has answers here:
How to read an entire file to a string using C#?
(17 answers)
Closed 5 years ago.
So I have this .json file: temp_file.json
Now all I need to do is get whatever is in this .json file, and put it in a string using C# in Visual Studio 2017.
That's it.
I don't want it to be turned into a object of a certain class or whatever. Just get whatsever in the file, right into a string.
A lot of other questions/answers I have stumbled upon are about desirializing and serializing etc. I don't need that. Just turn the .json file in to a string. No need to write it to a console or whatsoever.
Somewhy I just cant lay my finger on it. It sounds simple to do...
You dont get any simpler than
var contents = File.ReadAllText(#"drive:\path\to\yourfile.json");
This question already has answers here:
Should log file streams be opened/closed on each write or kept open during a desktop application's lifetime?
(13 answers)
Closed 6 years ago.
i need to write data into a CSV file each 600 msec using a c# application . The question: is better open and close file each time or keep it open until the end of write data actions? Note: i will change file name each day and each 60000 record
Thanck a lot for your opinions
CSV files are really easy to write to. If you don't know how to write to a file, the dotnetperls is your friend. You can simply call BinaryWriter.Write() to write anything. Write a value then a comma. That's it! If this file is going to be edited by the user at the time of running the application, then don't keep it open. Otherwise, keeping it open makes sure nothing unexpected happens.
This question already has answers here:
How to insert characters to a file using C#
(10 answers)
Closed 7 years ago.
I'm wondering if there is a way to write data from the program to a specific line on an external text document.
For example, so far within my program I have a string array which gets the users input and saves it in the corresponding element and into the text file. It can read the first element fine, however how do I get it so when I enter the input for element 2 it overwrites what is on line 2 so when it reads the text file it displays the newest input into a label?
Well, the simplest approach would be:
string[] lines = File.ReadAllLines(path);
lines[index] = newText;
File.WriteAllLines(path, lines);
However, that assumes that there's already an appropriate number of lines in the file - is that always the case?
Note that this is also potentially inefficient in memory if the file is very large - but making it more efficient would also make the code more complicated.
This question already has answers here:
Read last line of text file
(6 answers)
Closed 8 years ago.
Scenario is the following:
A (weather) service dumps sensor data into a log file/text file.
The new readings are appended to the bottom of a given (existing) file
New data is added at regular intervals (interval may or may not be known)
I need to parse the new information/line and send it off to another service.
I don't want to read the whole file every time, unless I have to.
EDIT: Sorry for the bad wording. "unless I have to" should be understood as if there is no other way around. I have seen the post/answer referenced and it seems a little extensive.
Framework is 4.5.x.
Thank you.
To get the the last line of a text file you can use this
File.ReadLines(myFileName).Last();
This is the simplest method, but is inefficient. You can write your own parser as show here