Closed RonnieBlade closed 2 years ago
pull requestありがとうございます。 動画が停止した時にCaptionSpeaker側の発話も停止するというアイデアは良いと思います。
ただ、少し動作を確認してみましたところ、動作上気になる点がいくつかありました。
具体的には、
id="movie_player"
のタグが存在するWebページで不必要なMutationObserverが生成されてしまう可能性がある。speechSynthesis.cancel()
で止めるのではなく、speechSynthesis.pause()
で一時停止して後から再開(speechSynthesis.resume()
)できるとさらに良さそうです。二番目の問題については const screen = document.getElementById("movie_player");
を行っている部分をURL等を確認してから行うように変更することで回避できると思います。
三番目については実現できると嬉しそうですが、そこまで頑張らなくても良いと考えています。
一番目の問題はできれば直しておきたいです。私はこの問題の解消には実装の方法を少し考えたほうが良さそうに考えています。
アイデアとしては、wasPaused
で停止されているかどうかの管理をするのではなく、prevSpeakTime
を初期化して発話が行われていなかった事にする形で実現することができそうな気がしています。
具体的には、お寄せいただいた pull request の552行目
の wasPaused = true;
の部分を prevSpeakTime = "";
に変更するような形です(恐らくこの修正だけでは正常には動作しないと思います)。
以上のような点を考えてみましたが、改善はできるでしょうか。 難しそうであればこちらで作業しても良いです。
Thank you for the prompt review! Working on that
素晴らしい! 期待しています。(´ω`)
Hi Limura! I've changed the implementation and fixed the bugs. Regarding to your notes:
I detected that if you pause the video, then play a video in another tab, it continues speaking the remaining part of a speech from the previous video. I have fixed it in the last commit. It seems that everything works as expected now.
変更ありがとうございます。 .pause() を実装したのですね。素晴らしい仕事だと思います。
ただ、全体的に変更箇所が多くなっているために問題が出てきてしまっているようです。 以下で詳しく述べますが、私が同様の機能を実装し直したほうが早そうな気がしています。
まず、実装上の事について私が気になった点は以下のような所です。
.resume()
した後に .speak()
している箇所があります。場合によっては発話が重複するかもしれません。安全のため、.resume()
した後は return;
した方が良さそうです。また、直前の .cancel()
が誤動作を誘発しないかも心配なので、SpeechSynthesis の仕様を確認しておいたほうが良さそうな気がしています。(具体的には https://github.com/limura/CaptionSpeaker/pull/8/commits/1b869099a1cc8e707ec3e37851920fcdc5a9956e#diff-22f1e79483087db4b872e00c5e454ed5d5dc28a26b761d05239c0a981951acadR332 の辺りの箇所です)次に、以下に述べる項目は私が pull request を受け付ける前に提示しておくべき事であったので申し訳ないのですが、プログラムコードの書き方について、注意して頂きたい事項になります。
paused
, videoStreamElement
, screen
, videoUrl
辺りは無くせるような気がしています。getVideoUrl()
は videoStreamElement
という外部変数に依存しています。この場合は引数に videoStreamElement
に当たるものを定義する事で回避すると良いと考えています。cls
ではなく className
などとします。実装上の問題については対応は簡単かと思いますが、プログラムコードの書き方の問題についてはかなりの修正が必要になりそうです。これらは私が行う場合、この pull request を参考に初めから書く事になりそうです。それでも良いのであればこちらでこの作業を私が引き受けます。貴方はどうしたいですか?
Hi! Thank you very much for these reasonable recommendations! To me it would be better if I finally manage these problems in this pull request. If you don't mind, I'll try to do that
お返事ありがとうございます。 こちらでプログラムコードの書き方についてのガイドラインを用意できていればよかったと思っています。ガイドラインを用意できていないため、場合によっては別の指摘をすることになるかもしれませんが、それでもよろしければ引き続き作業をお願いしたいです。お手数をおかけしてしまいますが、よろしくお願いいたします。
あと1点、使っていて気づいた点がありました。 以下に示します。
.cancel()
を行っている事が原因のような気がしています。@RonnieBlade 改良は進んでいますでしょうか? 少し時間がかかっているようなので心配しています。
もし、実装するのが難しいのであれば、こちらで作業致しますのでお知らせ下さい。
Hi Limura! Sorry it's been a while, I needed some time to investigate the issue. I've made some changes. I'll commit today
Here is what I’ve changed in the new commit:
Hope, everything is fine now.
ありがとうございます。 素晴らしい仕事です。
いくつか気になった点はあったのですが、概ね問題ないと思いますので取り込みました。
重ねて、ありがとうございます。大変助かりました。
なお、気になった点は以下の点でした。これらはこちらで検証して修正が必要そうであれば修正することにしようと思っています。
Hi! Thank you very much! It's very interesting and inspiring to work on your project.
speechSynthesis.speaking
is true . I've just tested it, this approach works fine, but it's not suitable for all situations, for example when pausing a video, rewind or fast-forward and hit play, we need to use cancel to prevent speechSynthesis from speaking an utterance from a different time of the video.
Hi there! I think it would be a nice feature to make speechSynthesis stop speaking immediately when the video gets paused. I've implemented that feature using MutationObserver, waiting for the "paused-mode" class to appear in the player element.
Also, I've added "wasPaused" flag to repeat the last captions after playback resumes if there are no new captions at current time.
I hope my humble contribution will help the project!
P.S. Sorry for reformating your code in commits on the last pull request, this time I made the changes super carefully.