Skip to content
Snippets Groups Projects
Verified Commit fe26b226 authored by Lucas Ondel Yang's avatar Lucas Ondel Yang
Browse files

fixed creating recording

parent 0b20e4b6
No related branches found
No related tags found
No related merge requests found
# Tags # Tags
## [0.4.1](https://https://gitlab.lisn.upsaclay.fr/fast/speechcorpora.jl/-/tags/v0.4.1)- 25/09/2023
## Added
* HTML display of AudioSource rather than recording
## Fixed
* creating Recording from audio source without specifying the channels
and the sampling rate
## [0.4.0](https://https://gitlab.lisn.upsaclay.fr/fast/speechcorpora.jl/-/tags/v0.4.0)- 08/03/2023 ## [0.4.0](https://https://gitlab.lisn.upsaclay.fr/fast/speechcorpora.jl/-/tags/v0.4.0)- 08/03/2023
## Removed ## Removed
* `play` function and dependcy to PortAudio * `play` function and dependcy to PortAudio
......
name = "SpeechCorpora" name = "SpeechCorpora"
uuid = "3225a15e-d855-4a07-9546-2418058331ae" uuid = "3225a15e-d855-4a07-9546-2418058331ae"
authors = ["Lucas ONDEL YANG <lucas.ondel@cnrs.fr>"] authors = ["Lucas ONDEL YANG <lucas.ondel@cnrs.fr>"]
version = "0.4.0" version = "0.4.1"
[deps] [deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
......
...@@ -9,6 +9,9 @@ using WAV ...@@ -9,6 +9,9 @@ using WAV
export export
# ManifestItem # ManifestItem
FileAudioSource,
CmdAudioSource,
URLAudioSource,
Recording, Recording,
Supervision, Supervision,
load, load,
......
# SPDX-License-Identifier: CECILL-2.1 # SPDX-License-Identifier: CECILL-2.1
#=====================================================================#
# HTML pretty display
function Base.show(io::IO, ::MIME"text/html", r::AbstractAudioSource)
print(io, "<audio controls ")
print(io, "src=\"data:audio/wav;base64,")
x, s, _ = loadsource(r, :)
iob64_encode = Base64EncodePipe(io)
wavwrite(x, iob64_encode, Fs = s, nbits = 8, compression = WAV.WAVE_FORMAT_PCM)
close(iob64_encode)
println(io, "\" />")
end
#=====================================================================# #=====================================================================#
# JSON serialization of a manifest item # JSON serialization of a manifest item
...@@ -53,18 +68,6 @@ function Base.show(io::IO, m::MIME"application/json", r::Recording) ...@@ -53,18 +68,6 @@ function Base.show(io::IO, m::MIME"application/json", r::Recording)
print(io, "}") print(io, "}")
end end
function Base.show(io::IO, ::MIME"text/html", r::Recording)
print(io, "<audio controls ")
print(io, "src=\"data:audio/wav;base64,")
x, s = load(r)
iob64_encode = Base64EncodePipe(io)
wavwrite(x, iob64_encode, Fs = s, nbits = 8, compression = WAV.WAVE_FORMAT_PCM)
close(iob64_encode)
println(io, "\" />")
end
function Base.show(io::IO, m::MIME"application/json", s::Supervision) function Base.show(io::IO, m::MIME"application/json", s::Supervision)
compact = get(io, :compact, false) compact = get(io, :compact, false)
indent = compact ? 0 : 2 indent = compact ? 0 : 2
......
...@@ -52,12 +52,12 @@ A recording is an audio source associated with and id. ...@@ -52,12 +52,12 @@ A recording is an audio source associated with and id.
# Constructors # Constructors
Recording(id, source, channels, samplerate) Recording(id, source, channels, samplerate)
Recording(id, souce[; channels = missing, samplerate = missing]) Recording(id, source[; channels = missing, samplerate = missing])
If the channels or the sample rate are not provided then they will be If the channels or the sample rate are not provided then they will be
read from `source`. read from `source`.
!!! warn !!! warning
When preparing large corpus, not providing the channes and/or the When preparing large corpus, not providing the channes and/or the
sample rate can drastically reduce the speed as it forces to read sample rate can drastically reduce the speed as it forces to read
source. source.
...@@ -71,22 +71,13 @@ end ...@@ -71,22 +71,13 @@ end
function Recording(uttid, s::AbstractAudioSource; channels = missing, samplerate = missing) function Recording(uttid, s::AbstractAudioSource; channels = missing, samplerate = missing)
if ismissing(channels) || ismissing(samplerate) if ismissing(channels) || ismissing(samplerate)
x, sr = load(s) x, sr = loadsource(s, :)
samplerate = ismissing(samplerate) ? Int(sr) : samplerate samplerate = ismissing(samplerate) ? Int(sr) : samplerate
channels = ismissing(channels) ? collect(1:size(x,2)) : channels channels = ismissing(channels) ? collect(1:size(x,2)) : channels
end end
Recording(uttid, s, channels, samplerate) Recording(uttid, s, channels, samplerate)
end end
#function Base.show(io::IO, ::MIME"text/html", r::Recording)
# x, fs = load(r)
# wavwrite(x, "test.wav", Fs = fs)
# println(io, "<audio controls>")
# println(io, "<source src=\"file://test.wav\" type=\"audio/wav\">")
# #println(io, "Your browser does not support the audio element.")
# print(io, "</audio>")
#end
""" """
struct Supervision <: ManifestItem struct Supervision <: ManifestItem
id::AbstractString id::AbstractString
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment