[Tutor] How to generate a pure tones and random noise using Python?

2015-07-25 Thread Paul Z
Hi All,

I try to train my listening by using python. (estimating the frequency of sound)
So... Are there some way to generate a fixed frequency sound in different waves 
(eg. Sine Wave, Saw Wave, Triangle Wave etc.) and different random noise. (eg. 
white noise & pink noise) ?

I have search in web, some people say that I can use winsound which can 
generate a fixed frequency beep. However, It is Windows only. (I'm under Linux) 
and I think It is not a professional library to generate audio signal.

How about pygame? and some examples?
any ideas?

Thanks

Paul Z
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to generate a pure tones and random noise using Python?

2015-07-26 Thread Paul Z
Hi Laura,

Thanks for you helpful reply, and it is exactly what I want.

I'm going to learn Python from write a ears training program. ;-)
And Is there have a library to scope(print) this wave form? (real-time and non 
real-time)

I have already started to learn "generate audio with python", Thank you. :-)

Paul Z


> To: p...@whoosh.cn
> CC: tutor@python.org; l...@openend.se
> From: l...@openend.se
> Subject: Re: [Tutor] How to generate a pure tones and random noise using 
> Python?
> Date: Sat, 25 Jul 2015 22:35:24 +0200
>
> In a message of Sat, 25 Jul 2015 19:15:31 +0800, Paul Z writes:
>>Hi All,
>>
>>I try to train my listening by using python. (estimating the frequency of 
>>sound)
>>So... Are there some way to generate a fixed frequency sound in different 
>>waves (eg. Sine Wave, Saw Wave, Triangle Wave etc.) and different random 
>>noise. (eg. white noise & pink noise) ?
>>
>>I have search in web, some people say that I can use winsound which can 
>>generate a fixed frequency beep. However, It is Windows only. (I'm under 
>>Linux) and I think It is not a professional library to generate audio signal.
>>
>>How about pygame? and some examples?
>>any ideas?
>>
>>Thanks
>>
>>Paul Z
>>___
>>Tutor maillist - Tutor@python.org
>>To unsubscribe or change subscription options:
>>https://mail.python.org/mailman/listinfo/tutor
>
> I think you want this:
> https://zach.se/generate-audio-with-python/
> https://github.com/zacharydenton/wavebender
>
> pygame will not give you want you want.
>
> blender might. I am not sure but worth googling for.
>
> Laura
>
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to generate a pure tones and random noise using Python?

2015-07-26 Thread Paul Z
Hi Laura,

I just have read this webpage about Generate Audio with Python. 
It seem writing by Python 2? Esp. itertools (izip, imap).
I try to change izip and imap to zip and map, but I get error:

beatfreq, amplitude = remainder.split('/')
ValueError: need more than 1 value to unpack

Are there some way to conver it to the code of Python 3?

I'm too anxious to hear the sound from Python though I'm a absolute beginner.

Many thanks

Paul Z


> From: p...@whoosh.cn
> To: l...@openend.se
> Date: Sun, 26 Jul 2015 19:29:19 +0800
> Subject: Re: [Tutor] How to generate a pure tones and random noise using 
> Python?
> CC: tutor@python.org
>
> Hi Laura,
>
> Thanks for you helpful reply, and it is exactly what I want.
>
> I'm going to learn Python from write a ears training program. ;-)
> And Is there have a library to scope(print) this wave form? (real-time and 
> non real-time)
>
> I have already started to learn "generate audio with python", Thank you. :-)
>
> Paul Z
>
> 
>> To: p...@whoosh.cn
>> CC: tutor@python.org; l...@openend.se
>> From: l...@openend.se
>> Subject: Re: [Tutor] How to generate a pure tones and random noise using 
>> Python?
>> Date: Sat, 25 Jul 2015 22:35:24 +0200
>>
>> In a message of Sat, 25 Jul 2015 19:15:31 +0800, Paul Z writes:
>>>Hi All,
>>>
>>>I try to train my listening by using python. (estimating the frequency of 
>>>sound)
>>>So... Are there some way to generate a fixed frequency sound in different 
>>>waves (eg. Sine Wave, Saw Wave, Triangle Wave etc.) and different random 
>>>noise. (eg. white noise & pink noise) ?
>>>
>>>I have search in web, some people say that I can use winsound which can 
>>>generate a fixed frequency beep. However, It is Windows only. (I'm under 
>>>Linux) and I think It is not a professional library to generate audio signal.
>>>
>>>How about pygame? and some examples?
>>>any ideas?
>>>
>>>Thanks
>>>
>>>Paul Z
>>>___
>>>Tutor maillist - Tutor@python.org
>>>To unsubscribe or change subscription options:
>>>https://mail.python.org/mailman/listinfo/tutor
>>
>> I think you want this:
>> https://zach.se/generate-audio-with-python/
>> https://github.com/zacharydenton/wavebender
>>
>> pygame will not give you want you want.
>>
>> blender might. I am not sure but worth googling for.
>>
>> Laura
>>
>
> ___
> Tutor maillist - Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] a beginning question

