# Path: praatio/klattgrid.py
# def openKlattgrid(fnFullPath: str) -> Klattgrid:
# def wavToKlattgrid(
#     praatEXE: str,
#     inputFullPath: str,
#     outputFullPath: str,
#     timeStep: float = 0.005,
#     numFormants: int = 5,
#     maxFormantFreq: float = 5500.0,
#     windowLength: float = 0.025,
#     preEmphasis: float = 50.0,
#     pitchFloor: float = 60.0,
#     pitchCeiling: float = 600.0,
#     minPitch: float = 50.0,
#     subtractMean: bool = True,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def resynthesize(
#     praatEXE: str,
#     wavFN: str,
#     klattFN: str,
#     outputWavFN: str,
#     doCascade: bool = True,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def _openNormalKlattgrid(data: str) -> Klattgrid:
# def _proccessContainerTierInput(sectionData: str, name: str):
# def _findIndicies(data, keyword):
# def _getSectionHeader(data, indexList, i):
# def _buildEntryList(sectionTuple):
# def _processSectionData(sectionData: str) -> List[Tuple[float, float]]:
# 
# Path: praatio/praat_scripts.py
# SILENCE_LABEL = "silent"
# SOUND_LABEL = "sound"
# def changeGender(
#     praatEXE: str,
#     wavFN: str,
#     outputWavFN: str,
#     pitchFloor: float,
#     pitchCeiling: float,
#     formantShiftRatio: float,
#     pitchMedian: float = 0.0,
#     pitchRange: float = 1.0,
#     duration: float = 1.0,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def changeIntensity(
#     praatEXE: str,
#     wavFN: str,
#     outputWavFN: str,
#     newIntensity: float,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def getFormants(
#     praatEXE: str,
#     inputWavFN: str,
#     outputTxtFN: str,
#     maxFormant: float,
#     stepSize: float = 0.01,
#     window_length: float = 0.025,
#     preemphasis: float = 50,
#     scriptFN: Optional[str] = None,
#     undefinedValue: Optional[str] = None,
# ) -> List:
# def getPulses(
#     praatEXE: str,
#     inputWavFN: str,
#     outputPointTierFN: str,
#     minPitch: float,
#     maxPitch: float,
#     scriptFN: Optional[str] = None,
# ) -> data_points.PointObject1D:
# def getSpectralInfo(
#     praatEXE: str,
#     inputWavFN: str,
#     inputTGFN: str,
#     outputCSVFN: str,
#     tierName: str,
#     spectralPower: int = 2,
#     spectralMoment: int = 3,
#     scriptFN: Optional[str] = None,
# ) -> Tuple[List, List]:
# def resynthesizePitch(
#     praatEXE: str,
#     inputWavFN: str,
#     pitchFN: str,
#     outputWavFN: str,
#     minPitch: float,
#     maxPitch: float,
#     scriptFN: Optional[str] = None,
#     pointList: Optional[List] = None,
# ) -> None:
# def resynthesizeDuration(
#     praatEXE: str,
#     inputWavFN: str,
#     durationTierFN: str,
#     outputWavFN: str,
#     minPitch: float,
#     maxPitch: float,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def annotateSilences(
#     praatEXE: str,
#     inputWavPath: str,
#     outputTGPath: str,
#     minPitch: float = 100,
#     timeStep: float = 0.0,
#     silenceThreshold: float = -25.0,
#     minSilDur: float = 0.1,
#     minSoundDur: float = 0.1,
#     silentLabel: str = SILENCE_LABEL,
#     soundLabel: str = SOUND_LABEL,
#     scriptFN: Optional[str] = None,
# ) -> None:


import os
from os.path import join
from praatio import klattgrid
from praatio import praat_scripts
# File to manipulate
name = "bobby"
wavFN = join(path, name + ".wav")
mainKlattFN = join(outputPath, name + ".KlattGrid")

# Wav to klattgrid
praatEXE = "/Applications/Praat.app/Contents/MacOS/Praat"  # Example for Mac
# praatEXE = r"C:\Praat.exe" # Example for Windows
klattgrid.wavToKlattgrid(
    praatEXE, wavFN, mainKlattFN, maxFormantFreq=3500, pitchFloor=50, pitchCeiling=350
)

# Increase formants by 20%
incrTwenty = lambda x: x * 1.2
kg = klattgrid.openKlattgrid(mainKlattFN)

formantTier = kg.tierDict["oral_formants"]
subFormantTier = formantTier.tierDict["formants"]
for subTierName in subFormantTier.tierNameList:
    subFormantTier.tierDict[subTierName].modifyValues(incrTwenty)

outputName = name + "_twenty_percent_more"
klattFN = join(outputPath, outputName + ".KlattGrid")
outputWavFN = join(outputPath, outputName + ".wav")
kg.save(klattFN)
klattgrid.resynthesize(praatEXE, wavFN, klattFN, outputWavFN)

# Decrease formants by 20% - same technique as above, but shorthand version
# (also less flexible)
decrTwenty = lambda x: x * 0.8

