# Path: praatio/textgrid.py
# def openTextgrid(
#     fnFullPath: str,
#     includeEmptyIntervals: bool,
#     reportingMode: Literal["silence", "warning", "error"] = "warning",
#     duplicateNamesMode: Literal["error", "rename"] = "error",
# ) -> Textgrid:
# def _dictionaryToTg(
#     tgAsDict: dict, reportingMode: Literal["silence", "warning", "error"]
# ) -> Textgrid:
# 
# Path: praatio/audio.py
# class AudioDeletion:
# class AbstractWav(ABC):
# class WavQueryObj(AbstractWav):
# class WavObj(AbstractWav):
#     SHRINK: Final = "shrink"
#     SILENCE: Final = "silence"
#     SINE_WAVE: Final = "sine wave"
# _KEEP: Final = "keep"
# _DELETE: Final = "delete"
# ZERO_CROSSING_TIMESTEP: Final = 0.002
# def samplesAsNums(waveData, sampleWidth: int) -> Tuple[int, ...]:
# def numsAsSamples(sampleWidth: int, numList: List[int]) -> bytes:
# def getDuration(wavFN: str) -> float:
# def getMaxAmplitude(sampleWidth: int) -> int:
# def generateSineWave(
#     duration: float, freq: int, samplingFreq: int, amplitude: float
# ) -> List[int]:
# def generateSilence(duration: float, samplingFreq: int) -> Tuple[int, ...]:
# def extractSubwav(fn: str, outputFN: str, startT: float, endT: float) -> None:
#     def __init__(self, params):
#     def findNearestZeroCrossing(
#         self, targetTime: float, timeStep: float = ZERO_CROSSING_TIMESTEP
#     ) -> float:
#     def findNextZeroCrossing(
#         self,
#         targetTime: float,
#         timeStep: float = ZERO_CROSSING_TIMESTEP,
#         reverse: bool = False,
#     ) -> float:
#     def getDuration(self) -> float:
#     def getSamples(self, startTime: float, endTime: float) -> Tuple[int, ...]:
#     def __init__(self, fn: str):
#     def concatenate(
#         self, targetFrames: List[int], outputFN: str, prepend: bool = False
#     ) -> None:
#     def getDuration(self) -> float:
#     def getFrames(self, startTime: float = None, endTime: float = None):
#     def getSamples(self, startTime: float, endTime: float) -> Tuple[int, ...]:
#     def deleteWavSections(
#         self,
#         outputFN: str,
#         keepList: List[Tuple[float, float, str]] = None,
#         deleteList: List[Tuple[float, float, str]] = None,
#         operation: Literal["shrink", "silence", "sine wave"] = AudioDeletion.SHRINK,
#         sineWaveAmplitude: float = None,
#     ):
#     def outputModifiedWav(self, audioFrames: bytes, outputFN: str):
#     def __init__(self, audioSamples: Tuple[int, ...], params: dict):
#     def getIndexAtTime(self, startTime: float):
#     def insertSilence(self, startTime: float, silenceDuration: float):
#     def insert(self, startTime: float, audioSamples: Tuple[int, ...]):
#     def deleteSegment(self, startTime: float, endTime: float):
#     def getDuration(self):
#     def getSamples(self, startTime: float, endTime: float) -> Tuple[int, ...]:
#     def getSubsegment(self, startTime: float, endTime: float) -> "WavObj":
#     def new(self):
#     def save(self, outputFN: str):
# def openAudioFile(
#     fn: str,
#     keepList: List[Tuple[float, float, str]] = None,
#     deleteList: List[Tuple[float, float, str]] = None,
#     doShrink: bool = True,
# ) -> WavObj:


