Coder Social home page Coder Social logo

pynktrombonegym's People

Contributors

geson-anko avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pynktrombonegym's Issues

Type mistakes of Action and Observation space class.

space.sample()によって得られる返り値の型が全てnumpy.ndarrayであり想定していた型(float型など)と異なっていたため修正します。

  • ObservationSpace

    • frequency(float)
    • pitch_shift(float)
    • tenseness(float)
  • ActionSpace
    All parameters.

env/pad target sound wave

target_sound_waveを切り出した時にgenerate_chunkに満たない場合は0で配列を埋めます。

Use `librosa` to make simply.

音声処理ライブラリlibrosa用います。
現在stftなどをするための関数を独自で実装していますが、安全性、機能面からlibrosaに移行します。
spectrogram.pystft関数はそのまま残し、簡易的なラッパーとして利用します。

load_sound_file has some problems

pynktrombonegym/spectrogram.pyの中のload_sound_fileに次の問題点があります。

  • max_valueの計算方法は 2**(8*sample_width - 1)が正しい。
  • int型で書き込まれた音声ファイルのみを想定しており、float型で書き込まれたファイルの読み込みが正常に動作しない恐れがある。
    sound.sample_widthが返す値は波形の1サンプルあたりのバイト数であるため、値域が[-1,1]かつfloat32型だった場合に、全ての要素が 1 / (2 ** 31)倍され値が消失する恐れがある。

Source code of spectrogram.py

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

Demos

PynkTromboneGymによる波形生成デモンストレーション

  • generate_randomly
    ランダムに行動を生成して、2秒ほどの波形を生成します
  • nothing
    声道モデルに何も作用せず、波形を生成します。

Space Definition の後方互換性問題

現在の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(...)
})

Renderer

matplotlibによるリアルタイムRendering処理について

`Tongue Index` is float type.

PynkTromboneの実装では、tongue_indexの型はfloatです。従って、このPynkTromboneGymでもFloat型にすることが望まれます。

しかし、この命名は誤解を非常に呼びやすいため、READMEに書き込み、PynkTrombone environmentクラスにも書き込んでおく必要があります。

Renderer class circular import problem

#81 より、Rendering処理を記述するクラスをenv.pyから入り離しましたが、renderer.pyの内部でenv.pyを読み込んでしまっているため、無限importループに陥ってしまいました。
さて、どうしましょうか。

Add `Wave` Observation

PynkTromboneから生成される波形や、スペクトログラムに変換される前のtarget_soundの生の波形をObservationSpaceに追加します。

  • target_sound_wave
    そのステップで目的となる音声波形。 長さはCHUNK
  • generated_sound_wave
    そのステップでPynkTromboneから生成された生の波形。長さはCHUNK

Renderer `__del__` causes exception.

#81
__del__メソッドで自動的にcloseメソッド呼び出すことによって例外が送信されることがあります。よって__del__メソッドを削除し、明示的にcloseメソッドを呼び出すように変更しましょう。

Env/initialize_state

PynkTromboneの環境そのものの状態初期化メソッドを実装します。
resetメソッドと__init__コンストラクタで呼び出されます。
Vocの再構築などを行います。

Env/ space definition issue

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),
    ...
)

Bad Naming

直感的でない命名をしている変数の名前変更

  • ObservationSpace
    • target_sound -> target_sound_spectrogram
    • previous_generated_sound -> generated_sound_spectrogram

Rename env.py to environment.py

envは様々なモジュール、関数名として使用されることが多いため、environment.pyにリネームする必要があります。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.