1
$\begingroup$

When I execute:

Audio["ExampleData/rule30.wav"]

I get an Audio Object.

enter image description here

How can I programmatically wrap the output in another function (without evaluating it). Concretely, I want to wrap the Audio Object with the AudioPlay function so that it looks like this:

enter image description here

So I am looking to write a function f that takes as input the Audio and outputs the desired output wrapped in the AudioPlay function and unevaluated.

Input:

f[Audio["ExampleData/rule30.wav"]]

Output:

enter image description here

$\endgroup$
0

3 Answers 3

4
$\begingroup$

I believe you are looking for Defer.

f[a_] := Defer[AudioPlay[a]]
f[Audio["ExampleData/rule30.wav"]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you! This is exactly what I needed. Unfortunately, it causes M14 to crash on my Mac. $\endgroup$ Commented Jun 24 at 7:47
2
$\begingroup$

It would help to understand what you're trying to ultimately achieve, but here's a guess at what you might be looking for.

Inactivate[AudioPlay[Audio["ExampleData/rule30.wav"]], AudioPlay]

enter image description here

When you're ready to play/evaluate it, you can use Activate.

$\endgroup$
0
$\begingroup$

So here is an unreliable and hacky way to get my desired output:

Paste[Audio["ExampleData/rule30.wav"]];
SelectionMove[EvaluationNotebook[],After,CellContents];
Paste["//AudioPlay;"];

enter image description here

here is my f:

f[x_] := Module[{},
   
   Paste[x];
   SelectionMove[EvaluationNotebook[], After, CellContents];
   Paste["//AudioPlay;"];
   ];

I wish I could figure out a more reliable way to do it using Evaluation control functionality https://reference.wolfram.com/language/guide/EvaluationControl.html

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.