gimKondo / sound-of-cthulhu

Sound management tool for TRPG session
MIT License
3 stars 1 forks source link

Discordモードで音楽を再生できない #147

Open gimKondo opened 1 year ago

gimKondo commented 1 year ago

概要

Discordモードで音声を再生しようとしても音が鳴らない。

再現方法

  1. Output DeviceでDiscord APIを選択
  2. Discordでボイスチャンネルに入り、テキストチャンネルで :soc: join と打ち込む
  3. 任意の音楽を再生する
  4. 音楽が鳴らない
  5. (デバッグ実行すると)エラーポップアップが出る

期待する動作

3の時点で指定の音楽がDiscordのbotから再生される

環境 (下記の情報を埋めてください)

追加情報

デバッグ時のポップアップ

yarn electron:serve で実行してDiscordモードで音声を再生すると以下のようなエラーポップアップが出る。

Uncaught Exception:
Error: Error: Cannot find module 'node:path'
Require stack:
- path_of_app/sound-of-cthulhu/node_modules/@discordjs/opus/lib/index.js
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/util/loader.js
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/opus/Opus.js
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/opus/index.js
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/index.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/voice/player/BasePlayer.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/voice/player/BroadcastAudioPlayer.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/voice/VoiceBroadcast.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/voice/ClientVoiceManager.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/Client.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/index.js
- path_of_app/sound-of-cthulhu/dist_electron/index.js
- path_of_app/sound-of-cthulhu/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js
- 
Error: Cannot find module 'node-opus'
Require stack:
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/util/loader.js
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/opus/Opus.js
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/opus/index.js
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/index.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/voice/player/BasePlayer.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/voice/player/BroadcastAudioPlayer.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/voice/VoiceBroadcast.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/voice/ClientVoiceManager.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/client/Client.js
- path_of_app/sound-of-cthulhu/node_modules/discord.js/src/index.js
- path_of_app/sound-of-cthulhu/dist_electron/index.js
- path_of_app/sound-of-cthulhu/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js
- 
Error: Cannot find module 'opusscript'
Require stack:
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/util/loader.js
- path_of_app/sound-of-cthulhu/node_modules/prism-media/src/opus/Opus.js
gimKondo commented 1 year ago

Node.jsのバージョンを18系に上げてみる

Cannot find module 'node:path' のようなエラーはNode.jsのバージョンが古いときに起こることがあるという記事を見かけた。 例: https://stackoverflow.com/questions/72915260/babel-cannot-find-module-nodepath-error-react-native

そこで、Node.jsをv16.18.1からv18.16.0に上げてみた。 しかし、上げて yarn install すると下記のようなエラーが発生する。

