質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

1616閲覧

Pythonでsoxを使用したいが認識してくれない

btwk__wd

総合スコア0

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2022/01/09 08:34

前提・実現したいこと

Pythonで音声認識をするべく、公開されているソースコードを用いて実行を試みており、そのためにsoxというモジュールを使用したいのですが、Pythonが認識してくれません。

jupyter notebookを使っています。

発生している問題・エラーメッセージ

This install of SoX cannot process .wav files. This install of SoX cannot process .wav files. oto/data/original/jsut_ver1.1/basic5000/wav\BASIC5000_0001.wav --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) <ipython-input-2-eceebcabe0cd> in <module> 33 exit() 34 ---> 35 tfm.build_file(input_filepath=wav_path_in, 36 output_filepath=wav_path_out) 37 c:\users\tsujo\appdata\local\programs\python\python39\lib\site-packages\sox\transform.py in build_file(self, input_filepath, output_filepath, input_array, sample_rate_in, extra_args, return_output) 708 709 ''' --> 710 return self.build( 711 input_filepath, output_filepath, input_array, sample_rate_in, 712 extra_args, return_output c:\users\tsujo\appdata\local\programs\python\python39\lib\site-packages\sox\transform.py in build(self, input_filepath, output_filepath, input_array, sample_rate_in, extra_args, return_output) 591 592 ''' --> 593 input_format, input_filepath = self._parse_inputs( 594 input_filepath, input_array, sample_rate_in 595 ) c:\users\tsujo\appdata\local\programs\python\python39\lib\site-packages\sox\transform.py in _parse_inputs(self, input_filepath, input_array, sample_rate_in) 494 input_format = self.input_format 495 if input_format.get('channels') is None: --> 496 input_format['channels'] = file_info.channels(input_filepath) 497 elif input_array is not None: 498 if not isinstance(input_array, np.ndarray): c:\users\tsujo\appdata\local\programs\python\python39\lib\site-packages\sox\file_info.py in channels(input_filepath) 80 ''' 81 validate_input_file(input_filepath) ---> 82 output = soxi(input_filepath, 'c') 83 return int(output) 84 c:\users\tsujo\appdata\local\programs\python\python39\lib\site-packages\sox\core.py in soxi(filepath, argument) 145 146 try: --> 147 shell_output = subprocess.check_output( 148 args, 149 stderr=subprocess.PIPE c:\users\tsujo\appdata\local\programs\python\python39\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs) 422 kwargs['input'] = empty 423 --> 424 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, 425 **kwargs).stdout 426 c:\users\tsujo\appdata\local\programs\python\python39\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs) 503 kwargs['stderr'] = PIPE 504 --> 505 with Popen(*popenargs, **kwargs) as process: 506 try: 507 stdout, stderr = process.communicate(input, timeout=timeout) c:\users\tsujo\appdata\local\programs\python\python39\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask) 949 encoding=encoding, errors=errors) 950 --> 951 self._execute_child(args, executable, preexec_fn, close_fds, 952 pass_fds, cwd, env, 953 startupinfo, creationflags, shell, c:\users\tsujo\appdata\local\programs\python\python39\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session) 1418 # Start the process 1419 try: -> 1420 hp, ht, pid, tid = _winapi.CreateProcess(executable, args, 1421 # no special security 1422 None, None, FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。

該当のソースコード

Python

1import sox 2 3import os 4 5if __name__ == "__main__": 6 7 original_wav_dir = 'oto/data/original/jsut_ver1.1/basic5000/wav' 8 9 out_wav_dir = 'oto/data/wav' 10 11 out_scp_dir = 'oto/data/label/all' 12 13 os.makedirs(out_wav_dir, exist_ok=True) 14 os.makedirs(out_scp_dir, exist_ok=True) 15 16 tfm = sox.Transformer() 17 18 tfm.convert(samplerate=16000) 19 20 with open(os.path.join(out_scp_dir, 'wav.scp'), mode='w') as scp_file: 21 22 for i in range(5000): 23 filename = 'BASIC5000_%04d' % (i+1) 24 25 wav_path_in = os.path.join(original_wav_dir, filename+'.wav') 26 27 wav_path_out = os.path.join(out_wav_dir, filename+'.wav') 28 29 print(wav_path_in) 30 31 if not os.path.exists(wav_path_in): 32 print('Error: Not found %s' % (wav_path_in)) 33 exit() 34 35 tfm.build_file(input_filepath=wav_path_in, 36 output_filepath=wav_path_out) 37 38 scp_file.write('%s %s\n' % 39 (filename, os.path.abspath(wav_path_out))) 40 41

試したこと

同じソースコードを用いてエラーが出ていた方がいらっしゃったので、その方への回答を参考にパスを通そうと試みたのですが、それがうまくいっているのかすら判断ができません。

Python自体ほとんど扱ったことがないため、拙い点も多いかと思いますがよろしくお願いいたします。

補足情報(FW/ツールのバージョンなど)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

SoXをWindows10で使い始めるまでの手順(メモ)
を参考に、soxをインストールして、sox.exeがあるディレクトリパスを環境変数Pathに追加してみてください

投稿2022/02/04 08:03

jbpb0

総合スコア7653

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問