You are not logged in.

#1 2007-08-03 08:39:40

The_ouroboros
Member
From: Pavia, Italy
Registered: 2007-05-28
Posts: 140

Python and audio conversion

#! /usr/bin/env python
import sys, os
from subprocess import Popen

# Mp3 ==> Wav
file_in = raw_input("Mp3 file:")
cmd1 = "mpg321 -q -w in.wav " + file_in

retcode = Popen(cmd1, shell=True).wait()
if retcode != 0:
    print 'Mp3 ==> Wav failed.'

# Wav ==> Ogg
# ==>
opt = raw_input("1)Quality Mode" +
                "2)Bitrate mode\n")

if opt == 1:
    quality = raw_input("Select quality \n\n 1)Low \n\n 3)Normal " +
                        "\n\n 5)Higth\n")
    cmd2 = "oggenc -q " + quality + " in.wav"
    retcode = Popen(cmd2, shell=True).wait()
    if retcode != 0:
        print 'Wav ==> Ogg failed.'
elif opt == 2:
    min_br = raw_input("Select minimum bitrate:")
    max_br = raw_input("Select maximum bitrate:")
    cmd2 = "oggenc -m " + min_br +" -M " + max_br + " in.wav"
    retcode = Popen(cmd2, shell=True).wait()
    if retcode != 0:
        print 'Wav ==> Ogg failed.'

Arrived to the ==> line, the program exits...why???

Tnks

Last edited by The_ouroboros (2007-08-03 08:40:46)


Gnu/Linux User on Arch(x86_64)

Offline

#2 2007-08-03 22:20:14

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: Python and audio conversion

--- t.py.old    2007-08-03 18:19:30.000000000 -0400
+++ t.py        2007-08-03 18:18:28.000000000 -0400
@@ -4,7 +4,7 @@
 
 # Mp3 ==> Wav
 file_in = raw_input("Mp3 file:")
-cmd1 = "mpg321 -q -w in.wav " + file_in
+cmd1 = "mpg321 -q -w in.wav \"" + file_in + "\""
 
 retcode = Popen(cmd1, shell=True).wait()
 if retcode != 0:
@@ -15,14 +15,14 @@
 opt = raw_input("1)Quality Mode" +
                 "2)Bitrate mode\n")
 
-if opt == 1:
+if opt == "1":
     quality = raw_input("Select quality \n\n 1)Low \n\n 3)Normal " +
                         "\n\n 5)Higth\n")
     cmd2 = "oggenc -q " + quality + " in.wav"
     retcode = Popen(cmd2, shell=True).wait()
     if retcode != 0:
         print 'Wav ==> Ogg failed.'
-elif opt == 2:
+elif opt == "2":
     min_br = raw_input("Select minimum bitrate:")
     max_br = raw_input("Select maximum bitrate:")
     cmd2 = "oggenc -m " + min_br +" -M " + max_br + " in.wav"

Offline

Board footer

Powered by FluxBB