import os
from os.path import join
from praatio import textgrid
from praatio import audio
of the recording.
"""



path = join(".", "files")
outputPath = join(path, "anonymized_data")

if not os.path.exists(outputPath):
    os.mkdir(outputPath)

for wavFN, tgFN in (
    ("mary.wav", "mary.TextGrid"),
    ("bobby.wav", "bobby_words.TextGrid"),
):

    outputWavFN = join(outputPath, wavFN)

    # Find the word(s) to anonymize
    # (One could imagine a search for common names or identification of
    # some sort of code ('section-to-anonymize') rather than what I have
    # done here.
    deleteList = []
    tg = textgrid.openTextgrid(join(path, tgFN), False)
    deleteList.append(tg.tierDict["word"].entryList[0])

    # Get only time information from entries (i.e. remove label information)
    deleteList = [(start, end) for start, end, _ in deleteList]

    # Replace segments with a sine wave

# Path: praatio/textgrid.py
# def openTextgrid(
#     fnFullPath: str,
#     includeEmptyIntervals: bool,
#     reportingMode: Literal["silence", "warning", "error"] = "warning",
#     duplicateNamesMode: Literal["error", "rename"] = "error",
# ) -> Textgrid:
# def _dictionaryToTg(
#     tgAsDict: dict, reportingMode: Literal["silence", "warning", "error"]
# ) -> Textgrid:
# 
# Path: praatio/audio.py
# class AudioDeletion:
# class AbstractWav(ABC):
# class WavQueryObj(AbstractWav):
# class WavObj(AbstractWav):
#     SHRINK: Final = "shrink"
#     SILENCE: Final = "silence"
#     SINE_WAVE: Final = "sine wave"
# _KEEP: Final = "keep"
# _DELETE: Final = "delete"
# ZERO_CROSSING_TIMESTEP: Final = 0.002
# def samplesAsNums(waveData, sampleWidth: int) -> Tuple[int, ...]:
# def numsAsSamples(sampleWidth: int, numList: List[int]) -> bytes:
# def getDuration(wavFN: str) -> float:
# def getMaxAmplitude(sampleWidth: int) -> int:
# def generateSineWave(
#     duration: float, freq: int, samplingFreq: int, amplitude: float
# ) -> List[int]:
# def generateSilence(duration: float, samplingFreq: int) -> Tuple[int, ...]:
# def extractSubwav(fn: str, outputFN: str, startT: float, endT: float) -> None:
#     def __init__(self, params):
#     def findNearestZeroCrossing(
#         self, targetTime: float, timeStep: float = ZERO_CROSSING_TIMESTEP
#     ) -> float:
#     def findNextZeroCrossing(
#         self,
#         targetTime: float,
#         timeStep: float = ZERO_CROSSING_TIMESTEP,
#         reverse: bool = False,
#     ) -> float:
#     def getDuration(self) -> float:
#     def getSamples(self, startTime: float, endTime: float) -> Tuple[int, ...]:
#     def __init__(self, fn: str):
#     def concatenate(
#         self, targetFrames: List[int], outputFN: str, prepend: bool = False
#     ) -> None:
#     def getDuration(self) -> float:
#     def getFrames(self, startTime: float = None, endTime: float = None):
#     def getSamples(self, startTime: float, endTime: float) -> Tuple[int, ...]:
#     def deleteWavSections(
#         self,
#         outputFN: str,
#         keepList: List[Tuple[float, float, str]] = None,
#         deleteList: List[Tuple[float, float, str]] = None,
#         operation: Literal["shrink", "silence", "sine wave"] = AudioDeletion.SHRINK,
#         sineWaveAmplitude: float = None,
#     ):
#     def outputModifiedWav(self, audioFrames: bytes, outputFN: str):
#     def __init__(self, audioSamples: Tuple[int, ...], params: dict):
#     def getIndexAtTime(self, startTime: float):
#     def insertSilence(self, startTime: float, silenceDuration: float):
#     def insert(self, startTime: float, audioSamples: Tuple[int, ...]):
#     def deleteSegment(self, startTime: float, endTime: float):
#     def getDuration(self):
#     def getSamples(self, startTime: float, endTime: float) -> Tuple[int, ...]:
#     def getSubsegment(self, startTime: float, endTime: float) -> "WavObj":
#     def new(self):
#     def save(self, outputFN: str):
# def openAudioFile(
#     fn: str,
#     keepList: List[Tuple[float, float, str]] = None,
#     deleteList: List[Tuple[float, float, str]] = None,
#     doShrink: bool = True,
# ) -> WavObj:


# Path: examples/anonymize_recording.py
import os
from os.path import join
from praatio import textgrid
from praatio import audio

of the recording.
"""



path = join(".", "files")
outputPath = join(path, "anonymized_data")

if not os.path.exists(outputPath):
    os.mkdir(outputPath)

for wavFN, tgFN in (
    ("mary.wav", "mary.TextGrid"),
    ("bobby.wav", "bobby_words.TextGrid"),
):

    outputWavFN = join(outputPath, wavFN)

    # Find the word(s) to anonymize
    # (One could imagine a search for common names or identification of
    # some sort of code ('section-to-anonymize') rather than what I have
    # done here.
    deleteList = []
    tg = textgrid.openTextgrid(join(path, tgFN), False)
    deleteList.append(tg.tierDict["word"].entryList[0])

    # Get only time information from entries (i.e. remove label information)
    deleteList = [(start, end) for start, end, _ in deleteList]

    # Replace segments with a sine wave

    wavQObj = audio.WavQueryObj(join(path, wavFN))