LoginSignup
0
1

More than 1 year has passed since last update.

こちらを読んで試してみようと思いました。

マニュアルを読むとpip install librosaで行けるようです。

ところが、実際にやってみるとエラーに。

%pip install librosa
Python
import librosa
OSError: cannot load library 'libsndfile.so': libsndfile.so: cannot open shared object file: No such file or directory

Databricksランタイムにはlibsndfileがインストールされていないのでインストールが必要というオチでした。

initスクリプトを作成します。

Python
dbutils.fs.put("/cluster-init/scripts/librosa_init_script.sh","""
#!/bin/bash
apt-get --yes install libsndfile1
""", True)

クラスターでinitスクリプトを設定します。
Screenshot 2023-01-19 at 16.47.07.png

librosaもクラスターライブラリとしてインストールしてしまいます。
Screenshot 2023-01-19 at 16.47.56.png

サンプルプログラムを実行します。

Python
# Beat tracking example
import librosa

# 1. Get the file path to an included audio example
filename = librosa.example('nutcracker')

# 2. Load the audio as a waveform `y`
#    Store the sampling rate as `sr`
y, sr = librosa.load(filename)

# 3. Run the default beat tracker
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

print('Estimated tempo: {:.2f} beats per minute'.format(tempo))

# 4. Convert the frame indices of beat events into timestamps
beat_times = librosa.frames_to_time(beat_frames, sr=sr)

無事動きました。
Screenshot 2023-01-19 at 16.50.29.png

Databricks 無料トライアル

Databricks 無料トライアル

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1