# Path: praatio/klattgrid.py
# def openKlattgrid(fnFullPath: str) -> Klattgrid:
# def wavToKlattgrid(
#     praatEXE: str,
#     inputFullPath: str,
#     outputFullPath: str,
#     timeStep: float = 0.005,
#     numFormants: int = 5,
#     maxFormantFreq: float = 5500.0,
#     windowLength: float = 0.025,
#     preEmphasis: float = 50.0,
#     pitchFloor: float = 60.0,
#     pitchCeiling: float = 600.0,
#     minPitch: float = 50.0,
#     subtractMean: bool = True,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def resynthesize(
#     praatEXE: str,
#     wavFN: str,
#     klattFN: str,
#     outputWavFN: str,
#     doCascade: bool = True,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def _openNormalKlattgrid(data: str) -> Klattgrid:
# def _proccessContainerTierInput(sectionData: str, name: str):
# def _findIndicies(data, keyword):
# def _getSectionHeader(data, indexList, i):
# def _buildEntryList(sectionTuple):
# def _processSectionData(sectionData: str) -> List[Tuple[float, float]]:
# 
# Path: praatio/praat_scripts.py
# SILENCE_LABEL = "silent"
# SOUND_LABEL = "sound"
# def changeGender(
#     praatEXE: str,
#     wavFN: str,
#     outputWavFN: str,
#     pitchFloor: float,
#     pitchCeiling: float,
#     formantShiftRatio: float,
#     pitchMedian: float = 0.0,
#     pitchRange: float = 1.0,
#     duration: float = 1.0,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def changeIntensity(
#     praatEXE: str,
#     wavFN: str,
#     outputWavFN: str,
#     newIntensity: float,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def getFormants(
#     praatEXE: str,
#     inputWavFN: str,
#     outputTxtFN: str,
#     maxFormant: float,
#     stepSize: float = 0.01,
#     window_length: float = 0.025,
#     preemphasis: float = 50,
#     scriptFN: Optional[str] = None,
#     undefinedValue: Optional[str] = None,
# ) -> List:
# def getPulses(
#     praatEXE: str,
#     inputWavFN: str,
#     outputPointTierFN: str,
#     minPitch: float,
#     maxPitch: float,
#     scriptFN: Optional[str] = None,
# ) -> data_points.PointObject1D:
# def getSpectralInfo(
#     praatEXE: str,
#     inputWavFN: str,
#     inputTGFN: str,
#     outputCSVFN: str,
#     tierName: str,
#     spectralPower: int = 2,
#     spectralMoment: int = 3,
#     scriptFN: Optional[str] = None,
# ) -> Tuple[List, List]:
# def resynthesizePitch(
#     praatEXE: str,
#     inputWavFN: str,
#     pitchFN: str,
#     outputWavFN: str,
#     minPitch: float,
#     maxPitch: float,
#     scriptFN: Optional[str] = None,
#     pointList: Optional[List] = None,
# ) -> None:
# def resynthesizeDuration(
#     praatEXE: str,
#     inputWavFN: str,
#     durationTierFN: str,
#     outputWavFN: str,
#     minPitch: float,
#     maxPitch: float,
#     scriptFN: Optional[str] = None,
# ) -> None:
# def annotateSilences(
#     praatEXE: str,
#     inputWavPath: str,
#     outputTGPath: str,
#     minPitch: float = 100,
#     timeStep: float = 0.0,
#     silenceThreshold: float = -25.0,
#     minSilDur: float = 0.1,
#     minSoundDur: float = 0.1,
#     silentLabel: str = SILENCE_LABEL,
#     soundLabel: str = SOUND_LABEL,
#     scriptFN: Optional[str] = None,
# ) -> None:


# Path: examples/klatt_resynthesis.py
import os
from os.path import join
from praatio import klattgrid
from praatio import praat_scripts

# File to manipulate
name = "bobby"
wavFN = join(path, name + ".wav")
mainKlattFN = join(outputPath, name + ".KlattGrid")

# Wav to klattgrid
praatEXE = "/Applications/Praat.app/Contents/MacOS/Praat"  # Example for Mac
# praatEXE = r"C:\Praat.exe" # Example for Windows
klattgrid.wavToKlattgrid(
    praatEXE, wavFN, mainKlattFN, maxFormantFreq=3500, pitchFloor=50, pitchCeiling=350
)

# Increase formants by 20%
incrTwenty = lambda x: x * 1.2
kg = klattgrid.openKlattgrid(mainKlattFN)

formantTier = kg.tierDict["oral_formants"]
subFormantTier = formantTier.tierDict["formants"]
for subTierName in subFormantTier.tierNameList:
    subFormantTier.tierDict[subTierName].modifyValues(incrTwenty)

outputName = name + "_twenty_percent_more"
klattFN = join(outputPath, outputName + ".KlattGrid")
outputWavFN = join(outputPath, outputName + ".wav")
kg.save(klattFN)
klattgrid.resynthesize(praatEXE, wavFN, klattFN, outputWavFN)

# Decrease formants by 20% - same technique as above, but shorthand version
# (also less flexible)
decrTwenty = lambda x: x * 0.8

kg = klattgrid.openKlattgrid(mainKlattFN)