473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help quick please!

1 New Member
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.
Feb 8 '08 #1
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:
Expand|Select|Wrap|Line Numbers
  1. noteFileName=raw_input("What file are the notes in?")
  2. noteFile=open(noteFileName,'r')
  3.  
  4. song=[]
  5. for line in noteFile:
  6.     print line
  7.     tone=[10000*sin(i*freq*2*pi/44100) for i in range(int(1.0*44100))]
  8.  
  9.     if line[0]=="A":
  10.         freq=440.00
  11.     elif line[0]=="B":
  12.         freq=493.88
  13.     elif line[0]=="C":
  14.         freq=261.63
  15.     elif line[0]=="D":
  16.         freq=293.66
  17.     elif line[0]=="E":
  18.         freq=329.63
  19.     elif line[0]=="F":
  20.         freq=349.23
  21.     elif line[0]=="G":
  22.         freq=392.00
  23.     elif line[0]=="R":
  24.         freq=0.00
  25.     elif line[0]=="c":
  26.         freq=523.25
  27.     elif line[0]=="d":
  28.         freq=587.33
  29.     elif line[0]=="e":
  30.         freq 659.26
  31.  
  32.  
  33.  
  34. song=song=tone
  35.  
  36. outputWAV=makewave("notes.wav",44100)  
  37. for sample in song:                  
  38.     outputWAV.record(sample,0)      
  39. 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:
Expand|Select|Wrap|Line Numbers
  1. range(int(1.0*44100))
It's the same thing as:
Expand|Select|Wrap|Line Numbers
  1. range(44100)
Use a dictionary to determine freq:
Expand|Select|Wrap|Line Numbers
  1. freqDict = {'A': 440.00, "B": 493.88, "C": 261.63, "D": 293.66, \
  2.             "E": 329.63, "F": 349.23, "G": 392.00, "R": 0.00, \
  3.             "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?
Expand|Select|Wrap|Line Numbers
  1. song=song=tone
Maybe you want to do something like this:
Expand|Select|Wrap|Line Numbers
  1. freqDict = {'A': 440.00, "B": 493.88, "C": 261.63, "D": 293.66, \
  2.             "E": 329.63, "F": 349.23, "G": 392.00, "R": 0.00, \
  3.             "c": 523.25, "d": 587.33, "e": 659.26}
  4.  
  5. notes = ['D', 'B', 'e', 'E', 'F']
  6. toneList = [10000*sin(i*freqDict[note]*2*pi/44100) for i in range(1, 44100) for note in notes]
Feb 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2043
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,...
8
5359
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...
0
310
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...
2
3369
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. I need a code sample for quick sort. Thank you. --Mark
3
2333
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...
1
3340
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...
0
3921
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 ...
1
1689
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!
1
2845
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...
0
7201
marktang
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,...
0
7328
jinu1996
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...
1
6988
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...
0
5578
agi2029
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,...
1
5011
isladogs
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...
0
4672
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...
0
3166
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...
0
1510
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 ...
0
379
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.