Spaces:
Running
Running
SevenhuijsenM
commited on
Commit
•
befa5d2
1
Parent(s):
167c051
Attempt for radio
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ from transformers import pipeline
|
|
2 |
import gradio as gr
|
3 |
from pytube import YouTube
|
4 |
import os
|
|
|
|
|
5 |
|
6 |
pipe = pipeline(model="dussen/whisper-small-nl-hc")
|
7 |
print(pipe)
|
@@ -48,18 +50,22 @@ def audio_to_text(audio):
|
|
48 |
return text
|
49 |
|
50 |
def radio_to_text(radio_url):
|
51 |
-
|
52 |
-
stream_url = radio_url
|
53 |
|
54 |
r = requests.get(stream_url, stream=True)
|
55 |
|
|
|
56 |
with open('stream.mp3', 'wb') as f:
|
|
|
|
|
|
|
57 |
try:
|
58 |
for block in r.iter_content(1024):
|
59 |
f.write(block)
|
|
|
|
|
60 |
except KeyboardInterrupt:
|
61 |
pass
|
62 |
-
|
63 |
text = pipe("stream.mp3")["text"]
|
64 |
print(text)
|
65 |
return text
|
|
|
2 |
import gradio as gr
|
3 |
from pytube import YouTube
|
4 |
import os
|
5 |
+
import requests
|
6 |
+
import time
|
7 |
|
8 |
pipe = pipeline(model="dussen/whisper-small-nl-hc")
|
9 |
print(pipe)
|
|
|
50 |
return text
|
51 |
|
52 |
def radio_to_text(radio_url):
|
53 |
+
stream_url = "https://icecast.omroep.nl/radio1-bb-mp3"
|
|
|
54 |
|
55 |
r = requests.get(stream_url, stream=True)
|
56 |
|
57 |
+
# Open it and after 10 seconds close the connection
|
58 |
with open('stream.mp3', 'wb') as f:
|
59 |
+
# Get the stopping time as a UNIX timestamp
|
60 |
+
stop_after = time.time() + 0.5
|
61 |
+
|
62 |
try:
|
63 |
for block in r.iter_content(1024):
|
64 |
f.write(block)
|
65 |
+
if time.time() > stop_after:
|
66 |
+
break
|
67 |
except KeyboardInterrupt:
|
68 |
pass
|
|
|
69 |
text = pipe("stream.mp3")["text"]
|
70 |
print(text)
|
71 |
return text
|