I just started programming and I'm trying to get python to read a txt file and then turn the letters in the file into notes with certain frequencies, and then create a wav file. I'm doing ok but could really use some help. Thank you in advance. This is what I have:
noteFileName=raw_input("What file are the notes in?")
noteFile=open(noteFileName,'r')
song=[]
for line in noteFile:
print line
tone=[10000*sin(i*freq*2*pi/44100) for i in range(int(1.0*44100))]
if line[0]=="A":
freq=440.00
elif line[0]=="B":
freq=493.88
elif line[0]=="C":
freq=261.63
elif line[0]=="D":
freq=293.66
elif line[0]=="E":
freq=329.63
elif line[0]=="F":
freq=349.23
elif line[0]=="G":
freq=392.00
elif line[0]=="R":
freq=0.00
elif line[0]=="c":
freq=523.25
elif line[0]=="d":
freq=587.33
elif line[0]=="e":
freq 659.26
song=song=tone
outputWAV=makewave("notes.wav",44100)
for sample in song:
outputWAV.record(sample,0)
outputWAV.close()
I keep getting an error after the last .26 frequency.
1 1021 bvdet 2,851
Recognized Expert Moderator Specialist
I just started programming and I'm trying to get python to read a txt file and then turn the letters in the file into notes with certain frequencies, and then create a wav file. I'm doing ok but could really use some help. Thank you in advance. This is what I have: -
noteFileName=raw_input("What file are the notes in?")
-
noteFile=open(noteFileName,'r')
-
-
song=[]
-
for line in noteFile:
-
print line
-
tone=[10000*sin(i*freq*2*pi/44100) for i in range(int(1.0*44100))]
-
-
if line[0]=="A":
-
freq=440.00
-
elif line[0]=="B":
-
freq=493.88
-
elif line[0]=="C":
-
freq=261.63
-
elif line[0]=="D":
-
freq=293.66
-
elif line[0]=="E":
-
freq=329.63
-
elif line[0]=="F":
-
freq=349.23
-
elif line[0]=="G":
-
freq=392.00
-
elif line[0]=="R":
-
freq=0.00
-
elif line[0]=="c":
-
freq=523.25
-
elif line[0]=="d":
-
freq=587.33
-
elif line[0]=="e":
-
freq 659.26
-
-
-
-
song=song=tone
-
-
outputWAV=makewave("notes.wav",44100)
-
for sample in song:
-
outputWAV.record(sample,0)
-
outputWAV.close()
I keep getting an error after the last .26 frequency.
Please use code tags. It is difficult to follow your code without them. Why do you do this:
It's the same thing as:
Use a dictionary to determine freq: - freqDict = {'A': 440.00, "B": 493.88, "C": 261.63, "D": 293.66, \
-
"E": 329.63, "F": 349.23, "G": 392.00, "R": 0.00, \
-
"c": 523.25, "d": 587.33, "e": 659.26}
Your code could not possibly work because freq is used before it is assigned a value.
What is the following supposed to do?
Maybe you want to do something like this: - freqDict = {'A': 440.00, "B": 493.88, "C": 261.63, "D": 293.66, \
-
"E": 329.63, "F": 349.23, "G": 392.00, "R": 0.00, \
-
"c": 523.25, "d": 587.33, "e": 659.26}
-
-
notes = ['D', 'B', 'e', 'E', 'F']
-
toneList = [10000*sin(i*freqDict[note]*2*pi/44100) for i in range(1, 44100) for note in notes]
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: TrvlOrm |
last post by:
HI There,
I have been struggling with JavaScript code for days now, and this is
my last resort! Please help...
I am trying to create a JavaScript slide show with links for Next
Slide,...
|
by: Dutchy |
last post by:
Dear reader,
In an attempt to obtain the path to the quick-launch-folder in order to
create a shortcut to my application-updates during installation , I thought
to:
1- check if quick launch...
|
by: aredo3604gif |
last post by:
The user can dynamically enter and change the rule connection between
objects. The rule is a "<" and so given two objects:
a < b simply means that b < a can't be set, also it must be a != b.
And...
|
by: Mark Kamoski |
last post by:
Hi Everyone--
Please help.
I need a code sample for quick sort.
Thank you.
--Mark
|
by: B Maxey |
last post by:
I am storing images in a database and need a way to browse those files. I
can load the files into an image list or whatever the control needs, but I
need a control.
It doesn't seem that any of...
| |
by: jmbn2k |
last post by:
HI
Can anyone get me the code for the Big-O-Notation implementation of Quick sort and Bubble Sort........please
(1) BUBBLE SORT
Bubble Sort Time Complexity Space...
|
by: U S Contractors Offering Service A Non-profit |
last post by:
Brilliant technology helping those most in need Inbox
Reply
U S Contractors Offering Service A Non-profit
show details
10:37 pm (1 hour ago)
Brilliant technology helping those most in need ...
|
by: AngelLopez1989 |
last post by:
I need the complete C++ program/ algorithm of Quick Sort. Can you please help me out? No pseudocode please. Can you please also explain how to do the quick sort? Thank you!
|
by: =?Utf-8?B?eFNBTkRJeA==?= |
last post by:
I cant get i tunes/ quicktime working on the computer,
I had both of these before but they are not working now for some
reason.
Advice given on Apple site was to uninstall and then install...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |