geson-anko / pynktrombonegym Goto Github PK
View Code? Open in Web Editor NEWThe vocal tract environment for speech generations by reinforcement learning.
The vocal tract environment for speech generations by reinforcement learning.
space.sample()
によって得られる返り値の型が全てnumpy.ndarray
であり想定していた型(float型など)と異なっていたため修正します。
ObservationSpace
ActionSpace
All parameters.
target_sound_wave
を切り出した時にgenerate_chunk
に満たない場合は0で配列を埋めます。
Action/Observation Spaceをコンストラクトする際にキーワード引数として割り当ててないため、割り当てミスをする恐れがあります。
ActionSpace(
spaces.Box(-1.0, 1.0),
spaces.Box(0.0, 1.0),
...
)
よってこのようにキーワード引数として指定することで可読性、安全性が向上します。
ActionSpace(
pitch_shift=spaces.Box(-1.0, 1.0),
tenseness=spaces.Box(0.0, 1.0),
...
)
gym.ObservationWrapper
を用いてObservationのspectrogram
をlog1p mel spectrogramに変換します。
引数のtarget_sound_files
の長さが0の時にValueError
を送信するようにします。
PynkTromboneの環境そのものの状態初期化メソッドを実装します。
reset
メソッドと__init__
コンストラクタで呼び出されます。
Vocの再構築などを行います。
pynktrombonegym/spectrogram.pyの中のload_sound_file
に次の問題点があります。
max_value
の計算方法は 2**(8*sample_width - 1)
が正しい。sound.sample_width
が返す値は波形の1サンプルあたりのバイト数であるため、値域が[-1,1]かつfloat32型だった場合に、全ての要素が 1 / (2 ** 31)
倍され値が消失する恐れがある。def load_sound_file(file_path: Any, sample_rate: int) -> np.ndarray:
"""Load sound wave from file.
Fix sound channel to 1, sample_rate, and
normalize range to [-1,1].
Args:
file_path (str): Path to the sound file.
Returns:
waveform (ndarray): Range[-1,1]
Waveform of loaded sound.
"""
sound: AudioSegment = AudioSegment.from_file(file_path)
if sound.frame_rate != sample_rate:
sound = sound.set_frame_rate(sample_rate)
if sound.channels != 1:
sound = sound.set_channels(1)
max_value = 2 ** (8 * sound.sample_width)
wave = np.array(sound.get_array_of_samples()).reshape(-1) / max_value
wave = wave.astype(np.float32)
return wave
target_sound_wave
self.current_step
を用いてself.target_sound_wave_full
から切り出されます。generated_sound_wave
self._generated_sound_wave_2chunks
の後ろ半分を返します。#81 より、Rendering処理を記述するクラスをenv.py
から入り離しましたが、renderer.py
の内部でenv.py
を読み込んでしまっているため、無限importループに陥ってしまいました。
さて、どうしましょうか。
PynkTromboneGymによる波形生成デモンストレーション
gym.ActionWrapper
を用いて行動のフォーマットを加速度によるものにします。
matplotlibによるリアルタイムRendering処理について
直感的でない命名をしている変数の名前変更
target_sound
-> target_sound_spectrogram
previous_generated_sound
-> generated_sound_spectrogram
PynkTromboneから生成される波形や、スペクトログラムに変換される前のtarget_sound
の生の波形をObservationSpace
に追加します。
CHUNK
CHUNK
env
は様々なモジュール、関数名として使用されることが多いため、environment.py
にリネームする必要があります。
現在のobservation/action spaceの定義はデータクラスを用いて行なっていますが、この手法は新たな観測情報や、行動をラッパークラスや派生クラスで定義することができません。
よって、gym.spaces.Dict
をそのまま扱い、keyの値をEnum型のクラスで扱うような形を提案します。
class Keys(Enum):
target_sound_wave = 'target_sound_wave'
...
observation_space = spaces.Dict({
Keys.target_sound_wave : spaces.Box(...)
})
音声処理ライブラリlibrosa
用います。
現在stft
などをするための関数を独自で実装していますが、安全性、機能面からlibrosa
に移行します。
spectrogram.py
のstft
関数はそのまま残し、簡易的なラッパーとして利用します。
#81
__del__
メソッドで自動的にclose
メソッド呼び出すことによって例外が送信されることがあります。よって__del__
メソッドを削除し、明示的にclose
メソッドを呼び出すように変更しましょう。
PynkTromboneの実装では、tongue_index
の型はfloat
です。従って、このPynkTromboneGym
でもFloat型にすることが望まれます。
しかし、この命名は誤解を非常に呼びやすいため、READMEに書き込み、PynkTrombone
environmentクラスにも書き込んでおく必要があります。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.