I was working with audio processing but got stuck. I have a video file which first I converted to .wav file. Actually I need to extract only the vocal part. What I did is I am able to remove the vocal part and only the background sound. That means I have two file now one the main file another only the music file i.e. Karoake file. Both the file sample rate is same. What I am planning to do that to compare the file whenever the main file and karoake file at exactly the same time will give zero if both are same. In the process I can extract the vocal parts only. I am new to octave and matlab. I am attaching my till date work.
[wave,fs]=wavread('music.wav');
[wave1,fs1]=wavread('sound.wav');
t=0:1/fs:(length(wave)-1)/fs;
t1=0:1/fs1:(length(wave1)-1)/fs1;
for x=0:length(wave)
if (wave{x}==wave1{x})
wave2{x}=wave{x}-wave1{x};
else
endif
endfor
for loop is showing an error.
EDIT: OK the question I asked was not actually the question. What I want is that to extract the vocal part only of an audio file.
In Matlab (or Octave) you can only index matrix with "()". Moreover the start index in Matlab is 1, not 0 like in C or Java. So I think your code must be correct by:
for x=1:length(wave)
if (wave(x)==wave1(x))
wave2(x)=wave(x)-wave1(x);
end
You can also remove the for instruction by using some arrays multiplications:
wave2 = (wave - wave1).*(wave1==wave);
Related
I'm having trouble visualizing my .wav file
There are total of 5 signals combined together in my .wav file
Lets assume the .wav file is lucky.wav
##My syntax in R
library(tuneR)
library(seewave)
audio_file<-readWave("luckky.wav")
length(sdata)
[1] 3595680
How do i view all the Signals in lucky.wav file?
I've tried length=hdr$nSignals but I got an error.
Please help me in R or in Python. Thank you
What do you mean? you want to see each wave individually? Like if you have a music file you want to see waves from vocal, drum, and piano? If that what you want to do, you cant do that. When you combine 2 signals, the frequency of that 2 signals combined becomes 1 new signal. You can never see the source signal again
I have some .wma file which I am trying to merge into a single one...
I started with python reading files in bytes and writing them into a new one, just as I tried the cmd command copy /b file1.wma + file2.wma + else.wma total.wma
all came up with the same result: my total file was as large in byte as real total of my segments, but when I try to open the file it plays the first segment both in length(time) and content -meaning that I have a 15 MB 10 second voice :-))
I tried to do that with different .wma files but each time it is the first one in length and content and total of them in size.
My assumption is that probably some were my .wma data frame (maybe in file header) there is a data about length of current file, so that after merging the file when the player attempts to play the file reads that data about time and stops after the time. or some like that.
so I need to edit those data frame or header (if even exist) in a way that matches my final output or just simply ignore that.
but I don't know whether it is right or how I can do that
.wma file sample: https://github.com/Fsunroo/PowerPointVoiceExtract (media1.wma and media2.wma for example)
note: there is no such problem with web applications that join songs (maybe they do editing header??!)
Note2: it is a part of my code witch extract voice from a power point file.
I solved the problem by using moviepy.editor
the corrected project is accessible at: https://github.com/Fsunroo/PowerPointVoiceExtract
I'am trying to get lines from a text file (.log) into a .txt document.
I need get into my .txt file the same data. But the line itself is sometimes different. From what I have seen on internet, it's usualy done with a pattern that will anticipate how the line is made.
1525:22Player 11 spawned with userinfo: \team\b\forcepowers\0-5-030310001013001131\ip\46.98.134.211:24806\rate\25000\snaps\40\cg_predictItems\1\char_color_blue\34\char_color_green\34\char_color_red\34\color1\65507\color2\14942463\color3\2949375\color4\2949375\handicap\100\jp\0\model\desann/default\name\Faybell\pbindicator\1\saber1\saber_malgus_broken\saber2\none\sex\male\ja_guid\420D990471FC7EB6B3EEA94045F739B7\teamoverlay\1
The line i'm working with usualy looks like this. The data i'am trying to collect are :
\ip\0.0.0.0
\name\NickName_of_the_player
\ja_guid\420D990471FC7EB6B3EEA94045F739B7
And print these data, inside a .txt file. Here is my current code.
As explained above, i'am unsure about what keyword to use for my research on google. And how this could be called (Because the string isn't the same?)
I have been looking around alot, and most of the test I have done, have allowed me to do some things, but i'am not yet able to do as explained above. So i'am in hope for guidance here :) (Sorry if i'am noobish, I understand alot how it works, I just didn't learned language in school, I mostly do small scripts, and usualy they work fine, this time it's way harder)
def readLog(filename):
with open(filename,'r') as eventLog:
data = eventLog.read()
dataList = data.splitlines()
return dataList
eventLog = readLog('games.log')
You'll need to read the files in "raw" mode rather than as strings. When reading the file from disk, use open(filename,'rb'). To use your example, I ran
text_input = r"1525:22Player 11 spawned with userinfo: \team\b\forcepowers\0-5-030310001013001131\ip\46.98.134.211:24806\rate\25000\snaps\40\cg_predictItems\1\char_color_blue\34\char_color_green\34\char_color_red\34\color1\65507\color2\14942463\color3\2949375\color4\2949375\handicap\100\jp\0\model\desann/default\name\Faybell\pbindicator\1\saber1\saber_malgus_broken\saber2\none\sex\male\ja_guid\420D990471FC7EB6B3EEA94045F739B7\teamoverlay\1"
text_as_array = text_input.split('\\')
You'll need to know which columns contain the strings you care about. For example,
with open('output.dat','w') as fil:
fil.write(text_as_array[6])
You can figure these array positions from the sample string
>>> text_as_array[6]
'46.98.134.211:24806'
>>> text_as_array[34]
'Faybell'
>>> text_as_array[44]
'420D990471FC7EB6B3EEA94045F739B7'
If the column positions are not consistent but the key-value pairs are always adjacent, we can leverage that
>>> text_as_array.index("ip")
5
>>> text_as_array[text_as_array.index("ip")+1]
'46.98.134.211:24806'
I'm trying to read in a file
the text file itself is laid out in 9 columns with tons of data (454 lines total)
I'm trying to read in and retrieve certain columns of data so I can plot a diagram of the mass related to temperature (an HR diagram)
however when I try to load the text using:
file = 'nameoftext.txt' #the file itself is saved as a txt from notepad++
track1 = np.loadtext(file, skiprows=70) #im skipping 70 rows of headers to the data (and np is numpy)
I get an error saying:
ValueError: could not convert string to float: 'iso'
I have no idea what this means or what I'm doing.
I'm also using np.loadtext because that's the only way my professor showed us how to load files and I have no idea how else to do it.
another option for loading .txt files in the python is the genfromtxt() function also in numpy. In this function the object type of values in each column can be specified or you can allow the function to guess the type on its own.
Check out the link below for a similar question.
Loading text file containing both float and string using numpy.loadtxt
I am looking for a way that I can combine multiple wave files into one wave file using python and run it on linux. I don't want to use any add on other than the default shell command line and default python modules.
For example, if I have a.wav and b.wav. I want to create a c.wav which start with the content from a.wav then b.wav.
I've found wave module, that I can open a wave file and write into a new file. Since i'm really new in this audio world. I still can't figure out how to do it. Below is my code
import struct, wave
waveFileA = wave.open('./a.wav', 'r')
waveFileB = wave.open('./b.wav', 'r')
waveFileC = wave.open('./c.wav', 'w')
lengthA = waveFileA.getnframes()
for i in range(0,lengthA):
waveFileC.writeframes(waveFileA.readframes(1))
lengthB = waveFileB.getnframes()
for i in range(0,lengthB):
waveFileC.writeframes(waveFileB.readframes(1))
waveFileA.close()
waveFileB.close()
waveFileC.close()
When i run this code, I got this error:
wave.Error: # channels not specified
Please can any one help me?
You need to set the number of channels, sample width, and frame rate:
waveFileC.setnchannels(waveFileA.getnchannels())
waveFileC.setsampwidth(waveFileA.getsampwidth())
waveFileC.setframerate(waveFileA.getframerate())
If you want to handle a.wav and b.wav having different settings, you'll want to use something like pysox to convert them to the same settings, or for nchannels and sampwidth you may be able to tough through it yourself.
Looks like you need to call n=waveFileA.getnchannels() to find out how many channels the first input file uses, likewise for waveFileB, then you'll need to use waveFileC.setnchannels(n) to tell it how many channels to put in the outgoing file. I don't know how it will handle input files with different numbers of channels...
Here is the answer I am looking for
How to join two wav files using python?
(look for a thread by Tom 10)
It's in another thread. some one already solved this problem.