Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jan Kruse
potify
Commits
d9b9bddb
Commit
d9b9bddb
authored
Sep 11, 2017
by
Andre Julius
👀
Browse files
Add playing functionality. No error checking yet.
parent
67d08fe8
Changes
2
Hide whitespace changes
Inline
Side-by-side
api/player.py
View file @
d9b9bddb
import
wave
import
pyaudio
import
api.index
from
config
import
datadir
sound
=
wave
.
open
(
"data/test.wav"
)
p
=
pyaudio
.
PyAudio
()
chunk
=
1024
stream
=
p
.
open
(
format
=
p
.
get_format_from_width
(
sound
.
getsampwidth
()),
channels
=
sound
.
getnchannels
(),
rate
=
sound
.
getframerate
(),
output
=
True
)
data
=
sound
.
readframes
(
chunk
)
while
data
!=
''
:
stream
.
write
(
data
)
data
=
sound
.
readframes
(
chunk
)
def
play
(
filename
):
if
api
.
index
.
is_indexed
(
filename
):
wave_file
=
wave
.
open
(
datadir
+
"/"
+
filename
)
p
=
pyaudio
.
PyAudio
()
chunk
=
1024
stream
=
p
.
open
(
format
=
p
.
get_format_from_width
(
wave_file
.
getsampwidth
()
),
channels
=
wave_file
.
getnchannels
(),
rate
=
wave_file
.
getframerate
(),
output
=
True
)
data
=
wave_file
.
readframes
(
chunk
)
while
data
!=
''
:
stream
.
write
(
data
)
data
=
wave_file
.
readframes
(
chunk
)
web/views.py
View file @
d9b9bddb
from
flask
import
redirect
,
abort
,
request
,
jsonify
,
Response
from
web
import
web
import
api.index
import
api.player
@
web
.
route
(
'/'
,
defaults
=
{
'path'
:
''
})
...
...
@@ -15,3 +16,8 @@ def catch_all(path):
@
web
.
route
(
"/index/"
)
def
index
():
return
jsonify
(
api
.
index
.
index
)
@
web
.
route
(
"/play/<file>"
)
def
play
(
file
):
api
.
player
.
play
(
file
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment