File: examples-hears_artificial_vowels.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (77 lines) | stat: -rw-r--r-- 1,948 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
.. currentmodule:: brian

.. index::
   pair: example usage; subplot
   pair: example usage; plot
   pair: example usage; play
   pair: example usage; show
   pair: example usage; set_default_samplerate
   pair: example usage; Sound
   pair: example usage; save

.. _example-hears_artificial_vowels:

Example: artificial_vowels (hears)
==================================

This example implements the artificial vowels from
Culling, J. F. and Summerfield, Q. (1995a). "Perceptual segregation of
concurrent speech sounds: absence of across-frequency grouping by common
interaural delay" J. Acoust. Soc. Am. 98, 785-797.

::

    from brian import *
    from brian.hears import *
    
    duration = 409.6*ms
    width = 150*Hz/2
    samplerate = 10*kHz
    
    set_default_samplerate(samplerate)
    
    centres = [225*Hz, 625*Hz, 975*Hz, 1925*Hz]
    vowels = {
        'ee':[centres[0], centres[3]],
        'ar':[centres[1], centres[2]],
        'oo':[centres[0], centres[2]],
        'er':[centres[1], centres[3]]
        }
    
    def generate_vowel(vowel):
        vowel = vowels[vowel]
        x = whitenoise(duration)
        y = fft(asarray(x).flatten())
        f = fftfreq(len(x), 1/samplerate)
        I = zeros(len(f), dtype=bool)
        for cf in vowel:
            I = I|((abs(f)<cf+width)&(abs(f)>cf-width))
        I = -I
        y[I] = 0
        x = ifft(y)
        return Sound(x.real)
    
    v1 = generate_vowel('ee').ramp()
    v2 = generate_vowel('ar').ramp()
    v3 = generate_vowel('oo').ramp()
    v4 = generate_vowel('er').ramp()
    
    for s in [v1, v2, v3, v4]:
        s.play(normalise=True, sleep=True)
    
    s1 = Sound((v1, v2))
    #s1.play(normalise=True, sleep=True)
    
    s2 = Sound((v3, v4))
    #s2.play(normalise=True, sleep=True)
    
    v1.save('mono_sound.wav')
    s1.save('stereo_sound.wav')
    
    subplot(211)
    plot(v1.times, v1)
    subplot(212)
    v1.spectrogram()
    show()