2016-02-20 Thread Paul Z
Hi all,

I receive the string messages from my Mobile via UDP as below:
A, 0.1, 0.6, 0.7
B, 0.2, 0.3, 0.8

I want to arrange them to two array as below:

a = (0.1, 0.6, 0.7)
b = (0.2, 0.3, 0.8)

all the number are float.

Thanks!

Paul Z

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a beginning question

2016-02-20 Thread Paul Z
Hi,

I writed some codes as the UDP messages:

import socket 
import random
from array import *

port = 8088
host = "localhost"

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

num = array('f')
x = 0
while x < 6:
    num.append(random.random())
    x += 1

a0 = str("%.2f"%num[0]) + ','
a1 = str("%.2f"%num[1]) + ','
a2 = str("%.2f"%num[2]) + ','
a3 = str("%.2f"%num[3]) + ','
a4 = str("%.2f"%num[4]) + ','
a5 = str("%.2f"%num[5]) + ','

msg1 = 'a,' + a0 + a1 + a2
msg1 = bytes(msg1, 'utf-8')
msg2 = 'b,' + a3 + a4 + a5
msg2 = bytes(msg2, 'utf-8')

s.sendto(msg1, (host, port))
s.sendto(msg2, (host, port))

and I receive the messages via:

import socket 
port = 8088
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) 
s.bind(("",port)) 
print('waiting on port:',port)
while True: 
  data,addr = s.recvfrom(1024) 
  print('reciveed:', data, "from", addr)

I want to arrange the messages to:

array1 = #the numbers which is start as 'a' in the messages 
array2 = #the numbers which is start as b in the messages

Thanks!
Paul Z 

 


> From: p...@whoosh.cn
> To: alan.ga...@btinternet.com
> CC: tutor@python.org
> Subject: RE: [Tutor] a beginning question
> Date: Sat, 20 Feb 2016 19:51:16 +0800
>
> Hi Alan,
>
> Thanks for your reply,
>
> My friend help me to write a andriod app which send UDP messages.
> And I writed some codes by using Python to receive the messages as below:
>
> import socket
> port = 8081
> s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
> s.bind(("",port))
> print('waiting on port:',port)
> while True:
>   data,addr = s.recvfrom(1024)
>   print('reciveed:', data, "from", addr)
>
> and I plan to re-pack them, and send them to an other computer and port.
> I think my code should judge the messages which is "a..." or "b..." first, 
> then arrange them as below:
>
> a = (0.1, 0.6, 0.7)
> b = (0.2, 0.3, 0.8)
>
> the numbers in the example is variable.
> and The messages I recived from andriod app are some strings which is as the 
> head 'a' or 'b', such as 'a, 0.1, 0.6, 0.7'.
>
> Thanks
> Paul Z
>
> 
>> To: tutor@python.org
>> From: alan.ga...@btinternet.com
>> Date: Sat, 20 Feb 2016 10:33:51 +
>> Subject: Re: [Tutor] a beginning question
>>
>> On 20/02/16 09:15, Paul Z wrote:
>>> Hi all,
>>>
>>> I receive the string messages from my Mobile via UDP as below:
>>> A, 0.1, 0.6, 0.7
>>> B, 0.2, 0.3, 0.8
>>
>> I think we need a bit more detail.
>> How do you receive these messages? UDP requires some
>> kind of receiving service, so what is it that is
>> receiving these messages? Is it your python program?
>> Or is it some other bit of software?
>>
>> Having received these strings what happens?
>> Are they stored in a variable? In a file? where?
>>
>>> I want to arrange them to two array as below:
>>>
>>> a = (0.1, 0.6, 0.7)
>>> b = (0.2, 0.3, 0.8)
>>
>> What you've shown would be tuples in Python, not
>> arrays. We need to be precise about data types.
>> Do you want the data in a list, a tuple, an array?
>> Do you understand the differences?
>>
>> Now, to try to answer your question based on the
>> most optimistic set of assumptions:
>> ie. You are receiving the messages in your python code
>> and storing them as string variables called s1
>> and s2 and you want the result to be a list of floats.
>>
>> a = [float(n) for n in s1.split(',')]
>> b = [float(n) for n in s2.split(',')]
>>
>> But I suspect that I'm being overly optimistic...
>> --
>> Alan G
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>> http://www.amazon.com/author/alan_gauld
>> Follow my photo-blog on Flickr at:
>> http://www.flickr.com/photos/alangauldphotos
>>
>>
>> ___
>> Tutor maillist - Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
  

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] how to receive messages form a server?

2016-03-08 Thread Paul Z
Hi,

There is AP with UDP-Server(sending UDP messages).
My computer has connected the AP. I know how to receive messages form a client 
via socket.
But, Now, how to receive messages from a server?

Thanks!
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor