How to Delete downloadable sample by id for Download product Magento 2?

Delete downloadable sample by sample id for the product Magento 2.

Each Downloadable Item supports the sample data of the attachment type like video, music, ebook, software file.

You can programmatically delete it by the sample id using code snippet with the delete($id) method.

<?php
namespace Jesadiya\DeleteSample\Model;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Downloadable\Api\SampleRepositoryInterface;
use Psr\Log\LoggerInterface;

class DeleteSample
{
    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * @var SampleRepositoryInterface
     */
    private $sampleRepository;

    public function __construct(
        LoggerInterface $logger,
        SampleRepositoryInterface $sampleRepository
    ) {
        $this->logger = $logger;
        $this->sampleRepository = $sampleRepository;
    }

    /**
     * Delete samples data by id from the downloadable item
     *
     * @param int $id
     * @return bool
     */
    public function deleteSampleByid(int $id): bool
    {
        $isSampleDelete = false;
        try {
            $isSampleDelete = $this->sampleRepository->delete($sku);
        } catch (NoSuchEntityException $exception) {
            $this->logger->error($exception->getMessage());
        }
        return $isSampleDelete;
    }
}

Call from the template or any PHP class,

$id = 1;
$isSampleDelete = $this->deleteSampleByid($sku);

On Error of function call,
No downloadable sample with the provided ID was found. Verify the ID and try again.

Output:
true/false