Height = 23
OnClick = SpeedButton1Click
end
+ object button3: TLabel
+ Left = 34
+ Top = 245
+ Width = 139
+ Height = 26
+ Caption = 'pyaudio'#12391'10'#31186#38291#37682#38899#12375#12414#12377' '#27425#12395'GO'#12508#12479#12531#12434#12463#12522#12483#12463
+ WordWrap = True
+ end
+ object Label1: TLabel
+ Left = 34
+ Top = 159
+ Width = 79
+ Height = 13
+ Caption = 'python27.dll'#12497#12473
+ end
object MediaPlayer1: TMediaPlayer
Left = 136
Top = 120
- Width = 113
+ Width = 85
Height = 30
- VisibleButtons = [btPlay, btPause, btStop, btRecord]
+ VisibleButtons = [btPlay, btPause, btStop]
AutoOpen = True
DeviceType = dtWaveAudio
DoubleBuffered = True
ParentDoubleBuffered = False
TabOrder = 0
- OnClick = MediaPlayer1Click
OnMouseEnter = MediaPlayer1MouseEnter
end
object Edit1: TEdit
Text = 'Edit1'
end
object Button1: TButton
- Left = 288
- Top = 176
+ Left = 320
+ Top = 125
Width = 75
Height = 25
Caption = 'GO'
ItemHeight = 13
TabOrder = 3
end
+ object Memo1: TMemo
+ Left = 240
+ Top = 178
+ Width = 185
+ Height = 89
+ Lines.Strings = (
+ 'import pyaudio #'#37682#38899#27231#33021#12434#20351#12358#12383#12417#12398#12521#12452#12502#12521#12522
+ 'import wave #wav'#12501#12449#12452#12523#12434#25201#12358#12383#12417#12398#12521#12452#12502#12521#12522
+ ''
+ 'RECORD_SECONDS = 10 #'#37682#38899#12377#12427#26178#38291#12398#38263#12373#65288#31186#65289
+ 'WAVE_OUTPUT_FILENAME = "temp.wav" #'#38899#22768#12434#20445#23384#12377#12427#12501#12449#12452#12523#21517
+ 'iDeviceIndex = 0 #'#37682#38899#12487#12496#12452#12473#12398#12452#12531#12487#12483#12463#12473#30058#21495
+ ''
+ '#'#22522#26412#24773#22577#12398#35373#23450
+ 'FORMAT = pyaudio.paInt16 #'#38899#22768#12398#12501#12457#12540#12510#12483#12488
+ 'CHANNELS = 2 #'#12473#12486#12524#12458
+ 'RATE = 44100 #'#12469#12531#12503#12523#12524#12540#12488
+ 'CHUNK = 2**11 #'#12487#12540#12479#28857#25968
+ 'audio = pyaudio.PyAudio() #pyaudio.PyAudio()'
+ ''
+ 'stream = audio.open(format=FORMAT, channels=CHANNELS,'
+ ' rate=RATE, input=True,'
+ ' input_device_index = iDeviceIndex, #'#37682#38899#12487#12496#12452#12473#12398#12452#12531#12487#12483#12463#12473#30058#21495
+ ' frames_per_buffer=CHUNK)'
+ ''
+ '#--------------'#37682#38899#38283#22987'---------------'
+ ''
+ 'print ("recording...")'
+ 'frames = []'
+ 'for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):'
+ '#while True:'
+ ' data = stream.read(CHUNK)'
+ ' frames.append(data)'
+ ''
+ ''
+ 'print ("finished recording")'
+ ''
+ '#--------------'#37682#38899#32066#20102'---------------'
+ ''
+ 'stream.stop_stream()'
+ 'stream.close()'
+ 'audio.terminate()'
+ ''
+ 'waveFile = wave.open(WAVE_OUTPUT_FILENAME, '#39'wb'#39')'
+ 'waveFile.setnchannels(CHANNELS)'
+ 'waveFile.setsampwidth(audio.get_sample_size(FORMAT))'
+ 'waveFile.setframerate(RATE)'
+ 'waveFile.writeframes(b'#39#39'.join(frames))'
+ 'waveFile.close()')
+ TabOrder = 4
+ Visible = False
+ WordWrap = False
+ end
+ object Button2: TButton
+ Left = 64
+ Top = 214
+ Width = 75
+ Height = 25
+ Caption = 'record'
+ TabOrder = 5
+ OnClick = Button2Click
+ end
+ object Edit2: TEdit
+ Left = 34
+ Top = 178
+ Width = 187
+ Height = 21
+ TabOrder = 6
+ Text = 'C:\Users\yamat\Anaconda2'
+ end
object OpenDialog1: TOpenDialog
Filter = 'wav file|*.wav'
Left = 528
Left = 528
Top = 168
end
+ object PythonEngine1: TPythonEngine
+ DllPath = 'C:\Users\yamat\Anaconda2'
+ IO = PythonInputOutput1
+ Left = 432
+ Top = 168
+ end
+ object PythonInputOutput1: TPythonInputOutput
+ OnSendData = PythonInputOutput1SendData
+ UnicodeIO = False
+ RawOutput = False
+ Left = 432
+ Top = 216
+ end
end
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, Vcl.StdCtrls, Vcl.MPlayer,
- effect, selectFile, spWav, wav, WriteHeader;
+ effect, selectFile, spWav, wav, WriteHeader, PythonEngine,
+ PythonGUIInputOutput;
type
TForm2 = class(TForm)
SaveDialog1: TSaveDialog;
Button1: TButton;
ListBox1: TListBox;
+ PythonEngine1: TPythonEngine;
+ Memo1: TMemo;
+ Button2: TButton;
+ button3: TLabel;
+ Edit2: TEdit;
+ Label1: TLabel;
+ PythonInputOutput1: TPythonInputOutput;
procedure SpeedButton1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure MediaPlayer1MouseEnter(Sender: TObject);
- procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
- var DoDefault: Boolean);
+ procedure Button2Click(Sender: TObject);
+ procedure PythonInputOutput1SendData(Sender: TObject;
+ const Data: AnsiString);
private
{ Private \90é\8c¾ }
public
Finalize(sp.pWav^);
end;
-procedure TForm2.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
- var DoDefault: Boolean);
-var
- s: TFileStream;
+procedure TForm2.Button2Click(Sender: TObject);
begin
- if Button = btRecord then
- begin
- MediaPlayer1.fileName := 'temp.wav';
- if FileExists('temp.wav') = false then
- begin
- {
- sp.channels:=2;
- sp.samplePerSec:=44100;
- sp.bytesPerSec:=176400;
- sp.bitsPerSample:=16;
- sp.posOfData:=44;
- sp.sizeOfData:=0;
- s:=TFileStream.Create('temp.wav',fmCreate);
- try
- waveHeaderWrite(s,sp);
- finally
- s.Free;
- end;
- }
- end;
- MediaPlayer1.Open;
- end;
+ ListBox1.Items.Clear;
+ PythonEngine1.ExecStrings(Memo1.Lines);
end;
procedure TForm2.MediaPlayer1MouseEnter(Sender: TObject);
end;
end;
+procedure TForm2.PythonInputOutput1SendData(Sender: TObject;
+ const Data: AnsiString);
+begin
+ ListBox1.Items.Add(Data);
+end;
+
procedure TForm2.SpeedButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute = true then
<FrameworkType>VCL</FrameworkType>
<MainSource>changer.dpr</MainSource>
<Base>True</Base>
- <Config Condition="'$(Config)'==''">Debug</Config>
- <Platform Condition="'$(Platform)'==''">Win32</Platform>
+ <Config Condition="'$(Config)'==''">Release</Config>
+ <Platform Condition="'$(Platform)'==''">Win64</Platform>
<TargetedPlatforms>3</TargetedPlatforms>
<AppType>Application</AppType>
</PropertyGroup>
const
j = 24;
var
- i, a, b, pmin, pmax: integer;
+ i, k, a, b, pmin, pmax: integer;
len, temp_size, offset0, offset1, p, q: integer;
m, ma, pitch, rate: Single;
pMem, pCpy, pRes: array of SmallInt;
inc(offset1, p + q);
end;
pitch := 1.5;
- len := trunc(len / pitch);
- for i := 0 to len - 1 do
+ k := trunc(len / pitch);
+ for i := 0 to k - 1 do
begin
m := pitch * i;
q := trunc(m);
--- /dev/null
+# -*- coding: utf-8 -*-
+"""
+Created on Sat Aug 18 19:46:34 2018
+
+@author: fuke masasi
+"""
+
+import pyaudio #録音機能を使うためのライブラリ
+import wave #wavファイルを扱うためのライブラリ
+
+RECORD_SECONDS = 10 #録音する時間の長さ(秒)
+WAVE_OUTPUT_FILENAME = "sample.wav" #音声を保存するファイル名
+iDeviceIndex = 0 #録音デバイスのインデックス番号
+
+#基本情報の設定
+FORMAT = pyaudio.paInt16 #音声のフォーマット
+CHANNELS = 2 #ステレオ
+RATE = 44100 #サンプルレート
+CHUNK = 2**11 #データ点数
+audio = pyaudio.PyAudio() #pyaudio.PyAudio()
+
+stream = audio.open(format=FORMAT, channels=CHANNELS,
+ rate=RATE, input=True,
+ input_device_index = iDeviceIndex, #録音デバイスのインデックス番号
+ frames_per_buffer=CHUNK)
+
+#--------------録音開始---------------
+
+print ("recording...")
+frames = []
+#for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
+while True:
+ data = stream.read(CHUNK)
+ frames.append(data)
+
+
+print ("finished recording")
+
+#--------------録音終了---------------
+
+stream.stop_stream()
+stream.close()
+audio.terminate()
+
+waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
+waveFile.setnchannels(CHANNELS)
+waveFile.setsampwidth(audio.get_sample_size(FORMAT))
+waveFile.setframerate(RATE)
+waveFile.writeframes(b''.join(frames))
+waveFile.close()
\ No newline at end of file