Документация Engee

Public interface

Страница в процессе перевода.

PortAudioStream(input_channels = 2, output_channels = 2; options...)
PortAudioStream(duplex_device, input_channels = 2, output_channels = 2; options...)
PortAudioStream(input_device, output_device, input_channels = 2, output_channels = 2; options...)

Audio devices can either be PortAudioDevice instances as returned by devices, or strings with the device name as reported by the operating system. Set input_channels to 0 for an output only stream; set output_channels to 0 for an input only steam. If you pass the function maximum instead of a number of channels, use the maximum channels allowed by the corresponding device. If a single duplex_device is given, it will be used for both input and output. If no devices are given, the system default devices will be used.

The PortAudioStream type supports all the stream and buffer features defined SampledSignals.jl by default. For example, if you load SampledSignals with using SampledSignals you can read 5 seconds to a buffer with buf = read(stream, 5s), regardless of the sample rate of the device. write(stream, stream) will set up a loopback that will read from the input and play it back on the output.

Options:

  • adjust_channels = false: If set to true, if either input_channels or output_channels exceeds the corresponding device maximum, adjust down to the maximum.

  • call_back = C_NULL: The PortAudio call-back function. Currently, passing anything except C_NULL is unsupported.

  • eltype = Float32: Sample type of the audio stream

  • flags = PortAudio.paNoFlag: PortAudio flags

  • frames_per_buffer = 128: the number of frames per buffer

  • input_info = C_NULL: host API specific stream info for the input device. Currently, passing anything except C_NULL is unsupported.

  • latency = nothing: Requested latency. Stream could underrun when too low, consider using the defaults. If left as nothing, use the defaults below:

    • For input/output only streams, use the corresponding device’s default high latency.

    • For duplex streams, use the max of the default high latency of the input and output devices.

  • output_info = C_NULL: host API specific stream info for the output device. Currently, passing anything except C_NULL is unsupported.

  • reader = PortAudio.SampledSignalsReader(): the scribe that will read input. Defaults to a PortAudio.SampledSignalsReader. Users can pass custom scribes; see PortAudio.Scribe.

  • samplerate = nothing: Sample rate. If left as nothing, use the defaults below:

    • For input/output only streams, use the corresponding device’s default sample rate.

    • For duplex streams, use the default sample rate if the default sample rates for the input and output devices match, otherwise throw an error.

  • warn_xruns = true: Display a warning if there is a stream overrun or underrun, which often happens when Julia is compiling, or with a particularly large GC run. Only affects duplex streams.

  • writer = PortAudio.SampledSignalsWriter(): the scribe that will write output. Defaults to a PortAudio.SampledSignalsReader. Users can pass custom scribes; see PortAudio.Scribe.

Examples:

Set up an audio pass-through from microphone to speaker

julia> using PortAudio, SampledSignals

julia> stream = PortAudioStream(2, 2; warn_xruns = false);

julia> try
            # cancel with Ctrl-C
            write(stream, stream, 2s)
        finally
            close(stream)
        end

Use do syntax to auto-close the stream

julia> using PortAudio, SampledSignals

julia> PortAudioStream(2, 2; warn_xruns = false) do stream
            write(stream, stream, 2s)
        end

Open devices by name

using PortAudio, SampledSignals
PortAudioStream("Built-in Microph", "Built-in Output"; warn_xruns = false) do stream
    write(stream, stream, 2s)
end
2 s

Record 10 seconds of audio and save to an ogg file

julia> using PortAudio, SampledSignals, LibSndFile

julia> PortAudioStream(2, 0; warn_xruns = false) do stream
            buf = read(stream, 10s)
            save(joinpath(tempname(), ".ogg"), buf)
        end
2 s
devices()

List the devices available on your system. Devices will be shown with their internal name, and maximum input and output channels.