#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributors.

from fenrirscreenreader.speechDriver.hardwareSerialDriver import (
    hardware_serial_driver,
)


class driver(hardware_serial_driver):
    cancel_command = b"\x18"

    def _speak_bytes(self, text):
        return self._clean_text(text).encode("ascii", errors="replace") + b"\r"

    def _rate_command(self, rate):
        return self._setting_command(self._scale(rate, 0, 9), b"S")

    def _pitch_command(self, pitch):
        return self._setting_command(self._scale(pitch, 0, 99), b"P")

    def _volume_command(self, volume):
        return self._setting_command(self._scale(volume, 0, 9), b"V")

    def _setting_command(self, value, command):
        return b"\x01" + str(value).encode("ascii") + command
