# How can I regulate 'Play sound duration' in Mathematica 8

How can I regulate the time of play sound[s] - duration in Mathematica 8. I want to import and save wav file in *.nb document & manipulate (with) the sound duration, for example, select sound fragment, split etc. I can not present sounds with duration more than 5 or 7 seconds in wavelet form - problem with CPU or memory ("very large..."). Thank you for answers.

I really tried to solve the problem of primitive –

file="C:/**.wav";
data=Flatten@Import[file,"Data"];
Import[file,"Options"];
data=Import[file,"Sound"];
L=Length[data];  Manipulate[Sound[data,t],{t,0.1,L}]


it works, but probably not optimal. It works slowly. In general, my problem has arisen from a desire to manipulate with time (duration) of the wav sound file. Your perfect solution, since it allows to allocate the sample.

Before that I was faced with freezing when trying to view 10-second file in the wavelet form. «No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry». I used the "Direct conversion of acoustic data" Mathematica code - Direct analysis of acoustic data using continuous wavelet transforms.

http://www.wolfram.com/mathematica/new-in-8/wavelet-analysis/directly-transform-sound.html

snd = ExampleData[{"Sound", "Apollo11ReturnSafely"}]
cwd = ContinuousWaveletTransform[snd,
GaborWavelet[6], {Automatic, 12}]
sty = Directive[14, FontFamily -> "Helvetica"];
WaveletScalogram[cwd, {3 | 4 | 5 | 6 | 7, _}, ImageSize -> 570,
Ticks -> {Automatic, {#, Superscript[2, #]} & /@ Range[7]},
TicksStyle -> sty,  AxesLabel -> {Style["Time", sty], Style["Scale", sty]},
ColorFunction -> ColorData["SiennaTones"]]


But it hangs when I try to submit a file whose duration is 10 seconds or more. Maybe it depends on the record a sound file.

-
Welcome Alexander. I am not quite sure what you are trying to achieve. Do you want to import only parts of the sound as the files are so large? Could you post some code of what you have tried. This would give me/us some better idea of what you are after. – Matariki Jul 2 '12 at 4:36
Alexander, the "answer" you posted was not an answer, therefore I deleted it according the standard operating rules of this site. I have editing your addendum into your question. You should edit it further as necessary and remove the personal comments. – Mr.Wizard Jul 2 '12 at 15:07
Alexander, the code posted on this site is under a specific CreativeCommons license (CC by-sa). See the link at the bottom right corner of every page… – F'x Sep 7 '12 at 15:12

Let's take an example of WAV sound data:

data=Import[ "ExampleData/rule30.wav"]


You can see sampling rate 44100 Hz and duration 1.8 s of your sample. This function extracts data for a specific time duration:

TakeSound[d_, s_, e_] := {d[[1, 1, 1, Round[44100 s] ;; Round[44100 e]]]}


And this app allows you to cut and play sub-samples of your data:

Manipulate[ Column@{ListLinePlot[
Transpose[{Table[N[t/44100], {t, 1, Length[data[[1, 1, 1]]], 1}],
data[[1, 1, 1]]}], PlotRange -> All, Frame -> True,
Epilog -> Dynamic@{Opacity[.3], Rectangle[{s, -1}, {e, 1}]},
AspectRatio -> 1/4, ImageSize -> 250,
FrameTicks -> {Automatic, None}],
Dynamic@Sound[SampledSoundList[TakeSound[data, s, e], 44100]]},
{{s, .2, "start"}, .00003, 1.8, Appearance -> "Labeled",
ImageSize -> Small}, {{e, 1.5, "end"}, 0, 1.8,
Appearance -> "Labeled", ImageSize -> Small}, AppearanceElements -> None]


Of course, always end > start. Otherwise interface will break. It is easy to build in protection against it, but I wanted to keep it simple and clear. You can add it yourself.

-