yarn install時のエラー ``` yarn install v1.22.19 [1/4] 🔍 Resolving packages... [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... warning " > babel-core@7.0.0-bridge.0" has unmet peer dependency "@babel/core@^7.0.0-0". warning " > sass-loader@7.3.1" has unmet peer dependency "webpack@^3.0.0 || ^4.0.0". warning " > vuetify-loader@1.9.2" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0". warning "vuetify-loader > file-loader@6.2.0" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0". [4/4] 🔨 Building fresh packages... $ electron-builder install-app-deps • electron-builder version=23.6.0 • rebuilding native dependencies dependencies=@discordjs/opus@0.9.0 platform=darwin arch=x64 • rebuilding native dependency name=@discordjs/opus version=0.9.0 ⨯ cannot execute cause=exit status 1 yarn run v1.22.19 $ node-pre-gyp install --fallback-to-build Failed to execute '/Users/a_user/.anyenv/envs/nodenv/versions/18.16.0/bin/node /Users/a_user/projects/sound-of-cthulhu/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus/prebuild/electron-v9.4-napi-v3-darwin-x64-unknown-unknown/opus.node --module_name=opus --module_path=/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus/prebuild/electron-v9.4-napi-v3-darwin-x64-unknown-unknown --napi_version=8 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1) info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. errorOut=node-pre-gyp info it worked if it ends with ok node-pre-gyp info using node-pre-gyp@0.4.5 node-pre-gyp info using node@18.16.0 | darwin | x64 node-pre-gyp http GET https://github.com/discordjs/opus/releases/download/v0.9.0/opus-v0.9.0-electron-v9.4-napi-v3-darwin-x64-unknown-unknown.tar.gz node-pre-gyp ERR! install response status 404 Not Found on https://github.com/discordjs/opus/releases/download/v0.9.0/opus-v0.9.0-electron-v9.4-napi-v3-darwin-x64-unknown-unknown.tar.gz node-pre-gyp WARN Pre-built binaries not installable for @discordjs/opus@0.9.0 and electron@9.4.4 (electron-v9.4 ABI, unknown) (falling back to source compile with node-gyp) node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/discordjs/opus/releases/download/v0.9.0/opus-v0.9.0-electron-v9.4-napi-v3-darwin-x64-unknown-unknown.tar.gz gyp info it worked if it ends with ok gyp info using node-gyp@8.4.1 gyp info using node@18.16.0 | darwin | x64 gyp info ok gyp info it worked if it ends with ok gyp info using node-gyp@8.4.1 gyp info using node@18.16.0 | darwin | x64 gyp info find Python using Python version 3.11.2 found at "/usr/local/opt/python@3.11/bin/python3.11" gyp info spawn /usr/local/opt/python@3.11/bin/python3.11 gyp info spawn args [ gyp info spawn args '/Users/a_user/projects/sound-of-cthulhu/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/Users/a_user/projects/sound-of-cthulhu/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/Users/a_user/.electron-gyp/9.4.4/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/Users/a_user/.electron-gyp/9.4.4', gyp info spawn args '-Dnode_gyp_dir=/Users/a_user/projects/sound-of-cthulhu/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=/Users/a_user/.electron-gyp/9.4.4/<(target_arch)/node.lib', gyp info spawn args '-Dmodule_root_dir=/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' gyp info spawn args ] gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/Users/a_user/projects/sound-of-cthulhu/node_modules/node-gyp/lib/configure.js:259:16) gyp ERR! stack at ChildProcess.emit (node:events:513:28) gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:291:12) gyp ERR! System Darwin 22.3.0 gyp ERR! command "/Users/a_user/.anyenv/envs/nodenv/versions/18.16.0/bin/node" "/Users/a_user/projects/sound-of-cthulhu/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus/prebuild/electron-v9.4-napi-v3-darwin-x64-unknown-unknown/opus.node" "--module_name=opus" "--module_path=/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus/prebuild/electron-v9.4-napi-v3-darwin-x64-unknown-unknown" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3" gyp ERR! cwd /Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus gyp ERR! node -v v18.16.0 gyp ERR! node-gyp -v v8.4.1 gyp ERR! not ok node-pre-gyp ERR! build error node-pre-gyp ERR! stack Error: Failed to execute '/Users/a_user/.anyenv/envs/nodenv/versions/18.16.0/bin/node /Users/a_user/projects/sound-of-cthulhu/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus/prebuild/electron-v9.4-napi-v3-darwin-x64-unknown-unknown/opus.node --module_name=opus --module_path=/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus/prebuild/electron-v9.4-napi-v3-darwin-x64-unknown-unknown --napi_version=8 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1) node-pre-gyp ERR! stack at ChildProcess. (/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/node-pre-gyp/lib/util/compile.js:85:20) node-pre-gyp ERR! stack at ChildProcess.emit (node:events:513:28) node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1091:16) node-pre-gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:302:5) node-pre-gyp ERR! System Darwin 22.3.0 node-pre-gyp ERR! command "/Users/a_user/.anyenv/envs/nodenv/versions/18.16.0/bin/node" "/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" node-pre-gyp ERR! cwd /Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus node-pre-gyp ERR! node -v v18.16.0 node-pre-gyp ERR! node-pre-gyp -v v0.4.5 node-pre-gyp ERR! not ok error Command failed with exit code 1. command=/Users/a_user/.anyenv/envs/nodenv/versions/18.16.0/bin/node /Users/a_user/.anyenv/envs/nodenv/versions/18.16.0/lib/node_modules/yarn/bin/yarn.js run install workingDir=/Users/a_user/projects/sound-of-cthulhu/node_modules/@discordjs/opus error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. ```
gimKondo commented 1 year ago

関連しそうなissue

gimKondo commented 1 year ago

https://qiita.com/tukiyo3/items/c9d638f4c7fe5bcaa4f2#openssl_fips%E6%9C%AA%E5%AE%9A%E7%BE%A9%E3%82%A8%E3%83%A9%E3%83%BC%E5%AF%BE%E5%BF%9C の記事のように node_modules/node-gyp/gyp/pylib/gyp/input.py を直接書き換えると yarn install は正常に終了する。

さらに https://qiita.com/tukiyo3/items/c9d638f4c7fe5bcaa4f2#%E3%83%87%E3%83%90%E3%83%83%E3%82%B0%E8%B5%B7%E5%8B%95%E3%81%95%E3%81%9B%E3%82%8B%E6%96%B9%E6%B3%95 のようなコードを追加することでアプリを起動させることもできる。 (これをやらないと記事にある通りのエラーになる)

しかし、結局、Discord APIで音声を再生しようとすると同じエラーが起きる。

※そもそも node_modules以下の書き換えが必要になる時点で解決方法としてはだめだが。

gimKondo commented 1 year ago

electronのバージョンが古いことにも関連してそうなので、この辺を片付けると解消しそうな気もする。