When humans and robots work together, ensuring safe cooperation must be a priority. This research aims to develop a novel real-time planning algorithm that can handle unpredictable human movements by both slowing down task execution and modifying the robot's path based on the proximity of the human operator. To achieve this, an efficient method for updating the robot's motion is developed using a two-fold control approach that combines B-Splines and Hidden Markov Models. This allows the algorithm to adapt to a changing environment and avoid collisions. The proposed framework is thus validated using the Franka Emika Panda robot in a simple start-goal task. Our algorithm successfully avoids collision with the moving hand of an operator monitored by a fixed camera.