/
make_sentence.py
63 lines (57 loc) · 1.51 KB
/
make_sentence.py
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
# -*- coding:utf-8 -*-
import pyaudio
import numpy as np
import wave
import struct
RATE=44100
CHUNK = 22050
p=pyaudio.PyAudio()
#f_list=['a','i','si','te','ru','u','wa','n','sa','n']
#sentence='あ い し て る う わ ん さ ん ま る'
file1 = open("sentence2.txt","r",encoding="utf-8")
sentence=file1.read()
print(sentence)
f_list=sentence.split(" ")
print(f_list)
#f_list=['あ','い','し','て','る','う','わ','ん','さ','ん','ま','る']
stream=p.open(format = pyaudio.paInt16,
channels = 1,
rate = int(RATE*1.15),
frames_per_buffer = CHUNK,
input = True,
output = True) # inputとoutputを同時にTrueにする
w = wave.Wave_write("./fft_sound/Success_a-n_05/a-n-iine/aiueo/ohayo005_sin.wav")
p = (1, 2, RATE, CHUNK, 'NONE', 'not compressed')
w.setparams(p)
def kana2a(i):
j='n'
if i=='あ':
j='a'
elif i=='い':
j='i'
elif i=='し':
j='si'
elif i=='て':
j='te'
elif i=='る':
j='ru'
elif i=='う':
j='u'
elif i=='わ':
j='wa'
elif i=='ん':
j='n'
elif i=='さ':
j='sa'
elif i=='ま':
j='ma'
return j
#C:\Users\user\Onsei_AE\fft_sound\Success_a-n_05\a-n-iine\aiueo
for i in f_list:
i=kana2a(i)
wavfile = './fft_sound/Success_a-n_05/a-n-iine/aiueo/'+i+'.wav'
print(wavfile)
wr = wave.open(wavfile, "rb")
input = wr.readframes(wr.getnframes())
output = stream.write(input)
w.writeframes(input)