Giter Site home page Giter Site logo

stefanocoretta / speakr Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 3.0 1.79 MB

speakr: A Wrapper for the Phonetic Software Praat

Home Page: https://stefanocoretta.github.io/speakr/

License: Other

R 100.00%
praat praatscript r package r-package rstats software

speakr's Introduction

speakr: A Wrapper for the Phonetic Software Praat

CRAN checks R-CMD-check R-CMD-check

With speakr, you can run Praat scripts in R and capture their infoLine output.

Installation

You can install the released version of speakr from CRAN with:

install.packages("speakr")

If you want to install a stable(ish) development version, use:

remotes::install_github("stefanocoretta/speakr@devel", build_vignettes = TRUE)

Use

For a quick start, check out the vignette with:

vignette("run-praat", "speakr")

On macOS, Linux and Windows, the path to praat is set automatically to the default installation path. If you have installed Praat in a different location, or if your operating system is not supported, you can set the path to Praat with options(speakr.praat.path).

For example:

options(speakr.praat.path = "./custom/praat.exe")

You can either run this command every time you start a new R session, or you can add the command to your .Rprofile (recommended).

Example

Use prat_run() to run a Praat script, and capture = TRUE to capture the output of the write/appendInfoLine commands in the script. Everything is set in the Praat script as usual, so you don’t have to learn a new language to perform tasks you already know how to perform.

script <- system.file("extdata", "get-formants-args.praat", package = "speakr")

formants <- praat_run(script, "Hertz", 0.03, capture = TRUE) %>%
  read_csv()
#> Rows: 5 Columns: 4
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): vowel
#> dbl (3): F1, F2, F3
#> 
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Let’s check the tibble formants.

formants
#> # A tibble: 5 × 4
#>   vowel    F1    F2    F3
#>   <chr> <dbl> <dbl> <dbl>
#> 1 a      784. 1391. 2433.
#> 2 e      417. 2042. 2424.
#> 3 i      259. 2232. 2819.
#> 4 o      562.  855. 2463.
#> 5 u      434. 1331. 2816.

And let’s make a vowel plot.

formants %>%
  ggplot(aes(F2, F1, label = vowel)) +
  geom_label(size = 10) +
  labs(
    title = "Vowel plot",
    x = "F2 (Hertz)",
    y = "F1 (Hertz)"
  ) +
  scale_x_reverse(position = "top", limits = c(2250, 700)) +
  scale_y_reverse(position = "right", limits = c(900, 150)) +
  coord_fixed()

Simple plotting utility

You can plot a sound file and TextGrid using Praat’s plotting facilities.

wav <- system.file("extdata", "vowels.wav", package = "speakr")

praat_plot("vowels.png", wav, f0 = T, f0_max = 200, end = 3)

You can include the plot in an Rmarkdown file with knitr.

knitr::include_graphics("man/figures/vowels.png")

speakr's People

Contributors

agricolamz avatar jimhester avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

speakr's Issues

Set path onLoad and not onAttach

This will allow the Praat path to be set when calling the package namespace directly with ::.

Would be useful to have a function that checks Praat exists to be included in each function that calls Praat.

Question about running Praat scripts using speakr

Hi Stefano,

I hope this message finds you well. My name is Ruohan, and I am a second-year PhD student at UCL.

I am using speakr to run Praat scripts and extract data from the outcomes. Your tutorial on passing arguments to Praat forms (https://cran.r-project.org/web/packages/speakr/vignettes/run-praat.html) has been incredibly helpful, and I have successfully set most field types in Praat forms, such as option and boolean.

However, I encountered an issue when trying to run a specific Praat script using speakr. The script (https://sites.google.com/view/uhm-o-meter/scripts/syllablenuclei_v3?authuser=0) measures speech rate and requires 11 arguments. The first argument needs a directory path to the audio files (please see the attached snapshots), and I haven't been able to get this right in R.

Could you please advise me on how to pass this type of argument to Praat scripts from R? I can provide the code I used if that would help with the diagnosis.

Thank you in advance for your assistance.

Best wishes,
Ruohan

Praat_script Praat_window

`speakr` on windows

Hi, during the class of @agricolamz, I've run the following code and get the following problem. So my teacher and me don't know, what to do.

> options(speakr.praat.path = 'C:/Users/NewUser/Desktop/praat.exe')
> script <- system.file("extdata", "get-formants-args.praat", package = "speakr")
> ormants <- praat_run(script, "Hertz", 0.03, capture = TRUE) %>%
+   read_csv()
Warning message:
In system2(getOption("speakr.praat.path"), c("--run", c(script,  :
  running command '"C:/Users/NewUser/Desktop/praat.exe" --run C:/Program Files/R/R-4.1.0/library/speakr/extdata/get-formants-args.praat Hertz 0.03' had status 65535

Here is my info:

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=Russian_Russia.1251  LC_CTYPE=Russian_Russia.1251   
[3] LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C                   
[5] LC_TIME=Russian_Russia.1251    
system code page: 1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.5.1        stringr_1.4.0        dplyr_1.0.7         
 [4] purrr_0.3.4          readr_1.4.0          tidyr_1.1.3         
 [7] tibble_3.1.2         ggplot2_3.3.5        tidyverse_1.3.1     
[10] phonfieldwork_0.0.11 speakr_3.2.0        

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1  xfun_0.24         haven_2.4.1       colorspace_2.0-2 
 [5] vctrs_0.3.8       generics_0.1.0    htmltools_0.5.1.1 yaml_2.2.1       
 [9] utf8_1.2.1        rlang_0.4.11      pillar_1.6.1      withr_2.4.2      
[13] glue_1.4.2        DBI_1.1.1         dbplyr_2.1.1      modelr_0.1.8     
[17] readxl_1.3.1      lifecycle_1.0.0   munsell_0.5.0     gtable_0.3.0     
[21] cellranger_1.1.0  rvest_1.0.0       evaluate_0.14     labeling_0.4.2   
[25] uchardet_1.1.0    knitr_1.33        fansi_0.5.0       broom_0.7.8      
[29] Rcpp_1.0.7        scales_1.1.1      backports_1.2.1   jsonlite_1.7.2   
[33] farver_2.1.0      fs_1.5.0          hms_1.1.0         digest_0.6.27    
[37] stringi_1.6.2     grid_4.1.0        cli_3.0.0         tools_4.1.0      
[41] magrittr_2.0.1    crayon_1.4.1      pkgconfig_2.0.3   MASS_7.3-54      
[45] ellipsis_0.3.2    xml2_1.3.2        tuneR_1.3.3.1     reprex_2.0.0     
[49] lubridate_1.7.10  rstudioapi_0.13   assertthat_0.2.1  rmarkdown_2.9    
[53] httr_1.4.2        R6_2.5.0          signal_0.7-7      compiler_4.1.0

Warning at load time

Hi,

I tried installing your package, and it gives a warning I guess has to do with your setup:

> devtools::install_github("stefanocoretta/[email protected]", build_opts = c("--no-resave-data", "--no-manual"))
Downloading GitHub repo stefanocoretta/[email protected]
✓  checking for file ‘/private/var/folders/vc/lhvg_40x50l3nb3rndb4kwbm0000gp/T/RtmpL0m1oY/remotes175e693631af/stefanocoretta-speakr-6e67bac/DESCRIPTION’ ...
─  preparing ‘speakr’:
✓  checking DESCRIPTION meta-information ...
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘speakr_2.1.0.tar.gz’
   
* installing *source* package ‘speakr’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Warning in normalizePath("~/go/bin/lmt") :
  path[1]="/Users/frkkan96/go/bin/lmt": No such file or directory
** testing if installed package can be loaded from final location
Warning in normalizePath("~/go/bin/lmt") :
  path[1]="/Users/frkkan96/go/bin/lmt": No such file or directory
** testing if installed package keeps a record of temporary installation path
* DONE (speakr)
> library(speakr)
Warning message:
In normalizePath("~/go/bin/lmt") :
  path[1]="/Users/frkkan96/go/bin/lmt": No such file or directory

Add literate programming utilities

  • praat_purl() to extract Praat code from fenced code chunks in an Rmarkdown file.
  • Pandoc syntax highlighting support for Praat scripting language.

Quote Praat

CRAN requires external software to be surrounded by single quotes: 'Praat'.

Fix CRAN error on Solaris

When setting the path, use ./.notsupported if the OS is not supported. The user can set the path to Praat manually.

Save Praat form arguments as attributes in returned object

When running praat_run() with arguments to be passed to form in the Praat script, the returned object should have an attribute args with a named list of arguments and their value.

For example:

obj <- run_praat("script.praat", "Hertz", 0.5, capture = TRUE)
attributes(obj)
> $args
> $args$unit
> [1] "Hertz"
>
> $args$window
> [1] 0.5

How to assign names? Perhaps:

obj <- run_praat("script.praat", "Hertz", 0.5, capture = TRUE, args = c("unit", "window"))

or better, use named args.

test <- function(...) names(list(...))
test(1, a = "a", b = "b")
> [1] ""  "a" "b"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.